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