LED_Control.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace MeterPlugInLibrary
  7. {
  8. public class LED_Control
  9. {
  10. public LED_Control(string Ip)
  11. {
  12. int nResult;
  13. LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
  14. CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
  15. CommunicationInfo.IpStr = Ip;//给IpStr赋值LED控制卡的IP
  16. CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和248通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
  17. nResult = LedDll.LV_SetBasicInfo(ref CommunicationInfo, 2, 128, 48);//设置屏参,屏的颜色为2即为双基色,128为屏宽点数,48为屏高点数,具体函数参数说明见函数声明注示
  18. if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
  19. {
  20. string ErrStr;
  21. ErrStr = LedDll.LS_GetError(nResult);
  22. //设置失败
  23. }
  24. else
  25. {
  26. //设置成功
  27. }
  28. }
  29. public void setOneLineMsg(string Ip,string ledInfo)
  30. {
  31. int nResult;
  32. LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
  33. CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
  34. CommunicationInfo.IpStr = Ip;//给IpStr赋值LED控制卡的IP
  35. CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和248通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
  36. int hProgram;//节目句柄
  37. hProgram = LedDll.LV_CreateProgram(128, 48, 2);//根据传的参数创建节目句柄,128是屏宽点数,48是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
  38. //此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
  39. nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
  40. if (nResult != 0)
  41. {
  42. string ErrStr;
  43. ErrStr = LedDll.LS_GetError(nResult);
  44. return;
  45. }
  46. LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
  47. /*
  48. AreaRect.left = 0;
  49. AreaRect.top = 0;
  50. AreaRect.width = 128;
  51. AreaRect.height = 12;
  52. LedDll.DIGITALCLOCKAREAINFO DigitalClockAreaInfo = new LedDll.DIGITALCLOCKAREAINFO();
  53. DigitalClockAreaInfo.TimeColor = LedDll.COLOR_RED;
  54. DigitalClockAreaInfo.ShowStrFont.FontName = "宋体";
  55. DigitalClockAreaInfo.ShowStrFont.FontSize = 10;
  56. DigitalClockAreaInfo.IsShowHour = 1;
  57. DigitalClockAreaInfo.IsShowMinute = 1;
  58. nResult = LedDll.LV_AddDigitalClockArea(hProgram, 1, 1, ref AreaRect, ref DigitalClockAreaInfo);//注意区域号不能一样,详见函数声明注示
  59. //*/
  60. AreaRect.left = 0;
  61. AreaRect.top = 8;
  62. AreaRect.width = 128;
  63. AreaRect.height = 34;
  64. LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
  65. FontProp.FontName = "宋体";
  66. FontProp.FontSize = 24;
  67. FontProp.FontColor = LedDll.COLOR_RED;
  68. FontProp.FontBold = 0;
  69. //int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
  70. nResult = LedDll.LV_QuickAddSingleLineTextArea(hProgram, 1, 2, ref AreaRect, LedDll.ADDTYPE_STRING, ledInfo, ref FontProp, 4);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  71. nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
  72. LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
  73. if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
  74. {
  75. string ErrStr;
  76. ErrStr = LedDll.LS_GetError(nResult);
  77. }
  78. else
  79. {
  80. //"发送成功";
  81. }
  82. }
  83. public void setTwoLineMsg(string Ip)
  84. {
  85. int nResult;
  86. LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
  87. CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
  88. CommunicationInfo.IpStr = Ip;//给IpStr赋值LED控制卡的IP
  89. CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和248通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
  90. int hProgram;//节目句柄
  91. hProgram = LedDll.LV_CreateProgram(128, 48, 2);//根据传的参数创建节目句柄,128是屏宽点数,48是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
  92. //此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
  93. nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
  94. if (nResult != 0)
  95. {
  96. string ErrStr;
  97. ErrStr = LedDll.LS_GetError(nResult);
  98. return;
  99. }
  100. LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
  101. AreaRect.left = 0;
  102. AreaRect.top = 0;
  103. AreaRect.width = 128;
  104. AreaRect.height = 8;
  105. LedDll.DIGITALCLOCKAREAINFO DigitalClockAreaInfo = new LedDll.DIGITALCLOCKAREAINFO();
  106. DigitalClockAreaInfo.TimeColor = LedDll.COLOR_RED;
  107. DigitalClockAreaInfo.ShowStrFont.FontName = "宋体";
  108. DigitalClockAreaInfo.ShowStrFont.FontSize = 6;
  109. DigitalClockAreaInfo.IsShowHour = 1;
  110. DigitalClockAreaInfo.IsShowMinute = 1;
  111. nResult = LedDll.LV_AddDigitalClockArea(hProgram, 1, 1, ref AreaRect, ref DigitalClockAreaInfo);//注意区域号不能一样,详见函数声明注示
  112. AreaRect.left = 0;
  113. AreaRect.top = 8;
  114. AreaRect.width = 128;
  115. AreaRect.height = 20;
  116. LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
  117. FontProp.FontName = "宋体";
  118. FontProp.FontSize = 12;
  119. FontProp.FontColor = LedDll.COLOR_RED;
  120. FontProp.FontBold = 0;
  121. //int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
  122. nResult = LedDll.LV_QuickAddSingleLineTextArea(hProgram, 1, 2, ref AreaRect, LedDll.ADDTYPE_STRING, "湖南视拓信息技术", ref FontProp, 4);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  123. AreaRect.left = 0;
  124. AreaRect.top = 28;
  125. AreaRect.width = 128;
  126. AreaRect.height = 20;
  127. nResult = LedDll.LV_QuickAddSingleLineTextArea(hProgram, 1, 3, ref AreaRect, LedDll.ADDTYPE_STRING, "智能计量系统", ref FontProp, 4);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  128. nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
  129. LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
  130. if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
  131. {
  132. string ErrStr;
  133. ErrStr = LedDll.LS_GetError(nResult);
  134. }
  135. else
  136. {
  137. //"发送成功";
  138. }
  139. }
  140. #region 成品秤添加一个静止的图文区域显示重量
  141. public void setProductOneLineMsg(string Ip, string ledInfo)
  142. {
  143. int nResult;
  144. LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
  145. CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
  146. CommunicationInfo.IpStr = Ip;//给IpStr赋值LED控制卡的IP
  147. CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和248通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
  148. nResult = LedDll.LV_SetBasicInfo(ref CommunicationInfo, 2, 192, 64);//设置屏参,屏的颜色为2即为双基色,64为屏宽点数,32为屏高点数,具体函数参数说明见函数声明注示
  149. int hProgram;//节目句柄
  150. hProgram = LedDll.LV_CreateProgram(192, 64, 2);//根据传的参数创建节目句柄,128是屏宽点数,48是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
  151. //此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
  152. nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
  153. if (nResult != 0)
  154. {
  155. string ErrStr;
  156. ErrStr = LedDll.LS_GetError(nResult);
  157. return;
  158. }
  159. LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
  160. AreaRect.left = 0;
  161. AreaRect.top = 8;
  162. AreaRect.width = 192;
  163. AreaRect.height = 34;
  164. LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
  165. FontProp.FontName = "宋体";
  166. FontProp.FontSize = 24;
  167. FontProp.FontColor = LedDll.COLOR_RED;
  168. FontProp.FontBold = 0;
  169. //int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
  170. nResult = LedDll.LV_QuickAddSingleLineTextArea(hProgram, 1, 2, ref AreaRect, LedDll.ADDTYPE_STRING, ledInfo, ref FontProp, 4);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  171. nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
  172. LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
  173. if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
  174. {
  175. string ErrStr;
  176. ErrStr = LedDll.LS_GetError(nResult);
  177. }
  178. else
  179. {
  180. //"发送成功";
  181. }
  182. }
  183. public void setStaticLineMsg(string Ip, string ledInfo)
  184. {
  185. int nResult;
  186. LedDll.COMMUNICATIONINFO CommunicationInfo = new LedDll.COMMUNICATIONINFO();//定义一通讯参数结构体变量用于对设定的LED通讯,具体对此结构体元素赋值说明见COMMUNICATIONINFO结构体定义部份注示
  187. CommunicationInfo.SendType = 0;//设为固定IP通讯模式,即TCP通讯
  188. CommunicationInfo.IpStr = Ip;//给IpStr赋值LED控制卡的IP
  189. CommunicationInfo.LedNumber = 1;//LED屏号为1,注意socket通讯和248通讯不识别屏号,默认赋1就行了,485必需根据屏的实际屏号进行赋值
  190. nResult = LedDll.LV_SetBasicInfo(ref CommunicationInfo, 2, 192, 64);//设置屏参,屏的颜色为2即为双基色,64为屏宽点数,32为屏高点数,具体函数参数说明见函数声明注示
  191. int hProgram;//节目句柄
  192. hProgram = LedDll.LV_CreateProgram(192, 64, 2);//根据传的参数创建节目句柄,128是屏宽点数,48是屏高点数,2是屏的颜色,注意此处屏宽高及颜色参数必需与设置屏参的屏宽高及颜色一致,否则发送时会提示错误
  193. //此处可自行判断有未创建成功,hProgram返回NULL失败,非NULL成功,一般不会失败
  194. nResult = LedDll.LV_AddProgram(hProgram, 1, 0, 1);//添加一个节目,参数说明见函数声明注示
  195. if (nResult != 0)
  196. {
  197. string ErrStr;
  198. ErrStr = LedDll.LS_GetError(nResult);
  199. return;
  200. }
  201. LedDll.AREARECT AreaRect = new LedDll.AREARECT();//区域坐标属性结构体变量
  202. AreaRect.left = 0;
  203. AreaRect.top = 0;
  204. AreaRect.width = 192;
  205. AreaRect.height = 64;
  206. LedDll.FONTPROP FontProp = new LedDll.FONTPROP();//文字属性
  207. FontProp.FontName = "宋体";
  208. FontProp.FontSize = 10;
  209. FontProp.FontColor = LedDll.COLOR_RED;
  210. FontProp.FontBold = 0;
  211. //int nsize = System.Runtime.InteropServices.Marshal.SizeOf(typeof(LedDll.FONTPROP));
  212. nResult = LedDll.LV_AddImageTextArea(hProgram, 1, 2, ref AreaRect, 0);
  213. //nResult = LedDll.LV_QuickAddSingleLineTextArea(hProgram, 1, 2, ref AreaRect, LedDll.ADDTYPE_STRING, ledInfo, ref FontProp, 4);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  214. nResult = LedDll.LV_AddStaticTextToImageTextArea(hProgram, 1, 2, LedDll.ADDTYPE_STRING, ledInfo, ref FontProp, 1, 2, 1);//快速通过字符添加一个单行文本区域,函数见函数声明注示
  215. nResult = LedDll.LV_Send(ref CommunicationInfo, hProgram);//发送,见函数声明注示
  216. LedDll.LV_DeleteProgram(hProgram);//删除节目内存对象,详见函数声明注示
  217. if (nResult != 0)//如果失败则可以调用LV_GetError获取中文错误信息
  218. {
  219. string ErrStr;
  220. ErrStr = LedDll.LS_GetError(nResult);
  221. }
  222. else
  223. {
  224. //"发送成功";
  225. }
  226. }
  227. #endregion
  228. }
  229. }