Led5kSDK.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6. namespace ONNONLed5KSDKD
  7. {
  8. public class Led5kSDK
  9. {
  10. #region
  11. public class bx5k_err
  12. {
  13. public const int ERR_NO = 0; //No Error
  14. public const int ERR_OUTOFGROUP = 1; //Command Group Error
  15. public const int ERR_NOCMD = 2; //Command Not Found
  16. public const int ERR_BUSY = 3; //The Controller is busy now
  17. public const int ERR_MEMORYVOLUME = 4; //Out of the Memory Volume
  18. public const int ERR_CHECKSUM = 5; //CRC16 Checksum Error
  19. public const int ERR_FILENOTEXIST = 6; //File Not Exist
  20. public const int ERR_FLASH = 7;//Flash Access Error
  21. public const int ERR_FILE_DOWNLOAD = 8; //File Download Error
  22. public const int ERR_FILE_NAME = 9; //Filename Error
  23. public const int ERR_FILE_TYPE = 10;//File type Error
  24. public const int ERR_FILE_CRC16 = 11;//File CRC16 Error
  25. public const int ERR_FONT_NOT_EXIST = 12;//Font Library Not Exist
  26. public const int ERR_FIRMWARE_TYPE = 13;//Firmware Type Error (Check the controller type)
  27. public const int ERR_DATE_TIME_FORMAT = 14;//Date Time format error
  28. public const int ERR_FILE_EXIST = 15;//File Exist for File overwrite
  29. public const int ERR_FILE_BLOCK_NUM = 16;//File block number error
  30. public const int ERR_COMMUNICATE = 100;//通信失败
  31. public const int ERR_PROTOCOL = 101;//协议数据不正确
  32. public const int ERR_TIMEOUT = 102;//通信超时
  33. public const int ERR_NETCLOSE = 103;//通信断开
  34. public const int ERR_INVALID_HAND = 104;//无效句柄
  35. public const int ERR_PARAMETER = 105;//参数错误
  36. public const int ERR_SHOULDREPEAT = 106;//需要重复上次数据包
  37. public const int ERR_FILE = 107;//无效文件
  38. }
  39. //public static string GetError(int err)
  40. //{
  41. // string str = "";
  42. // switch (err)
  43. // {
  44. // case bx5k_err.ERR_OUTOFGROUP:
  45. // str = GobalData.allcatalog.GetString("Command Group Error");
  46. // break;
  47. // case bx5k_err.ERR_NOCMD:
  48. // str = GobalData.allcatalog.GetString("Command Not Found");
  49. // break;
  50. // case bx5k_err.ERR_BUSY:
  51. // str = GobalData.allcatalog.GetString("The Controller is busy now");
  52. // break;
  53. // case bx5k_err.ERR_MEMORYVOLUME:
  54. // str = GobalData.allcatalog.GetString("Out of the Memory Volume");
  55. // break;
  56. // case bx5k_err.ERR_CHECKSUM:
  57. // str = GobalData.allcatalog.GetString("CRC16 Checksum Error");
  58. // break;
  59. // case bx5k_err.ERR_FILENOTEXIST:
  60. // str = GobalData.allcatalog.GetString("File Not Exist");
  61. // break;
  62. // case bx5k_err.ERR_FLASH:
  63. // str = GobalData.allcatalog.GetString("Flash Access Error");
  64. // break;
  65. // case bx5k_err.ERR_FILE_DOWNLOAD:
  66. // str = GobalData.allcatalog.GetString("File Download Error");
  67. // break;
  68. // case bx5k_err.ERR_FILE_NAME:
  69. // str = GobalData.allcatalog.GetString("Filename Error");
  70. // break;
  71. // case bx5k_err.ERR_FILE_TYPE:
  72. // str = GobalData.allcatalog.GetString("File type Error");
  73. // break;
  74. // case bx5k_err.ERR_FILE_CRC16:
  75. // str = GobalData.allcatalog.GetString("File CRC16 Error");
  76. // break;
  77. // case bx5k_err.ERR_FONT_NOT_EXIST:
  78. // str = GobalData.allcatalog.GetString("Font Library Not Exist");
  79. // break;
  80. // case bx5k_err.ERR_FIRMWARE_TYPE:
  81. // str = GobalData.allcatalog.GetString("Firmware Type Error");
  82. // break;
  83. // case bx5k_err.ERR_DATE_TIME_FORMAT:
  84. // str = GobalData.allcatalog.GetString("Date Time format error");
  85. // break;
  86. // case bx5k_err.ERR_FILE_EXIST:
  87. // str = GobalData.allcatalog.GetString("File Exist for File overwrite");
  88. // break;
  89. // case bx5k_err.ERR_FILE_BLOCK_NUM:
  90. // str = GobalData.allcatalog.GetString("File block number error");
  91. // break;
  92. // case bx5k_err.ERR_COMMUNICATE:
  93. // str = GobalData.allcatalog.GetString("Communication failure");
  94. // break;
  95. // case bx5k_err.ERR_PROTOCOL:
  96. // str = GobalData.allcatalog.GetString("The protocol data is incorrect");
  97. // break;
  98. // case bx5k_err.ERR_TIMEOUT:
  99. // str = GobalData.allcatalog.GetString("Communication timeout");
  100. // break;
  101. // case bx5k_err.ERR_NETCLOSE:
  102. // str = GobalData.allcatalog.GetString("Communication disconnection");
  103. // break;
  104. // case bx5k_err.ERR_INVALID_HAND:
  105. // str = GobalData.allcatalog.GetString("Invalid handle");
  106. // break;
  107. // case bx5k_err.ERR_PARAMETER:
  108. // str = GobalData.allcatalog.GetString("Parameter error");
  109. // break;
  110. // case bx5k_err.ERR_SHOULDREPEAT:
  111. // str = GobalData.allcatalog.GetString("need to repeat the last packet");
  112. // break;
  113. // case bx5k_err.ERR_FILE:
  114. // str = GobalData.allcatalog.GetString("Invalid file");
  115. // break;
  116. // default:
  117. // str = GobalData.allcatalog.GetString("unknown error");
  118. // break;
  119. // }
  120. // return str;
  121. //}
  122. #endregion
  123. //串口停止位
  124. public enum serial_stopbits : byte
  125. {
  126. COM_ONESTOPBIT = 0,
  127. COM_ONE5STOPBITS = 1,
  128. COM_TWOSTOPBITS = 2,
  129. }
  130. //串口校验模式
  131. public enum serial_parity : byte
  132. {
  133. COM_NOPARITY = 0,
  134. COM_ODDPARITY = 1,
  135. COM_EVENPARITY = 2,
  136. COM_MARKPARITY = 3,
  137. COM_SPACEPARITY = 4,
  138. }
  139. //串口数据位
  140. public enum serial_databits : byte
  141. {
  142. COM_4BITS = 4,
  143. COM_5BITS = 5,
  144. COM_6BITS = 6,
  145. COM_7BITS = 7,
  146. COM_8BITS = 8,
  147. }
  148. //控制器类型
  149. public enum bx_5k_card_type : byte
  150. {
  151. BX_Any = 0xFE,
  152. BX_5K1 = 0x51,
  153. BX_5K2 = 0x58,
  154. BX_5MK2 = 0x53,
  155. BX_5MK1 = 0x54,
  156. BX_5K1Q_YY = 0x5c,
  157. BX_6K1 = 0x61,
  158. BX_6K2 = 0x62,
  159. BX_6K3 = 0x63,
  160. BX_6K1_YY = 0x64,
  161. BX_6K2_YY = 0x65,
  162. BX_6K3_YY = 0x66,
  163. }
  164. //-------区域格式------
  165. // area header | data |
  166. //---------------------
  167. //节目内区域定义
  168. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  169. public struct bx_5k_area_header
  170. {
  171. public byte AreaType;
  172. public ushort AreaX;
  173. public ushort AreaY;
  174. public ushort AreaWidth;
  175. public ushort AreaHeight;
  176. public byte DynamicAreaLoc;
  177. public byte Lines_sizes;
  178. public byte RunMode;
  179. public short Timeout;
  180. public byte Reserved1;
  181. public byte Reserved2;
  182. public byte Reserved3;
  183. public byte SingleLine;
  184. public byte NewLine;
  185. public byte DisplayMode;
  186. public byte ExitMode;
  187. public byte Speed;
  188. public byte StayTime;
  189. public int DataLen;
  190. }
  191. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  192. public struct bx_5k_sound
  193. {
  194. public byte StoreFlag;
  195. public byte SoundPerson;//一个字节
  196. public byte SoundVolum;
  197. public byte SoundSpeed;
  198. public byte SoundDataMode;
  199. public int SoundReplayTimes;
  200. public int SoundReplayDelay;
  201. public byte SoundReservedParaLen;
  202. public int SoundDataLen;
  203. }
  204. [StructLayoutAttribute(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
  205. public struct bx_5k_table
  206. {
  207. public short CellDataLen0;
  208. public byte CellDataRow0;//一个字节
  209. public byte CellDataLine0;
  210. public byte CellLoc;
  211. public byte[] Reserved;
  212. public string CellData;
  213. }
  214. [System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute(System.Runtime.InteropServices.CallingConvention.StdCall)]
  215. public delegate void CallBackClientClose(uint hand, int err);
  216. //初始化动态库
  217. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  218. public static extern void InitSdk(byte minorVer, byte majorVer);
  219. //释放动态库
  220. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  221. public static extern void ReleaseSdk();
  222. //创建广播通讯模式
  223. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  224. public static extern uint CreateBroadCast(byte[] broad_ip, uint broad_port, bx_5k_card_type card_type, byte[] barcode,byte Option, int mode);
  225. //创建固定IP通讯模式
  226. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  227. public static extern uint CreateClient(byte[] led_ip, uint led_port, bx_5k_card_type card_type, int tmout_sec, int mode, CallBackClientClose pCloseFunc);
  228. //创建TCP Modbus通讯
  229. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  230. public static extern uint CreateTcpModbus(byte[] led_ip, bx_5k_card_type card_type, CallBackClientClose pCloseFunc);
  231. //创建串口通讯
  232. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  233. public static extern uint CreateComClient(byte com, uint baudrate, bx_5k_card_type card_type, int mode, ushort ScreenID);
  234. //创建串口Modbus通讯
  235. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  236. public static extern uint CreateComModbus(byte com, uint baudrate, serial_parity Parity, serial_databits DataBits,
  237. serial_stopbits StopBits, bx_5k_card_type card_type, ushort ScreenID);
  238. //销毁通讯
  239. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  240. public static extern void Destroy(uint dwHand);
  241. //设置通讯超时
  242. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  243. public static extern void SetTimeout(uint dwHand, uint nSec);
  244. //ping
  245. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  246. public static extern int CON_PING(uint dwHand);
  247. //复位
  248. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  249. public static extern int CON_Reset(uint dwHand);
  250. //查询控制器状态
  251. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  252. public static extern int CON_ControllerStatus(uint dwHand, byte[] pStatus, ref ushort len);
  253. //查询字库信息
  254. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  255. public static extern int CON_CheckCurrentFont(uint dwHand, byte[] fontStatus, ref ushort len);
  256. //回读客户信息
  257. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  258. public static extern int CON_CheckCurrentCustomer(uint dwHand, byte[] CustomerStatus, ref ushort len);
  259. //参数回读
  260. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  261. public static extern int CON_ReadScreen(uint dwHand, byte[] ScreenStatus, ref ushort len);
  262. //校时
  263. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  264. public static extern int CON_SytemClockCorrect(uint dwHand);
  265. //查询固件状态
  266. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  267. public static extern int CON_CheckCurrentFirmware(uint dwHand, byte[] FirmwareName, byte[] FirmwareVersion, byte[] FirmwareDateTime);
  268. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  269. public static extern int OFS_SendFirmWareData(uint dwHand, byte overwrite, byte[] pFileName, byte[] FirmWareData, int FirmWareDataLen, CloseFunc pCloseFunc);
  270. //激活固件
  271. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  272. public static extern int CON_FirmwareActivate(uint dwHand, byte[] FirmwareName);
  273. //设置屏号
  274. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  275. public static extern int CON_SetScreenID(uint dwHand, ushort newScreenID);
  276. //读取屏号
  277. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  278. public static extern int CON_ReadScreenID(uint dwHand, ref ushort pScreenID);
  279. //强制开关机
  280. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  281. public static extern int SCREEN_ForceOnOff(uint dwHand, byte OnOffFlag);
  282. //定时开关机
  283. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  284. public static extern int SCREEN_TimeTurnOnOff(uint dwHand, byte[] pTimer, int nGroup);
  285. //亮度
  286. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  287. public static extern int SCREEN_SetBrightness(uint dwHand, byte BrightnessType, byte CurrentBrightness, byte[] BrightnessValue);
  288. //设置上电等待时间 未使用
  289. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  290. public static extern int SCREEN_SetWaitTime(uint dwHand, byte WaitTime);
  291. //解锁节目
  292. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  293. public static extern int SCREEN_LockProgram(uint dwHand, byte LockFlag, byte StoreMode, byte[] ProgramFileName);
  294. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  295. public static extern int SCREEN_DelDynamicArea(uint dwHand, byte DeleteAreaId);
  296. //动态区
  297. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  298. public static extern int SCREEN_SendDynamicArea(uint dwHand, bx_5k_area_header header, ushort TextLen, byte[] AreaText);
  299. //语音
  300. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  301. public static extern int SCREEN_SendSound(uint dwHand, bx_5k_sound sound, int TextLen, byte[] AreaText);
  302. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  303. public static extern int SCREEN_SendSoundDynamicArea(uint dwHand, bx_5k_area_header header, ushort TextLen, byte[] AreaText, byte SoundMode, byte SoundPerson, byte SoundVolume, byte SoundSpeed, int sound_len, byte[] sounddata);
  304. //测试屏幕 未使用
  305. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  306. public static extern int SCREEN_Test(uint dwHand, byte TestTime);
  307. //取消定时开关
  308. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  309. public static extern int SCREEN_CancelTimeOnOff(uint dwHand);
  310. #region 设置特殊动态区动态
  311. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  312. public static extern int BX5MK_SetSpecialAppDynamic(uint dwHand, ushort AreaX, ushort AreaY, ushort AreaW, ushort AreaH,
  313. byte DataType, byte Pagetotal, byte RunState, ushort Timeout, byte SingleLine, byte Lines_sizes, byte NewLine, ushort StayTime);
  314. //发送分页数据
  315. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  316. public static extern int BX5MK_SendPageData(uint dwHand, byte PageNum, ushort PageDataLen, byte[] PageData);
  317. //发送点阵信息
  318. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  319. public static extern int BX5MK_SendLatticeMessage(uint dwHand, byte BlockFlag, ushort BlockAddr, byte[] BlockData, ushort BlockDataLen);
  320. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  321. public static extern int BX5MK_DelSpecialAppDynamic(uint dwHand);
  322. //设置IP
  323. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  324. public static extern int BX5MK_SetIPAddress(uint dwHand, byte ConnnectMode, byte[] ip, byte[] SubnetMask, byte[] Gateway, ushort port,
  325. byte ServerMode, byte[] ServerIPAddress, ushort ServerPort, byte[] ServerAccessPassword, ushort HeartBeatInterval, byte[] NetID);
  326. //设置MAC地址
  327. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  328. public static extern int BX5MK_SetMACAddress(uint dwHand, byte[] MAC);
  329. //设置特殊动态区动态
  330. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  331. public static extern int BX5MK_SetSpecialAppDynamic(int dwHand, ushort AreaX, ushort AreaY, ushort AreaW, ushort AreaH, byte DataType, byte Pagetotal,
  332. byte RunState, ushort Timeout, byte SingleLine, byte Lines_sizes, byte NewLine, ushort StayTime);
  333. //网络搜索
  334. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  335. public static extern int BX5MK_WebSearch(uint dwHand, ref ushort Status, ref ushort Error, byte[] IP,
  336. byte[] SubNetMask, byte[] Gate, ref ushort Port, byte[] Mac, byte[] NetID);
  337. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  338. public static extern int BX5MK_DelPageData(uint dwHand, byte PageLog);
  339. #endregion
  340. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  341. public static extern int OFS_Formatting(uint dwHand);
  342. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  343. public static extern int OFS_DeleteFile(uint dwHand, ushort FileNumber, byte[] pFileNameList);
  344. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  345. public static extern int OFS_BeginSendMultiFiles(uint dwHand);
  346. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  347. public static extern int OFS_SendFile(uint dwHand, byte overwrite, byte[] pFilePath);
  348. //发送节目
  349. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  350. public static extern int OFS_SendFileData(uint dwHand, byte overwrite, byte[] pFileName, ushort DisplayType, byte PlayTimes,
  351. byte[] ProgramLife, byte ProgramWeek, byte ProgramTime, byte[] Period, byte AreaNum, byte[] AreaDataList, int AreaDataListLen);
  352. //添加扫描
  353. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  354. public static extern int OFS_SendScanData(uint dwHand, byte overwrite, byte[] pFileName, byte[] ScanData, int ScanDataLen);
  355. //添加字库
  356. public delegate void CloseFunc(int total, int sendlen);
  357. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  358. public static extern int OFS_SendFontData(uint dwHand, byte overwrite, byte[] pFileName, byte FontWidth, byte FontHeight,
  359. byte[] LibData, int LibData_len, byte FontEncode, CloseFunc pCloseFunc);
  360. //设置屏参
  361. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  362. public static extern int OFS_SendScreenData(uint dwHand, byte overwrite, byte[] pFileName, ushort Address, byte Baudrate,
  363. ushort ScreenWith, ushort ScreenHeight, byte Color, byte MirrorMode, byte OE, byte DA, byte RowOrder, byte FreqPar,
  364. byte OEAngle, byte CommTimeout, byte TipLanguage, byte LatticeMode);
  365. //结束写文件
  366. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  367. public static extern int OFS_EndSendMultiFiles(uint dwHand);
  368. //设置客户信息
  369. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  370. public static extern int OFS_SetFontInformation(uint dwHand, byte OverWrite, byte[] ClientMsg);
  371. public delegate void CallBackCon(uint dwHand, string pid);
  372. public delegate void CallBackLedClose(uint dwHand, string pid, int err_code);
  373. //启动gprs服务器
  374. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  375. public static extern bool StartGprsServer(uint port, CallBackCon pCallBackCon, CallBackLedClose pCallBackLedClose);
  376. //关闭gprs服务器
  377. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  378. public static extern void CloseGprsServer();
  379. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  380. public static extern void SetGprsAliveTick(uint dwHand, int time_sec);
  381. //表格
  382. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  383. public static extern int OFS_SendTable(uint dwHand, ushort OriginX, ushort OriginY, ushort TableWidth, ushort TableHeight, byte RowNum, byte LineNum, byte CellNum, byte[] TableDataList, int TableDataListLen);
  384. //扫描
  385. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  386. public static extern int SendAndRecvBuff(uint dwHand, byte cmd_group, byte cmd, byte[] cmd_data, ushort data_len, byte[] recv_data, ref short p_recv_len);
  387. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  388. public static extern int SendBuff(uint dwHand, byte cmd_group, byte cmd, byte[] cmd_data, ushort data_len);
  389. //发送多动态区
  390. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  391. public static extern int SCREEN_SendDynamicAreas(uint dwHand, byte AreaNum, ushort TextLen, byte[] AreaText);
  392. // 网络搜索
  393. [DllImport("Led5kSDK.dll", CharSet = CharSet.Unicode)]
  394. public static extern int BX5MK_WebSearch(uint dwHand, byte[] recv_buff, ushort[] recv_len);
  395. }
  396. public class ItemObject
  397. {
  398. public string Text = "";
  399. public uint Value = 0;//可以多个
  400. public ItemObject(string _text, uint _value)
  401. {
  402. Text = _text;
  403. Value = _value;
  404. }
  405. }
  406. public class Led5kstaticArea
  407. {
  408. public Led5kSDK.bx_5k_area_header header;
  409. public string text;
  410. public byte[] AreaToByteArray()
  411. {
  412. //计算header的大小:结构体bx_5k_area_header的大小
  413. ONNONLed5KSDKD.Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
  414. int hsz = Marshal.SizeOf(tu);
  415. //计算len的大小
  416. text = text.Replace("₩₩F", "\\F");
  417. List<byte[]> Byte_Area = new List<byte[]>();
  418. int Byte_t = 0;
  419. string[] str_Area = text.Trim().Split('\\');
  420. int font = 0;
  421. for (int n = 0; n < str_Area.Length; n++)
  422. {
  423. if (n > 0 && str_Area[n].Length > 1)
  424. {
  425. if (str_Area[n].Substring(0, 2).Equals("FK"))
  426. {
  427. font = 1;
  428. if (str_Area[n].Length > 5)
  429. {
  430. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 5));
  431. byte[] special = new byte[special_1.Length + 1];
  432. special[0] = 0x5c;
  433. for (int c = 0; c < special_1.Length; c++)
  434. {
  435. special[c + 1] = special_1[c];
  436. }
  437. Byte_Area.Add(special);
  438. Byte_t += special.Length;
  439. string Area_str = str_Area[n].Remove(0, 5);
  440. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  441. for (int k = 0; k < Korean.Length / 2; k++)
  442. {
  443. byte a = Korean[k * 2];
  444. Korean[k * 2] = Korean[k * 2 + 1];
  445. Korean[k * 2 + 1] = a;
  446. }
  447. Byte_Area.Add(Korean);
  448. Byte_t += Korean.Length;
  449. }
  450. else
  451. {
  452. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  453. byte[] special = new byte[special_1.Length + 1];
  454. special[0] = 0x5c;
  455. for (int c = 0; c < special_1.Length; c++)
  456. {
  457. special[c + 1] = special_1[c];
  458. }
  459. Byte_Area.Add(special);
  460. Byte_t += special.Length;
  461. }
  462. }
  463. else if (str_Area[n].Substring(0, 2).Equals("FE") || str_Area[n].Substring(0, 2).Equals("FO") || str_Area[n].Substring(0, 2).Equals("WF") || str_Area[n].Substring(0, 2).Equals("WC"))
  464. {
  465. font = 0;
  466. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  467. byte[] special = new byte[special_1.Length + 1];
  468. special[0] = 0x5c;
  469. for (int c = 0; c < special_1.Length; c++)
  470. {
  471. special[c + 1] = special_1[c];
  472. }
  473. Byte_Area.Add(special);
  474. Byte_t += special.Length;
  475. }
  476. else if (str_Area[n].Substring(0, 1).Equals("C") || str_Area[n].Substring(0, 1).Equals("D") || str_Area[n].Substring(0, 1).Equals("B") || str_Area[n].Substring(0, 1).Equals("T"))
  477. {
  478. if (font == 1)
  479. {
  480. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 2));
  481. byte[] special = new byte[special_1.Length + 1];
  482. special[0] = 0x5c;
  483. for (int c = 0; c < special_1.Length; c++)
  484. {
  485. special[c + 1] = special_1[c];
  486. }
  487. Byte_Area.Add(special);
  488. Byte_t += special.Length;
  489. string Area_str = str_Area[n].Remove(0, 2);
  490. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  491. for (int k = 0; k < Korean.Length / 2; k++)
  492. {
  493. byte a = Korean[k * 2];
  494. Korean[k * 2] = Korean[k * 2 + 1];
  495. Korean[k * 2 + 1] = a;
  496. }
  497. Byte_Area.Add(Korean);
  498. Byte_t += Korean.Length;
  499. }
  500. else
  501. {
  502. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  503. byte[] special = new byte[special_1.Length + 1];
  504. special[0] = 0x5c;
  505. for (int c = 0; c < special_1.Length; c++)
  506. {
  507. special[c + 1] = special_1[c];
  508. }
  509. Byte_Area.Add(special);
  510. Byte_t += special.Length;
  511. }
  512. }
  513. else if (str_Area[n].Substring(0, 1).Equals("n"))
  514. {
  515. if (font == 1)
  516. {
  517. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 1));
  518. byte[] special = new byte[special_1.Length + 1];
  519. special[0] = 0x5c;
  520. for (int c = 0; c < special_1.Length; c++)
  521. {
  522. special[c + 1] = special_1[c];
  523. }
  524. Byte_Area.Add(special);
  525. Byte_t += special.Length;
  526. string Area_str = str_Area[n].Remove(0, 1);
  527. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  528. for (int k = 0; k < Korean.Length / 2; k++)
  529. {
  530. byte a = Korean[k * 2];
  531. Korean[k * 2] = Korean[k * 2 + 1];
  532. Korean[k * 2 + 1] = a;
  533. }
  534. Byte_Area.Add(Korean);
  535. Byte_t += Korean.Length;
  536. }
  537. else
  538. {
  539. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  540. byte[] special = new byte[special_1.Length + 1];
  541. special[0] = 0x5c;
  542. for (int c = 0; c < special_1.Length; c++)
  543. {
  544. special[c + 1] = special_1[c];
  545. }
  546. Byte_Area.Add(special);
  547. Byte_t += special.Length;
  548. }
  549. }
  550. }
  551. else
  552. {
  553. if (n > 0)
  554. {
  555. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  556. byte[] special = new byte[special_1.Length + 1];
  557. special[0] = 0x5c;
  558. for (int c = 0; c < special_1.Length; c++)
  559. {
  560. special[c + 1] = special_1[c];
  561. }
  562. Byte_Area.Add(special);
  563. Byte_t += special.Length;
  564. }
  565. else
  566. {
  567. byte[] special = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  568. Byte_Area.Add(special);
  569. Byte_t += special.Length;
  570. }
  571. }
  572. }
  573. byte[] tmp = new byte[Byte_t];
  574. int g = 0;
  575. for (int n = 0; n < Byte_Area.Count(); n++)
  576. {
  577. if (n > 0)
  578. {
  579. for (int j = 0; j < Byte_Area[n].Length; j++)
  580. {
  581. tmp[g + j] = Byte_Area[n][j];
  582. }
  583. g += Byte_Area[n].Length;
  584. }
  585. else
  586. {
  587. for (int j = 0; j < Byte_Area[n].Length; j++)
  588. {
  589. tmp[j] = Byte_Area[n][j];
  590. }
  591. g += Byte_Area[n].Length;
  592. }
  593. }
  594. int len = tmp.Length + hsz + 4;
  595. header.DataLen = tmp.Length;
  596. //先copy len
  597. byte[] bt = new byte[len];
  598. //byte[] lenToByte = System.BitConverter.GetBytes(len);
  599. byte[] lenToByte = System.BitConverter.GetBytes(len);
  600. lenToByte.CopyTo(bt, 0);
  601. int index = lenToByte.Length;
  602. //再copy header
  603. //分配结构体大小的内存空间
  604. IntPtr structPtr = Marshal.AllocHGlobal(hsz);
  605. //将结构体拷到分配好的内存空间
  606. Marshal.StructureToPtr(header, structPtr, false);
  607. //从内存空间拷到AreaDataList数组
  608. Marshal.Copy(structPtr, bt, index, hsz);
  609. //释放内存空间
  610. Marshal.FreeHGlobal(structPtr);
  611. //copy text
  612. tmp.CopyTo(bt, index + hsz);
  613. return bt;
  614. }
  615. public int getAreaLen()
  616. {
  617. Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
  618. int hsz = Marshal.SizeOf(tu);
  619. //再考header
  620. text = text.Replace("₩₩F", "\\F");
  621. List<byte[]> Byte_Area = new List<byte[]>();
  622. int Byte_t = 0;
  623. string[] str_Area = text.Trim().Split('\\');
  624. int font = 0;
  625. for (int n = 0; n < str_Area.Length; n++)
  626. {
  627. if (n > 0 && str_Area[n].Length > 1)
  628. {
  629. if (str_Area[n].Substring(0, 2).Equals("FK"))
  630. {
  631. font = 1;
  632. if (str_Area[n].Length > 5)
  633. {
  634. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 5));
  635. byte[] special = new byte[special_1.Length + 1];
  636. special[0] = 0x5c;
  637. for (int c = 0; c < special_1.Length; c++)
  638. {
  639. special[c + 1] = special_1[c];
  640. }
  641. Byte_Area.Add(special);
  642. Byte_t += special.Length;
  643. string Area_str = str_Area[n].Remove(0, 5);
  644. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  645. for (int k = 0; k < Korean.Length / 2; k++)
  646. {
  647. byte a = Korean[k * 2];
  648. Korean[k * 2] = Korean[k * 2 + 1];
  649. Korean[k * 2 + 1] = a;
  650. }
  651. Byte_Area.Add(Korean);
  652. Byte_t += Korean.Length;
  653. }
  654. else
  655. {
  656. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  657. byte[] special = new byte[special_1.Length + 1];
  658. special[0] = 0x5c;
  659. for (int c = 0; c < special_1.Length; c++)
  660. {
  661. special[c + 1] = special_1[c];
  662. }
  663. Byte_Area.Add(special);
  664. Byte_t += special.Length;
  665. }
  666. }
  667. else if (str_Area[n].Substring(0, 2).Equals("FE") || str_Area[n].Substring(0, 2).Equals("FO") || str_Area[n].Substring(0, 2).Equals("WF") || str_Area[n].Substring(0, 2).Equals("WC"))
  668. {
  669. font = 0;
  670. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  671. byte[] special = new byte[special_1.Length + 1];
  672. special[0] = 0x5c;
  673. for (int c = 0; c < special_1.Length; c++)
  674. {
  675. special[c + 1] = special_1[c];
  676. }
  677. Byte_Area.Add(special);
  678. Byte_t += special.Length;
  679. }
  680. else if (str_Area[n].Substring(0, 1).Equals("C") || str_Area[n].Substring(0, 1).Equals("D") || str_Area[n].Substring(0, 1).Equals("B") || str_Area[n].Substring(0, 1).Equals("T"))
  681. {
  682. if (font == 1)
  683. {
  684. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 2));
  685. byte[] special = new byte[special_1.Length + 1];
  686. special[0] = 0x5c;
  687. for (int c = 0; c < special_1.Length; c++)
  688. {
  689. special[c + 1] = special_1[c];
  690. }
  691. Byte_Area.Add(special);
  692. Byte_t += special.Length;
  693. string Area_str = str_Area[n].Remove(0, 2);
  694. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  695. for (int k = 0; k < Korean.Length / 2; k++)
  696. {
  697. byte a = Korean[k * 2];
  698. Korean[k * 2] = Korean[k * 2 + 1];
  699. Korean[k * 2 + 1] = a;
  700. }
  701. Byte_Area.Add(Korean);
  702. Byte_t += Korean.Length;
  703. }
  704. else
  705. {
  706. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  707. byte[] special = new byte[special_1.Length + 1];
  708. special[0] = 0x5c;
  709. for (int c = 0; c < special_1.Length; c++)
  710. {
  711. special[c + 1] = special_1[c];
  712. }
  713. Byte_Area.Add(special);
  714. Byte_t += special.Length;
  715. }
  716. }
  717. else if (str_Area[n].Substring(0, 1).Equals("n"))
  718. {
  719. if (font == 1)
  720. {
  721. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n].Substring(0, 1));
  722. byte[] special = new byte[special_1.Length + 1];
  723. special[0] = 0x5c;
  724. for (int c = 0; c < special_1.Length; c++)
  725. {
  726. special[c + 1] = special_1[c];
  727. }
  728. Byte_Area.Add(special);
  729. Byte_t += special.Length;
  730. string Area_str = str_Area[n].Remove(0, 1);
  731. byte[] Korean = System.Text.Encoding.Unicode.GetBytes(Area_str);
  732. for (int k = 0; k < Korean.Length / 2; k++)
  733. {
  734. byte a = Korean[k * 2];
  735. Korean[k * 2] = Korean[k * 2 + 1];
  736. Korean[k * 2 + 1] = a;
  737. }
  738. Byte_Area.Add(Korean);
  739. Byte_t += Korean.Length;
  740. }
  741. else
  742. {
  743. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  744. byte[] special = new byte[special_1.Length + 1];
  745. special[0] = 0x5c;
  746. for (int c = 0; c < special_1.Length; c++)
  747. {
  748. special[c + 1] = special_1[c];
  749. }
  750. Byte_Area.Add(special);
  751. Byte_t += special.Length;
  752. }
  753. }
  754. }
  755. else
  756. {
  757. if (n > 0)
  758. {
  759. byte[] special_1 = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  760. byte[] special = new byte[special_1.Length + 1];
  761. special[0] = 0x5c;
  762. for (int c = 0; c < special_1.Length; c++)
  763. {
  764. special[c + 1] = special_1[c];
  765. }
  766. Byte_Area.Add(special);
  767. Byte_t += special.Length;
  768. }
  769. else
  770. {
  771. byte[] special = System.Text.Encoding.Default.GetBytes(str_Area[n]);
  772. Byte_Area.Add(special);
  773. Byte_t += special.Length;
  774. }
  775. }
  776. }
  777. byte[] tmp = new byte[Byte_t];
  778. int g = 0;
  779. for (int n = 0; n < Byte_Area.Count(); n++)
  780. {
  781. if (n > 0)
  782. {
  783. for (int j = 0; j < Byte_Area[n].Length; j++)
  784. {
  785. tmp[g + j] = Byte_Area[n][j];
  786. }
  787. g += Byte_Area[n].Length;
  788. }
  789. else
  790. {
  791. for (int j = 0; j < Byte_Area[n].Length; j++)
  792. {
  793. tmp[j] = Byte_Area[n][j];
  794. }
  795. g += Byte_Area[n].Length;
  796. }
  797. }
  798. int len = tmp.Length + hsz + 4;
  799. return len;
  800. }
  801. }
  802. public class Led5kProgram
  803. {
  804. public string name;
  805. public bool overwrite;
  806. public ushort DisplayType;
  807. public byte PlayTimes;
  808. public bool IsValidAlways;
  809. public ushort StartYear;
  810. public byte StartMonth;
  811. public byte StartDay;
  812. public ushort EndYear;
  813. public byte EndMonth;
  814. public byte EndDay;
  815. public byte ProgramWeek;
  816. public bool IsPlayOnTime;
  817. public byte StartHour;
  818. public byte StartMinute;
  819. public byte StartSecond;
  820. public byte EndHour;
  821. public byte EndMinute;
  822. public byte EndSecond;
  823. public byte AreaNum;
  824. public List<Led5kstaticArea> m_arealist = new List<Led5kstaticArea>();
  825. #region//转DCB码
  826. public static byte byte2bcd(byte num)
  827. {
  828. int i = num;
  829. return (byte)(i / 10 * 16 + i % 10);
  830. }
  831. public static byte bcd2byte(byte num)
  832. {
  833. int i = num;
  834. return (byte)(i / 16 * 10 + i % 16);
  835. }
  836. public static byte[] short2bcd(ushort num)
  837. {
  838. int i = num;
  839. byte high = (byte)(i / 100);
  840. byte low = (byte)(i % 100);
  841. byte[] tmp = new byte[2];
  842. tmp[0] = byte2bcd(low);
  843. tmp[1] = byte2bcd(high);
  844. return tmp;
  845. }
  846. #endregion
  847. public int SendProgram(uint hand)
  848. {
  849. byte[] ppFileName;
  850. byte[] ProgramLife;
  851. byte PlayPeriodGrpNum;
  852. byte[] Period;
  853. byte[] AreaDataList;
  854. int AreaDataListLen;
  855. int sum = 0;
  856. foreach (ONNONLed5KSDKD.Led5kstaticArea s in m_arealist)
  857. {
  858. sum += s.getAreaLen();
  859. }
  860. AreaDataList = new byte[sum];
  861. int index = 0;
  862. foreach (ONNONLed5KSDKD.Led5kstaticArea s in m_arealist)
  863. {
  864. byte[] bt = s.AreaToByteArray();
  865. bt.CopyTo(AreaDataList, index);
  866. index += bt.Length;
  867. }
  868. AreaDataListLen = sum;
  869. if (IsValidAlways == true)
  870. {
  871. ProgramLife = new byte[8];
  872. ProgramLife[0] = 0xff;
  873. ProgramLife[1] = 0xff;
  874. ProgramLife[2] = 0xff;
  875. ProgramLife[3] = 0xff;
  876. ProgramLife[4] = 0xff;
  877. ProgramLife[5] = 0xff;
  878. ProgramLife[6] = 0xff;
  879. ProgramLife[7] = 0xff;
  880. }
  881. else
  882. {
  883. ProgramLife = new byte[8];
  884. byte[] tmp = Led5kProgram.short2bcd(StartYear);
  885. ProgramLife[0] = tmp[0];
  886. ProgramLife[1] = tmp[1];
  887. ProgramLife[2] = byte2bcd(StartMonth);
  888. ProgramLife[3] = byte2bcd(StartDay);
  889. byte[] tmp1 = Led5kProgram.short2bcd(EndYear);
  890. ProgramLife[4] = tmp1[0];
  891. ProgramLife[5] = tmp1[1];
  892. ProgramLife[6] = byte2bcd(EndMonth);
  893. ProgramLife[7] = byte2bcd(EndDay);
  894. }
  895. ppFileName = System.Text.Encoding.Default.GetBytes(name);
  896. if (IsPlayOnTime == true)
  897. {
  898. Period = new byte[7];
  899. Period[0] = byte2bcd(StartHour);
  900. Period[1] = byte2bcd(StartMinute);
  901. Period[2] = byte2bcd(StartSecond);
  902. Period[3] = byte2bcd(EndHour);
  903. Period[4] = byte2bcd(EndMinute);
  904. Period[5] = byte2bcd(EndSecond);
  905. Period[6] = 0;
  906. }
  907. else
  908. {
  909. Period = null;
  910. }
  911. PlayPeriodGrpNum = Convert.ToByte(IsPlayOnTime ? 1 : 0);
  912. return ONNONLed5KSDKD.Led5kSDK.OFS_SendFileData(hand, 1, ppFileName, DisplayType, PlayTimes, ProgramLife,
  913. ProgramWeek, PlayPeriodGrpNum, Period, AreaNum, AreaDataList, AreaDataListLen);
  914. }
  915. }
  916. public class Led5kDynamics
  917. {
  918. public List<LedstaticArea> m_arealist = new List<LedstaticArea>();
  919. #region//转DCB码
  920. public static byte byte2bcd(byte num)
  921. {
  922. int i = num;
  923. return (byte)(i / 10 * 16 + i % 10);
  924. }
  925. public static byte bcd2byte(byte num)
  926. {
  927. int i = num;
  928. return (byte)(i / 16 * 10 + i % 16);
  929. }
  930. public static byte[] short2bcd(ushort num)
  931. {
  932. int i = num;
  933. byte high = (byte)(i / 100);
  934. byte low = (byte)(i % 100);
  935. byte[] tmp = new byte[2];
  936. tmp[0] = byte2bcd(low);
  937. tmp[1] = byte2bcd(high);
  938. return tmp;
  939. }
  940. #endregion
  941. public int SendAreas(uint hand)
  942. {
  943. byte[] AreaText;
  944. int TextLen;
  945. byte AreaNum=0;
  946. int sum = 0;
  947. foreach (ONNONLed5KSDKD.LedstaticArea s in m_arealist)
  948. {
  949. sum += s.getAreaLen();
  950. AreaNum++;
  951. }
  952. AreaText = new byte[sum];
  953. int index = 0;
  954. foreach (ONNONLed5KSDKD.LedstaticArea s in m_arealist)
  955. {
  956. byte[] bt = s.AreaToByteArray();
  957. bt.CopyTo(AreaText, index);
  958. index += bt.Length;
  959. }
  960. TextLen = sum;
  961. return ONNONLed5KSDKD.Led5kSDK.SCREEN_SendDynamicAreas(hand, AreaNum,(ushort)TextLen, AreaText);
  962. }
  963. }
  964. public class LedstaticArea
  965. {
  966. public Led5kSDK.bx_5k_area_header header;
  967. public string text;
  968. public byte[] AreaToByteArray()
  969. {
  970. //计算header的大小:结构体bx_5k_area_header的大小
  971. ONNONLed5KSDKD.Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
  972. int hsz = Marshal.SizeOf(tu);
  973. //计算len的大小
  974. byte[] tmp = System.Text.Encoding.Default.GetBytes(text);
  975. int len = tmp.Length + hsz + 2;
  976. header.DataLen = tmp.Length;
  977. //先copy len
  978. byte[] bt = new byte[len];
  979. //byte[] lenToByte = System.BitConverter.GetBytes(len);
  980. short Len = (short)(len-2);
  981. byte[] lenToByte = System.BitConverter.GetBytes(Len);
  982. lenToByte.CopyTo(bt, 0);
  983. int index = lenToByte.Length;
  984. //再copy header
  985. //分配结构体大小的内存空间
  986. IntPtr structPtr = Marshal.AllocHGlobal(hsz);
  987. //将结构体拷到分配好的内存空间
  988. Marshal.StructureToPtr(header, structPtr, false);
  989. //从内存空间拷到AreaDataList数组
  990. Marshal.Copy(structPtr, bt, index, hsz);
  991. //释放内存空间
  992. Marshal.FreeHGlobal(structPtr);
  993. //copy text
  994. tmp.CopyTo(bt, index + hsz);
  995. return bt;
  996. }
  997. public int getAreaLen()
  998. {
  999. Led5kSDK.bx_5k_area_header tu = new Led5kSDK.bx_5k_area_header();
  1000. int hsz = Marshal.SizeOf(tu);
  1001. //再考header
  1002. byte[] tmp = System.Text.Encoding.Default.GetBytes(text);
  1003. int len = tmp.Length + hsz+2;
  1004. return len;
  1005. }
  1006. }
  1007. }