Flyelectronic_485_RGB_Controller.cs
27.3 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
using log4net;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using TSA_V.Common;
namespace TSA_V.DeviceLibrary
{
public class Flyelectronic_485_RGB_Controller : IDisposable
{
ILog loge;
int baudRate = 115200;//波特率
Parity parity = Parity.None;//校验位
int dataBits = 8;//数据位
StopBits stopBits = StopBits.One; //停止位
SerialPort _serialPort = null;
string comPortName;
string Name;
private Dictionary<string, byte[][]> effactValue = new Dictionary<string, byte[][]>();
public Flyelectronic_485_RGB_Controller(string name, string logname = "defaultAppender")
{
Name = name;
loge = LogManager.GetLogger(logname);
}
bool ok = false;
/// <summary>
/// 打开串口资源
/// <returns>返回bool类型</returns>
/// </summary>
public bool OpenPort(string _comport, out string errmsg)
{
comPortName = _comport;
//如果串口是打开的,先关闭
errmsg = "";
if (_serialPort == null)
{
_serialPort = new SerialPort(comPortName, baudRate, parity, dataBits, stopBits);
//_serialPort.RtsEnable = true; //自动请求
_serialPort.ReadTimeout = 100;//超时
}
errmsg += ResourceControl.GetString("comInitError", "{0}初始化失败", _comport) ;
if (_serialPort.IsOpen)
{
_serialPort.Close();
_serialPort = null;
OpenPort(comPortName, out errmsg);
}
ok = false;
try
{
//打开串口
errmsg += ResourceControl.GetString("comOpenFail", "串口{0}打开失败", _comport);
_serialPort.Open();
LogUtil.info("氛围灯" + comPortName + "打开成功");
errmsg = "";
for (int i = 1; i < 10; i++)
{
Thread.Sleep(100);
//errmsg += "检测数据.";
var rev = SendAndReceive(CommandByte.GetDeviceID);
errmsg += Encoding.ASCII.GetString(rev);
if (rev.Count() > 0)
{
LogUtil.info("氛围灯" + comPortName + "查询到设备信息");
ok = true;
Run();
break;
}
}
}
catch (Exception Ex)
{
errmsg += Ex.ToString();
//throw Ex;
}
return ok;
}
private void Run()
{
return;
//Task.Run(() => {
// try
// {
// while (ok)
// {
// Task.Delay(200).Wait();
// if (RobotManage.mainMachine.lastColor.Equals("yellowL")) {
// ShowYellowLight();
// } else if (RobotManage.mainMachine.lastColor.Equals("greenL"))
// {
// ShowGreenLight();
// } else if (RobotManage.mainMachine.lastColor.Equals(Color.Black.Name.ToString())){
// }
// //else if (RobotManage.mainMachine.lastColor != "")
// //{
// // Color color = Color.FromName(RobotManage.mainMachine.lastColor);
// // if (color != null)
// // {
// // ShowColor(color);
// // }
// //}
// }
// }
// catch (Exception Ex)
// {
// LogUtil.error("出错:" + Ex.ToString());
// }
//});
}
public bool ShowColor(Color color, ColorFormat colorFormat = ColorFormat.GBR)
{
log("ShowColor,color=" + color );
var newbyte = CommandByte.SetOneColor;
var colorbyte = ConvertColorToByteArray(color, colorFormat);
newbyte[16] = colorbyte[0];
newbyte[17] = colorbyte[1];
newbyte[18] = colorbyte[2];
var rev = SendAndReceive(newbyte);
if (rev.Length > 0)
{
var txt = Encoding.ASCII.GetString(rev);
if (txt.IndexOf("RecvEnd") >= 0)
{
return true;
}
}
return false;
}
//public bool ShowLedColor(Color color, int startIndex, int endIndex)
//{
// List<int> ledIndex = new List<int>();
// for (int i = startIndex; i < endIndex; i++)
// {
// ledIndex.Add(i);
// }
// return ShowLedColor(color, ledIndex);
//}
/// <summary>
/// 指定索引的灯显示指定颜色,其他的灯灭
/// </summary>
/// <param name="color"></param>
/// <param name="colorFormat"></param>
/// <param name="ledIndex"></param>
/// <returns></returns>
public bool ShowLedColor(Color color, List<int> ledIndex, int maxledIndex = 0, ColorFormat colorFormat = ColorFormat.GBR)
{
log("开灯,color="+ color + ":" + string.Join("#", ledIndex));
ShowColor(Color.Black);
List<byte> allData = new List<byte>();
byte[] startByte = CommandByte.ledColorStart;
byte[] endByte = CommandByte.ledColorEnd;
allData.AddRange(startByte.ToList());
foreach (int index in ledIndex)
{
if (maxledIndex < index)
{
maxledIndex = index;
}
}
int length =( maxledIndex+1) * 3;
byte[] lengthByte = IntToByteArr(length);
allData[12] = lengthByte[0];
allData[13] = lengthByte[1];
byte[] colorbyte = ConvertColorToByteArray(color, colorFormat);
byte[] blackbyte = ConvertColorToByteArray(Color.Black, colorFormat);
for (int i = 0; i <= maxledIndex; i++)
{
if (ledIndex.Contains(i))
{
allData.Add(colorbyte[0]);
allData.Add(colorbyte[1]);
allData.Add(colorbyte[2]);
}
else
{
allData.Add(blackbyte[0]);
allData.Add(blackbyte[1]);
allData.Add(blackbyte[2]);
}
}
allData.AddRange(endByte.ToList());
var rev = SendAndReceive(allData.ToArray());
if (rev.Length > 0)
{
var txt = Encoding.ASCII.GetString(rev);
if (txt.IndexOf("RecvEnd") >= 0)
{
return true;
}
}
return false;
}
private static string IntToStr(int temp)
{
int value = (int)temp;
string tempStr = String.Format("{0:X}", (int)temp);
if (temp < 0)
{
uint v = (uint)(value & 0xFFFF);
tempStr = String.Format("{0:X}", v);
}
return tempStr;
}
/// <summary>
/// 打包方法,可以将十六制字符串转成byte[] ,字符串没有空格
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static byte[] StringToByte(string s)
{
string temps = s;
if (temps.Length % 2 != 0)
{
temps = "0" + temps;
}
byte[] tempb = new byte[50];
int j = 0;
for (int i = 0; i < temps.Length; i = i + 2, j++)
{
tempb[j] = Convert.ToByte(temps.Substring(i, 2), 16);
}
byte[] send = new byte[j];
Array.Copy(tempb, send, j);
return send;
}
private byte[] IntToByteArr(int value)
{
//int number = 42; // 要转换的数字
byte b1 = (byte)(value >> 8); // 取高8位
byte b2 = (byte)(value & 0xFF); // 取低8位
byte[] bytes = new byte[] { b1, b2 }; // 存储转换后的byte数组
return bytes;
}
private byte[][] getEffactValue(string fileName)
{
if (effactValue == null)
{
effactValue = new Dictionary<string, byte[][]>();
}
if (effactValue.ContainsKey(fileName))
{
return effactValue[fileName];
}return null;
}
public bool ShowEffact(string fileName,Color defColor)
{
var newbyte = getEffactValue(fileName);
if (newbyte != null)
{
foreach (var b in newbyte)
{
var rev = SendAndReceive(b);
}
}
else if (fileName != "" && File.Exists(fileName))
{
string Text = File.ReadAllText(fileName);
newbyte = CommandByte.GetEffBytes(Text);
foreach (var b in newbyte)
{
var rev = SendAndReceive(b);
}
}
else
{
//newbyte = CommandByte.GetEffBytes(CommandByte.eff1);
ShowColor(defColor);
}
return true;
}
public bool ShowYellowLight()
{
string fileName = Application.StartupPath + "/ledColor/yellow.txt";
return ShowEffact(fileName, Color.Yellow);
}
public bool ShowGreenLight()
{
string fileName = Application.StartupPath + "/ledColor/green.txt";
return ShowEffact(fileName, Color.Green);
}
public bool CloseLed()
{
return ShowColor(Color.Black);
}
byte[] SendAndReceive(byte[] buff)
{
byte[] restr = new byte[0];
if (_serialPort == null || !_serialPort.IsOpen)
{
if (!OpenPort(comPortName, out string errmsg))
{
log("未初始化,或已断开连接:" + errmsg);
return restr;
}
}
var t = Task.Run(delegate
{
byte[] recv = new byte[512];
try
{
debuglog("sendData:" + byteToHexStr(buff, " "));
_serialPort.Write(buff, 0, buff.Length);
Thread.Sleep(30);
int r = _serialPort.Read(recv, 0, recv.Length);
if (r > 0)
{
var recvdata = byteToHexStr(recv, " ");
debuglog("recvdata: " + recvdata);
return recv.Take(r).ToArray();//.Split(',');
}
}
catch (Exception e)
{
log(string.Format("{0}", e));
}
return restr;
});
try
{
t.Wait(500);
if (t.IsCompleted)
return t.Result;
else
return new byte[0];
}
catch
{
return new byte[0];
}
}
public static string byteToHexStr(byte[] bytes, string spilChar)
{
string returnStr = "";
if (bytes != null)
{
for (int i = 0; i < bytes.Length; i++)
{
returnStr += bytes[i].ToString("X2") + spilChar;
}
}
return returnStr;
}
void log(string msg)
{
loge.Info(Name + $"[{comPortName}]" + ":" + msg);
Console.WriteLine(msg);
}
void debuglog(string msg)
{
loge.Debug(Name + $"[{comPortName}]" + ":" + msg);
Console.WriteLine(msg);
}
static class CommandByte
{
//GBR
//DD 55 EE 00 00 00 01 00 99 02 00 00 00 03 00 6F FF 00 00 AA BB
//DD 55 EE 00 00 00 00 00 99 01 00 00 00 03 00 08 50 00 00 AABB
public static byte[] GetDeviceID = ConvertStringToByteArray("DD 55 EE 00 00 00 00 00 8F 01 00 00 00 03 00 01 00 00 00 AA BB");
// DD55EE0000000000990100000003006F500000AABB
public static byte[] SetOneColor = ConvertStringToByteArray("DD 55 EE 00 00 00 01 00 99 01 00 00 00 03 00 6F FF 00 00 AA BB");
//12,13 为数据数量
public static byte[] ledColorStart = ConvertStringToByteArray("DD 55 EE 00 00 00 01 00 99 01 00 00 00 03 00 01 ");
public static byte[] ledColorEnd = ConvertStringToByteArray("AA BB");
// DD 55 EE 00 00 00 01 00 99 01 00 00 00 03 00 C9 F0 F0 F0 AA BB
//DD 55 EE 00 00 00 01 00 99 01 00 00 00 03 00 C9 F0 F0 F0 AA BB
public static string eff1 = @"
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 6D 67 44 4D 43 53 2C 1D 63 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 C4 CC 18 9A 9C 2D 5A 51 4D 2B 1C 64 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 E6 F4 07 D5 E0 10 A0 A2 2A 55 4D 4F 29 19 65 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 E7 F5 07 E7 F5 07 D5 E0 10 9B 9E 2C 52 49 51 29 19 65 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 D6 E1 0F E8 F6 06 E9 F7 06 D5 E0 10 9A 9C 2D 50 46 52 26 15 67 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 A3 A6 29 D8 E3 0F E8 F6 06 EA F8 06 D1 DC 12 90 90 32 48 3D 56 25 14 67 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 5D 55 4B A5 A9 27 D8 E4 0E EA F8 06 E6 F3 08 CA D4 15 8B 8B 35 49 3E 55 27 16 66 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 2F 20 62 61 5A 49 AA AF 25 DD EA 0C EB F9 05 E6 F3 08 CD D7 14 91 91 32 4E 44 53 28 18 65 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1D 0C 6B 32 24 61 68 63 46 B2 B7 21 DF EC 0B EB FA 05 E8 F6 06 D1 DC 12 99 9B 2E 54 4B 50 29 19 65 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1E 0D 6A 34 26 60 6A 64 45 B3 B9 21 DE EB 0B EA F8 06 E8 F6 06 D5 E0 10 9C 9F 2C 55 4C 4F 2A 1A 65 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1F 0E 6A 34 26 60 65 5F 47 A9 AD 26 D9 E5 0E E9 F7 06 E8 F6 06 D6 E1 0F 9D A0 2C 54 4B 50 28 18 65 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1D 0B 6B 30 21 62 5C 54 4C A4 A7 28 D8 E3 0F E7 F5 07 EA F8 06 D3 DE 11 9B 9E 2C 54 4B 50 29 19 65 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0B 6B 2D 1E 63 5B 53 4C A2 A5 29 D5 E0 10 E7 F5 07 E7 F5 07 D3 DE 11 9A 9C 2D 51 47 51 27 17 66 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0B 6B 2E 1F 63 5A 52 4D A2 A5 29 D8 E3 0F E9 F7 06 E8 F6 06 D3 DE 11 93 94 30 4A 3F 55 25 14 67 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0C 6B 2D 1E 63 5C 54 4C A5 A8 28 D8 E4 0E E9 F7 06 E7 F5 07 CC D6 14 88 87 36 42 36 59 22 11 69 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 2D 1E 63 5D 55 4B A8 AC 26 DD EA 0C EB FA 05 E5 F2 08 C4 CC 18 7E 7B 3B 41 35 59 22 11 69 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 2F 20 62 63 5C 49 B2 B7 21 E1 EE 0A EA F8 06 E3 F1 09 C0 C8 1A 7C 79 3C 3F 33 5A 22 12 68 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0C 6B 34 26 60 6E 69 43 BC C4 1C E1 EF 0A E9 F7 06 E1 EF 0A C1 C9 1A 7F 7C 3B 40 34 5A 22 12 68 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 20 0F 6A 3D 30 5B 7B 78 3D C0 C8 1A E2 F0 09 E8 F6 06 E2 F0 09 C3 CB 19 7D 7A 3B 3A 2D 5D 1E 0D 6A 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 22 11 69 3F 33 5A 7B 78 3D BD C5 1C E0 ED 0B EA F8 06 E5 F2 08 BD C5 1C 6B 65 44 31 23 61 1C 0A 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 22 12 68 3E 31 5B 78 75 3E BC C4 1C E2 F0 09 EB FA 05 E0 ED 0B AD B2 24 5E 56 4B 2C 1D 63 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 21 10 69 3D 30 5B 7C 79 3C C6 CF 17 E6 F4 07 EA F8 06 D9 E5 0E A4 A7 28 5A 52 4D 2D 1E 63 1D 0C 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 21 10 69 43 37 58 8D 8D 34 D0 DB 12 E8 F6 06 E9 F7 06 D8 E3 0F A1 A4 2A 5B 53 4C 2B 1B 64 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 27 17 66 50 46 52 98 9A 2E D6 E1 0F E9 F7 06 E8 F6 06 D6 E1 0F A1 A4 2A 5A 52 4D 2B 1C 64 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 29 19 65 55 4D 4F 9D A0 2C D6 E1 0F E9 F7 06 E8 F6 06 D7 E2 0F A1 A4 2A 5A 52 4D 2B 1C 64 1D 0B 6B 1B 09 6C 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 2A 1A 65 55 4C 4F 9D A0 2C D7 E2 0F E9 F7 06 E8 F6 06 D8 E4 0E A8 AC 26 61 5A 49 31 23 61 1E 0D 6A 1B 09 6C 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 2C 1D 63 56 4E 4F 9E A1 2B D5 E0 10 E7 F5 07 EA F8 06 DD E9 0C AD B2 24 66 60 47 34 26 60 20 0F 6A 1B 09 6C AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0B 6B 2B 1B 64 54 4B 50 9B 9D 2D D3 DE 11 E7 F5 07 EB FA 05 DE EB 0B B1 B6 22 6C 66 44 39 2B 5D 1F 0E 6A AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1D 0B 6B 2A 1A 65 53 4A 50 94 95 30 CF DA 13 E6 F4 07 E9 F7 06 DD EA 0C B4 BA 20 6F 6A 42 38 2A 5E AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 28 18 65 4D 43 53 8E 8E 33 CB D5 15 E5 F2 08 E7 F5 07 DE EB 0B B4 BA 20 71 6D 41 AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 27 17 66 49 3E 55 88 87 36 C9 D2 16 E4 F2 08 E7 F5 07 DD EA 0C B7 BD 1F AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 24 13 68 47 3C 56 88 87 36 C5 CE 18 E3 F1 09 E8 F6 06 E0 ED 0B AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 25 14 67 45 3A 57 87 86 37 C5 CD 18 E4 F2 08 EB F9 05 AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 25 14 67 43 38 58 82 80 39 C2 CA 19 E4 F2 08 AA BB
DD 55 EE 00 00 00 01 00 99 01 00 00 00 5A 00 01 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1B 09 6C 1C 0A 6C 23 13 68 41 35 59 77 74 3E BA C1 1D AA BB
";
public static byte[][] GetEffBytes(string eff)
{
List<byte[]> bytes = new List<byte[]>();
var effs = eff.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var ef in effs)
{
bytes.Add(ConvertStringToByteArray(ef));
}
return bytes.ToArray();
}
}
static byte[] ConvertStringToByteArray(string input)
{
// 去除字符串中的空格
string[] hexValues = input.Trim().Split(' ');
// 创建一个与字符串长度相等的byte[]数组
byte[] byteArray = new byte[hexValues.Length];
// 将每个字符串转换为对应的byte值
for (int i = 0; i < hexValues.Length; i++)
{
byteArray[i] = Convert.ToByte(hexValues[i], 16);
}
return byteArray;
}
public enum ColorFormat
{
RGB,
BGR,
BRG,
GRB,
GBR,
RBG
}
public static byte[] ConvertColorToByteArray(Color color, ColorFormat format)
{
byte[] result = new byte[3];
switch (format)
{
case ColorFormat.RGB:
result[0] = color.R;
result[1] = color.G;
result[2] = color.B;
break;
case ColorFormat.BGR:
result[0] = color.B;
result[1] = color.G;
result[2] = color.R;
break;
case ColorFormat.BRG:
result[0] = color.B;
result[1] = color.R;
result[2] = color.G;
break;
case ColorFormat.GRB:
result[0] = color.G;
result[1] = color.R;
result[2] = color.B;
break;
case ColorFormat.GBR:
result[0] = color.G;
result[1] = color.B;
result[2] = color.R;
break;
case ColorFormat.RBG:
result[0] = color.R;
result[1] = color.B;
result[2] = color.G;
break;
default:
throw new ArgumentException("Invalid format specified.");
}
return result;
}
public void Dispose()
{
ok = false;
_serialPort?.Close();
}
}
}