123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- using System.Collections.Generic;
- using System.Windows.Forms;
- using System.Threading;
- using HNWD.Pregrant.BusinessLogic;
- using HNWD.Pregrant.Common;
- using HNWD.Pregrant.Model;
- using System;
- using System.Net.NetworkInformation;
- using System.Text;
- using System.Threading.Tasks;
- namespace HNWD.LatticeScreen.Server
- {
- internal class LedLatticeScreen
- {
- public List<ProgramBase> programlist = new List<ProgramBase>();
- public List<ProgramBase> CallingList = new List<ProgramBase>();
- private static readonly object obj = new object();
- public int CurDisIndex = 0;
- public string DeviceID = "0";
- public long secnow1 = 0;
- public IntPtr hdl = IntPtr.Zero;
- protected IntPtr ptl = IntPtr.Zero;
- protected IntPtr pargs = IntPtr.Zero;
- public WD_DeviceInfo wd_DeviceInfo;
- public int Width = 0;
- public int Height = 0;
- public bool bSuccess = true;
- public string Msg = "操作成功";
- public LedLatticeScreen(WD_DeviceInfo wd_DeviceInfo)
- {
- this.wd_DeviceInfo = wd_DeviceInfo;
- this.DeviceID = this.wd_DeviceInfo.ID;
- this.Width = wd_DeviceInfo.DEVICE_MODEL.Contains(",") ? Convert.ToInt16(wd_DeviceInfo.DEVICE_MODEL.Split(',')[0]) : (Int16)192;
- this.Height = wd_DeviceInfo.DEVICE_MODEL.Contains(",") ? Convert.ToInt16(wd_DeviceInfo.DEVICE_MODEL.Split(',')[1]) : (Int16)32;
- this.Initialize();
- }
- /// <summary>
- /// 清除节目列表
- /// </summary>
- private void ClearProgram()
- {
- this.programlist.Clear();
- }
- /// <summary>
- /// 添加节目列表
- /// </summary>
- /// <param name="deviceid"></param>
- public void AddProgram(string deviceid)
- {
- this.ClearProgram();
- WD_ProgramInfoBusinessLogic wd = new WD_ProgramInfoBusinessLogic(deviceid, "");
- ModelExtBase<WD_ProgramInfo> wd_ProgramInfoExt = wd.QueryByParentID();
- for (int i = 0; i < wd_ProgramInfoExt.messageDataList.Count; i++)
- {
- if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "0")
- {
- TextProgram tp = new TextProgram(this);
- tp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
- this.programlist.Add(tp);
- }
- if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "1")
- {
- MultPixelProgram mpp = new MultPixelProgram(this);
- mpp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
- this.programlist.Add(mpp);
- }
- if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "2" && wd_ProgramInfoExt.messageDataList[i].PROGRAM_FORMAT.Contains("两行"))
- {
- ClockDateTimeProgram cdtp = new ClockDateTimeProgram(this);
- cdtp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
- this.programlist.Add(cdtp);
- }
- else if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "2" && !wd_ProgramInfoExt.messageDataList[i].PROGRAM_FORMAT.Contains("两行"))
- {
- ClockCustomizedProgram ccp = new ClockCustomizedProgram(this);
- ccp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
- this.programlist.Add(ccp);
- }
- }
- }
- /// <summary>
- /// 初始化
- /// </summary>
- protected void JHInit()
- {
- LedControl.JHCommInit();
- }
- protected void Initialize()
- {
- int res;
- LedControl.JHCommInit();
- /* 本例只为演示功能,更多接口请调用DllImport来获得,千万要注意C#参数和C Dll中的接口要一一对应,否则会找不到函数入口点或调用出错 */
- /* JHCommInit和JHCommDeinit接口可以放在应用程序的初始化和退出时分别调用,且必须调用,否则TCP和UDP不能正常通讯,本例中分别放在Form1_Load和Form1_FormClosed中调用 */
- /* 创建控制卡实例 */
- res = LedControl.JHCreateInst(ref hdl, 1);
- if (res != LedControl.JR_OK)
- {
- this.Msg = "创建控制卡实例失败, 错误代码:" + res;
- this.bSuccess = false;
- return;
- }
- /* 获得TCP的传输接口 */
- res = LedControl.JHCommGetTransportlayer(ref ptl, 0/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
- if (res != LedControl.JR_OK)
- {
- LedControl.JHDeleteInst(hdl);
- this.Msg = "获得传输层接口失败, 错误代码:" + res;
- this.bSuccess = false;
- return;
- }
- /* 获得通讯参数 */
- //res = LedControl.JHCommGetNetArgStruct(ref pargs, this.wd_DeviceInfo.DEVICE_ETH_IP, 30000, 5000);
- res = LedControl.JHCommGetNetArgStruct(ref pargs, this.wd_DeviceInfo.DEVICE_ETH_IP, 5005, 5000);
- //res = LedControl.JHCommGetSerialportArgStruct(ref pargs, "COM1", 115200, 8, 0, 0, 5000);
- if (res != LedControl.JR_OK)
- {
- LedControl.JHDeleteInst(hdl);
- this.Msg = "获得传输层参数失败, 错误代码:" + res;
- this.bSuccess = false;
- return;
- }
- /* 为控制卡绑定传输层接口及通讯参数 */
- res = LedControl.JHMountTransportLayer(hdl, ptl, pargs);
- if (res != LedControl.JR_OK)
- {
- LedControl.JHCommReleaseArgStruct(pargs);
- LedControl.JHDeleteInst(hdl);
- this.Msg = "挂载传输层接口失败, 错误代码:" + res;
- this.bSuccess = false;
- return;
- }
- }
- public bool PingIpOrDomainName()
- {
- try
- {
- Ping objPingSender = new Ping();
- PingOptions objPinOptions = new PingOptions();
- objPinOptions.DontFragment = true;
- string data = "";
- byte[] buffer = Encoding.UTF8.GetBytes(data);
- int intTimeout = 120;
- PingReply objPinReply = objPingSender.Send(this.wd_DeviceInfo.DEVICE_ETH_IP, intTimeout, buffer, objPinOptions);
- string strInfo = objPinReply.Status.ToString();
- if (strInfo.ToLower() == "success")
- {
- this.bSuccess = true;
- this.Msg = "网络连接成功: " + this.wd_DeviceInfo.DEVICE_ETH_IP + "--" + this.wd_DeviceInfo.DEVICE_ETH_MAC;
- return true;
- }
- else
- {
- this.bSuccess = false;
- this.Msg = "网络连接失败: " + this.wd_DeviceInfo.DEVICE_ETH_IP + "--" + this.wd_DeviceInfo.DEVICE_ETH_MAC;
- return false;
- }
- }
- catch (Exception)
- {
- return false;
- }
- }
- /// <summary>
- /// 去初始化
- /// </summary>
- protected void JHDeinit()
- {
- LedControl.JHCommDeinit();
- }
- /// <summary>
- /// 清除点阵屏界面
- /// </summary>
- public void JHErase()
- {
- LedControl.JHErase(this.hdl);
- }
- public void Start()
- {
- if (CallingList.Count > 0)//有电话
- {
- if (CurDisIndex > this.CallingList.Count - 1)
- {
- CurDisIndex = 0;
- }
- if (new TimeSpan(DateTime.Now.Ticks - this.secnow1).TotalSeconds >= Convert.ToInt16(GlobalConfigureSetting.GetConfigureSetting("STAYINGTIME")))
- {
- this.CurDisIndex++;
- if (this.CurDisIndex == this.CallingList.Count)
- {
- this.CurDisIndex = 0;
- }
- this.CallingList[CurDisIndex].PlayWithErase();
- secnow1 = DateTime.Now.Ticks;
- }
- ///
- ///5分钟如果没有挂断,系统自动删除
- ///
- for (int i = 0; i < this.CallingList.Count; i++)
- {
- if (new TimeSpan(DateTime.Now.Ticks - this.CallingList[i].addTime).TotalSeconds > 5 * 60)
- {
- this.CallingList.Remove(this.CallingList[i]);
- }
- }
- }
- else
- {
- if (this.programlist.Count == 0) //如果没有节目,则不进行处理
- {
- return;
- }
- if (this.CurDisIndex > this.programlist.Count - 1)//如果当前索引大于最大值,重置为0
- {
- this.CurDisIndex = 0;
- }
- if (this.programlist.Count > 1) //如果多于1个节目,则轮播,否则不轮播
- {
- if (new TimeSpan(DateTime.Now.Ticks - this.secnow1).TotalSeconds >= Convert.ToInt32(this.programlist[this.CurDisIndex].GetEntity().PROGRAM_STAYINGTIME))
- {
- this.CurDisIndex++;
- if (this.CurDisIndex == this.programlist.Count)
- {
- this.CurDisIndex = 0;
- }
- this.programlist[CurDisIndex].PlayWithErase();
- secnow1 = DateTime.Now.Ticks;
- }
- }
- else
- {
- this.programlist[CurDisIndex].PlayWithoutErase();
- }
- if (this.programlist[CurDisIndex].GetEntity().PROGRAM_TYPE == "2")
- {
- this.programlist[this.CurDisIndex].PlayWithoutErase();
- }
- }
- }
- public void End()
- {
- }
- }
- }
|