LedLatticeScreen.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. using System.Collections.Generic;
  2. using System.Windows.Forms;
  3. using System.Threading;
  4. using HNWD.Pregrant.BusinessLogic;
  5. using HNWD.Pregrant.Common;
  6. using HNWD.Pregrant.Model;
  7. using System;
  8. using System.Net.NetworkInformation;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace HNWD.LatticeScreen.Server
  12. {
  13. internal class LedLatticeScreen
  14. {
  15. public List<ProgramBase> programlist = new List<ProgramBase>();
  16. public List<ProgramBase> CallingList = new List<ProgramBase>();
  17. private static readonly object obj = new object();
  18. public int CurDisIndex = 0;
  19. public string DeviceID = "0";
  20. public long secnow1 = 0;
  21. public IntPtr hdl = IntPtr.Zero;
  22. protected IntPtr ptl = IntPtr.Zero;
  23. protected IntPtr pargs = IntPtr.Zero;
  24. public WD_DeviceInfo wd_DeviceInfo;
  25. public int Width = 0;
  26. public int Height = 0;
  27. public bool bSuccess = true;
  28. public string Msg = "操作成功";
  29. public LedLatticeScreen(WD_DeviceInfo wd_DeviceInfo)
  30. {
  31. this.wd_DeviceInfo = wd_DeviceInfo;
  32. this.DeviceID = this.wd_DeviceInfo.ID;
  33. this.Width = wd_DeviceInfo.DEVICE_MODEL.Contains(",") ? Convert.ToInt16(wd_DeviceInfo.DEVICE_MODEL.Split(',')[0]) : (Int16)192;
  34. this.Height = wd_DeviceInfo.DEVICE_MODEL.Contains(",") ? Convert.ToInt16(wd_DeviceInfo.DEVICE_MODEL.Split(',')[1]) : (Int16)32;
  35. this.Initialize();
  36. }
  37. /// <summary>
  38. /// 清除节目列表
  39. /// </summary>
  40. private void ClearProgram()
  41. {
  42. this.programlist.Clear();
  43. }
  44. /// <summary>
  45. /// 添加节目列表
  46. /// </summary>
  47. /// <param name="deviceid"></param>
  48. public void AddProgram(string deviceid)
  49. {
  50. this.ClearProgram();
  51. WD_ProgramInfoBusinessLogic wd = new WD_ProgramInfoBusinessLogic(deviceid, "");
  52. ModelExtBase<WD_ProgramInfo> wd_ProgramInfoExt = wd.QueryByParentID();
  53. for (int i = 0; i < wd_ProgramInfoExt.messageDataList.Count; i++)
  54. {
  55. if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "0")
  56. {
  57. TextProgram tp = new TextProgram(this);
  58. tp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
  59. this.programlist.Add(tp);
  60. }
  61. if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "1")
  62. {
  63. MultPixelProgram mpp = new MultPixelProgram(this);
  64. mpp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
  65. this.programlist.Add(mpp);
  66. }
  67. if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "2" && wd_ProgramInfoExt.messageDataList[i].PROGRAM_FORMAT.Contains("两行"))
  68. {
  69. ClockDateTimeProgram cdtp = new ClockDateTimeProgram(this);
  70. cdtp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
  71. this.programlist.Add(cdtp);
  72. }
  73. else if (wd_ProgramInfoExt.messageDataList[i].PROGRAM_TYPE == "2" && !wd_ProgramInfoExt.messageDataList[i].PROGRAM_FORMAT.Contains("两行"))
  74. {
  75. ClockCustomizedProgram ccp = new ClockCustomizedProgram(this);
  76. ccp.SetEntity(wd_ProgramInfoExt.messageDataList[i]);
  77. this.programlist.Add(ccp);
  78. }
  79. }
  80. }
  81. /// <summary>
  82. /// 初始化
  83. /// </summary>
  84. protected void JHInit()
  85. {
  86. LedControl.JHCommInit();
  87. }
  88. protected void Initialize()
  89. {
  90. int res;
  91. LedControl.JHCommInit();
  92. /* 本例只为演示功能,更多接口请调用DllImport来获得,千万要注意C#参数和C Dll中的接口要一一对应,否则会找不到函数入口点或调用出错 */
  93. /* JHCommInit和JHCommDeinit接口可以放在应用程序的初始化和退出时分别调用,且必须调用,否则TCP和UDP不能正常通讯,本例中分别放在Form1_Load和Form1_FormClosed中调用 */
  94. /* 创建控制卡实例 */
  95. res = LedControl.JHCreateInst(ref hdl, 1);
  96. if (res != LedControl.JR_OK)
  97. {
  98. this.Msg = "创建控制卡实例失败, 错误代码:" + res;
  99. this.bSuccess = false;
  100. return;
  101. }
  102. /* 获得TCP的传输接口 */
  103. res = LedControl.JHCommGetTransportlayer(ref ptl, 0/* 0: tcp; 1: udp; 2: ether; 3:serial port; */);
  104. if (res != LedControl.JR_OK)
  105. {
  106. LedControl.JHDeleteInst(hdl);
  107. this.Msg = "获得传输层接口失败, 错误代码:" + res;
  108. this.bSuccess = false;
  109. return;
  110. }
  111. /* 获得通讯参数 */
  112. //res = LedControl.JHCommGetNetArgStruct(ref pargs, this.wd_DeviceInfo.DEVICE_ETH_IP, 30000, 5000);
  113. res = LedControl.JHCommGetNetArgStruct(ref pargs, this.wd_DeviceInfo.DEVICE_ETH_IP, 5005, 5000);
  114. //res = LedControl.JHCommGetSerialportArgStruct(ref pargs, "COM1", 115200, 8, 0, 0, 5000);
  115. if (res != LedControl.JR_OK)
  116. {
  117. LedControl.JHDeleteInst(hdl);
  118. this.Msg = "获得传输层参数失败, 错误代码:" + res;
  119. this.bSuccess = false;
  120. return;
  121. }
  122. /* 为控制卡绑定传输层接口及通讯参数 */
  123. res = LedControl.JHMountTransportLayer(hdl, ptl, pargs);
  124. if (res != LedControl.JR_OK)
  125. {
  126. LedControl.JHCommReleaseArgStruct(pargs);
  127. LedControl.JHDeleteInst(hdl);
  128. this.Msg = "挂载传输层接口失败, 错误代码:" + res;
  129. this.bSuccess = false;
  130. return;
  131. }
  132. }
  133. public bool PingIpOrDomainName()
  134. {
  135. try
  136. {
  137. Ping objPingSender = new Ping();
  138. PingOptions objPinOptions = new PingOptions();
  139. objPinOptions.DontFragment = true;
  140. string data = "";
  141. byte[] buffer = Encoding.UTF8.GetBytes(data);
  142. int intTimeout = 120;
  143. PingReply objPinReply = objPingSender.Send(this.wd_DeviceInfo.DEVICE_ETH_IP, intTimeout, buffer, objPinOptions);
  144. string strInfo = objPinReply.Status.ToString();
  145. if (strInfo.ToLower() == "success")
  146. {
  147. this.bSuccess = true;
  148. this.Msg = "网络连接成功: " + this.wd_DeviceInfo.DEVICE_ETH_IP + "--" + this.wd_DeviceInfo.DEVICE_ETH_MAC;
  149. return true;
  150. }
  151. else
  152. {
  153. this.bSuccess = false;
  154. this.Msg = "网络连接失败: " + this.wd_DeviceInfo.DEVICE_ETH_IP + "--" + this.wd_DeviceInfo.DEVICE_ETH_MAC;
  155. return false;
  156. }
  157. }
  158. catch (Exception)
  159. {
  160. return false;
  161. }
  162. }
  163. /// <summary>
  164. /// 去初始化
  165. /// </summary>
  166. protected void JHDeinit()
  167. {
  168. LedControl.JHCommDeinit();
  169. }
  170. /// <summary>
  171. /// 清除点阵屏界面
  172. /// </summary>
  173. public void JHErase()
  174. {
  175. LedControl.JHErase(this.hdl);
  176. }
  177. public void Start()
  178. {
  179. if (CallingList.Count > 0)//有电话
  180. {
  181. if (CurDisIndex > this.CallingList.Count - 1)
  182. {
  183. CurDisIndex = 0;
  184. }
  185. if (new TimeSpan(DateTime.Now.Ticks - this.secnow1).TotalSeconds >= Convert.ToInt16(GlobalConfigureSetting.GetConfigureSetting("STAYINGTIME")))
  186. {
  187. this.CurDisIndex++;
  188. if (this.CurDisIndex == this.CallingList.Count)
  189. {
  190. this.CurDisIndex = 0;
  191. }
  192. this.CallingList[CurDisIndex].PlayWithErase();
  193. secnow1 = DateTime.Now.Ticks;
  194. }
  195. ///
  196. ///5分钟如果没有挂断,系统自动删除
  197. ///
  198. for (int i = 0; i < this.CallingList.Count; i++)
  199. {
  200. if (new TimeSpan(DateTime.Now.Ticks - this.CallingList[i].addTime).TotalSeconds > 5 * 60)
  201. {
  202. this.CallingList.Remove(this.CallingList[i]);
  203. }
  204. }
  205. }
  206. else
  207. {
  208. if (this.programlist.Count == 0) //如果没有节目,则不进行处理
  209. {
  210. return;
  211. }
  212. if (this.CurDisIndex > this.programlist.Count - 1)//如果当前索引大于最大值,重置为0
  213. {
  214. this.CurDisIndex = 0;
  215. }
  216. if (this.programlist.Count > 1) //如果多于1个节目,则轮播,否则不轮播
  217. {
  218. if (new TimeSpan(DateTime.Now.Ticks - this.secnow1).TotalSeconds >= Convert.ToInt32(this.programlist[this.CurDisIndex].GetEntity().PROGRAM_STAYINGTIME))
  219. {
  220. this.CurDisIndex++;
  221. if (this.CurDisIndex == this.programlist.Count)
  222. {
  223. this.CurDisIndex = 0;
  224. }
  225. this.programlist[CurDisIndex].PlayWithErase();
  226. secnow1 = DateTime.Now.Ticks;
  227. }
  228. }
  229. else
  230. {
  231. this.programlist[CurDisIndex].PlayWithoutErase();
  232. }
  233. if (this.programlist[CurDisIndex].GetEntity().PROGRAM_TYPE == "2")
  234. {
  235. this.programlist[this.CurDisIndex].PlayWithoutErase();
  236. }
  237. }
  238. }
  239. public void End()
  240. {
  241. }
  242. }
  243. }