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 programlist = new List(); public List CallingList = new List(); 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(); } /// /// 清除节目列表 /// private void ClearProgram() { this.programlist.Clear(); } /// /// 添加节目列表 /// /// public void AddProgram(string deviceid) { this.ClearProgram(); WD_ProgramInfoBusinessLogic wd = new WD_ProgramInfoBusinessLogic(deviceid, ""); ModelExtBase 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); } } } /// /// 初始化 /// 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; } } /// /// 去初始化 /// protected void JHDeinit() { LedControl.JHCommDeinit(); } /// /// 清除点阵屏界面 /// 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() { } } }