천호석
2022-11-21 0f953099b1682402cf5e640db29d1c99936e28fd
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace SHARP_CLAS_UI
{
    public class Vision_Control
    {
        #region Property
 
        // =========================== 제어 -> Align ===============================
        readonly byte[] RecipeChangeReq = BitConverter.GetBytes((short)110);
 
        readonly byte[] GrabReadyReq = BitConverter.GetBytes((short)120);
 
        readonly byte[] GrabStartReq = BitConverter.GetBytes((short)130);
 
        readonly byte[] MotorPosMoveAck = BitConverter.GetBytes((short)181);
 
        readonly byte[] UserCommandReq = BitConverter.GetBytes((short)191);
 
        readonly byte[] SystemTimeSyncReq = BitConverter.GetBytes((short)192);
 
        // ============================ Align -> 제어 =================================
        readonly byte[] RecipeChangeAck = BitConverter.GetBytes((short)210);
 
        readonly byte[] GrabReadyAck = BitConverter.GetBytes((short)220);
 
        readonly byte[] GrabStartAck = BitConverter.GetBytes((short)230);
 
        readonly byte[] FilmJudgeResult1 = BitConverter.GetBytes((short)241);
 
        readonly byte[] FilmJudgeResult2 = BitConverter.GetBytes((short)242);
 
        readonly byte[] AlignResult1 = BitConverter.GetBytes((short)251);
 
        readonly byte[] AlignResult2 = BitConverter.GetBytes((short)252);
 
        readonly byte[] MeasurementResult1 = BitConverter.GetBytes((short)261);
 
        readonly byte[] MeasurementResult2 = BitConverter.GetBytes((short)262);
        
        readonly byte[] MotorPosMoveReq = BitConverter.GetBytes((short)281);
 
        readonly byte[] UserCommandCom = BitConverter.GetBytes((short)291);
 
        readonly byte[] SystemTimeSyncAck = BitConverter.GetBytes((short)292);
 
        readonly byte[] VisionAlive = BitConverter.GetBytes((short)100);
        #endregion
 
        #region Construct
        public Vision_Control()
        {
 
        }
        #endregion
 
        #region Function
        // =========================== 제어 -> Align ===============================
        /// <summary>
        /// Send Recipe Change Req
        /// </summary>
        /// <param name="RecipeMode">Recipe Move, 1 : 추가 , 2 : 변경(default), 3 : 삭제 => 현재 변경 고정 사용</param>
        /// <param name="RecipeName">제품 구분 정보(레시피 명)</param>
        public byte[] Send_Recipe_Change_Req(int RecipeMode, string RecipeName)
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
            byte[] send_recipe_name = new byte[20];
            byte[] recipe_name = Encoding.ASCII.GetBytes(RecipeName);
            Array.Copy(recipe_name, send_recipe_name, recipe_name.Length);
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(RecipeMode));
            body.InsertRange(body.Count, send_recipe_name);
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, RecipeChangeReq);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        /// <summary>
        ///  Send Grab Ready Req
        /// </summary>
        /// <param name="SeqType">물류 Sequence Type</param>
        /// <param name="ModuleIdx">카메라 Module Idx (0: Left, 1: Right)</param>
        /// <param name="GrabDir">단축 Grab(Default), 1: 단축 Grab</param>
        /// <param name="PnlDir">0: 단면 물류 흐름 방향, 1: 장면 물류 흐름 방향</param>
        /// <param name="StageNo">현재 검사를 위한 Panel이 로딩된 Stage 번호</param>
        /// <param name="SlotNo">Tray Slot 번호</param>
        /// <param name="PnlIdx">Tray 내 Panel이 위치한 Idx 번호</param>
        /// <param name="PanelID">Panel을 식별하기위한 ID (*없는 경우 NULL)</param>
        public byte[] Send_Grab_Ready_Req(int SeqType, int ModuleIdx, int GrabDir, int PnlDir, int StageNo, int SlotNo, int PnlIdx, string PanelID)
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
 
            byte[] send_panel_id = new byte[20];
            byte[] panel_id = Encoding.ASCII.GetBytes(PanelID);
            Array.Copy(panel_id, send_panel_id, panel_id.Length);
 
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(SeqType));
            body.InsertRange(body.Count, BitConverter.GetBytes(ModuleIdx));
            body.InsertRange(body.Count, BitConverter.GetBytes(GrabDir));
            body.InsertRange(body.Count, BitConverter.GetBytes(PnlDir));
            body.InsertRange(body.Count, BitConverter.GetBytes(StageNo));
            body.InsertRange(body.Count, BitConverter.GetBytes(SlotNo));
            body.InsertRange(body.Count, BitConverter.GetBytes(PnlIdx));
            body.InsertRange(body.Count, send_panel_id);
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, GrabReadyReq);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        /// <summary>
        /// Send Grab Start Req
        /// </summary>
        /// <param name="SeqType">물류 Sequence Type</param>
        /// <param name="ModelIndx">카메라 Module Idx (0: Left, 1: Right)</param>
        /// <param name="MotorOffsetX">현재 Motor Position X</param>
        /// <param name="MotorOffsetY">현재 Motor Position Y</param>
        public byte[] Send_Grab_Start_Req(int SeqType, int ModelIndx, int MarkIdx, double MotorOffsetX, double MotorOffsetY)
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
 
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(SeqType));
            body.InsertRange(body.Count, BitConverter.GetBytes(ModelIndx));
            body.InsertRange(body.Count, BitConverter.GetBytes(MarkIdx));
            body.InsertRange(body.Count, BitConverter.GetBytes(MotorOffsetX));
            body.InsertRange(body.Count, BitConverter.GetBytes(MotorOffsetY));
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, GrabStartReq);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        /// <summary>
        /// Send Motor Pos Move Ack
        /// </summary>
        /// <param name="Return"> 0 : 위치 이동 완료 (Success), n : 기타 에러(Fail) 제어 정의.</param>
        public byte[] Send_Motor_Pos_Move_Ack(int Return)
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
 
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(Return));
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, MotorPosMoveAck);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        /// <summary>
        /// Send Command Req
        /// </summary>
        /// <param name="CmdType">0: Scrap(제거, 1: Retry(재시도), 3: Skip(NG), 4: Pass(OK), 5: User(수동선택)</param>
        /// <param name="SeqType">물류 Sequence Type</param>
        /// <param name="ModuleIdx">카메라 Module Idx (0: Left, 1: Right)</param>
        /// <param name="PnlIdx">Tray 내 Panel이 위치한 Idx 번호</param>
        /// <param name="PanelID">Panel을 식별하기위한 ID (*없는 경우 NULL)</param>
        public byte[] Send_Command_Req(int CmdType, int SeqType, int ModuleIdx, int SlotNo, int PnlIdx, string PanelID)
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
 
            byte[] send_panel_id = new byte[20];
            byte[] panel_id = Encoding.ASCII.GetBytes(PanelID);
            Array.Copy(panel_id, send_panel_id, panel_id.Length);
 
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(CmdType));
            body.InsertRange(body.Count, BitConverter.GetBytes(SeqType));
            body.InsertRange(body.Count, BitConverter.GetBytes(ModuleIdx));
            body.InsertRange(body.Count, BitConverter.GetBytes(SlotNo));
            body.InsertRange(body.Count, BitConverter.GetBytes(PnlIdx));
            body.InsertRange(body.Count, send_panel_id);
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, UserCommandReq);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        /// <summary>
        /// Send System Time Sync Req
        /// </summary>
        public byte[] Send_System_Time_Sync_Req()
        {
            List<byte> senddata = new List<byte>();
            List<byte> body = new List<byte>();
 
            DateTime dt = DateTime.Now;
            int msgindex = int.Parse($"{dt.Hour:d2}{dt.Minute:d2}{dt.Second:d2}{dt.Millisecond:d3}");
            int year = dt.Year;
            int month = dt.Month;
            int day = dt.Day;
            int hour = dt.Hour;
            int minutes = dt.Minute;
            int second = dt.Second;
 
            body.InsertRange(body.Count, BitConverter.GetBytes(msgindex));
            body.InsertRange(body.Count, BitConverter.GetBytes(year));
            body.InsertRange(body.Count, BitConverter.GetBytes(month));
            body.InsertRange(body.Count, BitConverter.GetBytes(day));
            body.InsertRange(body.Count, BitConverter.GetBytes(hour));
            body.InsertRange(body.Count, BitConverter.GetBytes(minutes));
            body.InsertRange(body.Count, BitConverter.GetBytes(second));
 
            senddata.InsertRange(senddata.Count, BitConverter.GetBytes(body.Count));
            senddata.InsertRange(senddata.Count, SystemTimeSyncReq);
            senddata.InsertRange(senddata.Count, body);
 
            return senddata.ToArray();
        }
 
        // ============================ Align -> 제어 =================================
        /// <summary>
        /// Recv Recipe Change Ack
        /// </summary>
        /// <param name="Recvdata"></param>
        public void Recv_Recipe_Change_Ack(byte[] Recvdata, out RecipeChangeAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] Return = new byte[4]; //0 : Fail , 1: Success
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, Return, 0, Return.Length);
            copylength += Return.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_Return = BitConverter.ToInt32(Return, 0);
 
            Ack = new RecipeChangeAck(Result_MsgIndex, Result_Return);
        }
 
        public void Recv_Grab_Read_Ack(byte[] Recvdata, out GrabReadyAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] Return = new byte[4]; //0 : Fail, 1 : Success
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, Return, 0, Return.Length);
            copylength += Return.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_Return = BitConverter.ToInt32(Return, 0);
 
            Ack = new GrabReadyAck(Result_MsgIndex, Result_SeqType, Result_Return);
        }
 
        public void Recv_Grab_Start_Ack(byte[] Recvdata, out GrabStartAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] Return = new byte[4]; //0 : Fail, 1 : Success
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, Return, 0, Return.Length);
            copylength += Return.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_Return = BitConverter.ToInt32(Return, 0);
 
            Ack = new GrabStartAck(Result_MsgIndex, Result_SeqType, Result_ModuleIdx, Result_Return);
        }
 
        public void Recv_Film_Judge_Result(byte[] Recvdata, out FilmJudgeResultAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] FilmResult = new byte[4]; //0 : Film 無(Fail), 1 : Film 有(Success)
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, FilmResult, 0, FilmResult.Length);
            copylength += FilmResult.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Reuslt_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_FilmResult = BitConverter.ToInt32(FilmResult, 0);
 
            Ack = new FilmJudgeResultAck(Result_MsgIndex, Reuslt_SeqType, Result_ModuleIdx, Result_FilmResult);
        }
 
        public void Recv_Align_Result(byte[] Recvdata, out AlignResultAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] AlignResult = new byte[4]; //0 : Align Fail, 1 : Align Success
            byte[] AlignX = new byte[8]; //Align Offset X
            byte[] AlignY = new byte[8]; //Align Offset Y
            byte[] AlignAngle = new byte[8]; //Align Angle
            byte[] CenterAxis = new byte[4]; //제품 중심 좌표 (예비)
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, AlignResult, 0, AlignResult.Length);
            copylength += AlignResult.Length;
            Array.Copy(Recvdata, copylength, AlignX, 0, AlignX.Length);
            copylength += AlignX.Length;
            Array.Copy(Recvdata, copylength, AlignY, 0, AlignY.Length);
            copylength += AlignY.Length;
            Array.Copy(Recvdata, copylength, AlignAngle, 0, AlignAngle.Length);
            copylength += AlignAngle.Length;
            Array.Copy(Recvdata, copylength, CenterAxis, 0, CenterAxis.Length);
            copylength += CenterAxis.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_AlignResult = BitConverter.ToInt32(AlignResult, 0);
            double Result_AlignX = BitConverter.ToDouble(AlignX, 0);
            double Result_AlignY = BitConverter.ToDouble(AlignY, 0);
            double Result_AlignAngle = BitConverter.ToDouble(AlignAngle, 0);
            int Result_CenterAxis = BitConverter.ToInt32(CenterAxis, 0);
 
            Ack = new AlignResultAck(Result_MsgIndex, Result_SeqType, Result_ModuleIdx, Result_AlignResult, Result_AlignX, Result_AlignY, Result_AlignAngle, Result_CenterAxis);
        }
 
        public void Recv_Measurement_Result(byte[] Recvdata, out MeasurementResultAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] MeasureResult = new byte[4]; //0 : Fail, 1 : Success
            byte[] Mark1Point1 = new byte[8]; //Mark1의 #1(1/4 Point) to 레이저 가공부 상부 Edge 거리
            byte[] Mark1Point2 = new byte[8]; //Mark1의 #2(2/4 Point) to 레이저 가공부 하부 Edge 거리
            byte[] Mark2Point1 = new byte[8]; //Mark2의 #1(3/4 Point) to 레이저 가공부 상부 Edge 거리
            byte[] Mark2Point2 = new byte[8]; //Mark2의 #2(4/4 Point) to 레이저 가공부 하부 Edge 거리
            byte[] Mark3Point1 = new byte[8]; //Mark3의 #1(3/4 Point) to 레이저 가공부 상부 Edge 거리
            byte[] Mark3Point2 = new byte[8]; //Mark3의 #2(4/4 Point) to 레이저 가공부 하부 Edge 거리
            byte[] Mark4Point1 = new byte[8]; //Mark4의 #1(3/4 Point) to 레이저 가공부 상부 Edge 거리
            byte[] Mark4Point2 = new byte[8]; //Mark4의 #2(4/4 Point) to 레이저 가공부 하부 Edge 거리
            byte[] MarkDistance = new byte[8]; //Mark1과 Mark2의 거리
            byte[] AlignResult = new byte[4]; //0 : Align Fail, 1 : Align Success
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, MeasureResult, 0, MeasureResult.Length);
            copylength += MeasureResult.Length;
            Array.Copy(Recvdata, copylength, Mark1Point1, 0, Mark1Point1.Length);
            copylength += Mark1Point1.Length;
            Array.Copy(Recvdata, copylength, Mark1Point2, 0, Mark1Point2.Length);
            copylength += Mark1Point2.Length;
            Array.Copy(Recvdata, copylength, Mark2Point1, 0, Mark2Point1.Length);
            copylength += Mark2Point1.Length;
            Array.Copy(Recvdata, copylength, Mark2Point2, 0, Mark2Point2.Length);
            copylength += Mark2Point2.Length;
            Array.Copy(Recvdata, copylength, Mark3Point1, 0, Mark3Point1.Length);
            copylength += Mark3Point1.Length;
            Array.Copy(Recvdata, copylength, Mark3Point2, 0, Mark3Point2.Length);
            copylength += Mark3Point2.Length;
            Array.Copy(Recvdata, copylength, Mark4Point1, 0, Mark4Point1.Length);
            copylength += Mark4Point1.Length;
            Array.Copy(Recvdata, copylength, Mark4Point2, 0, Mark4Point2.Length);
            copylength += Mark4Point2.Length;
            Array.Copy(Recvdata, copylength, MarkDistance, 0, MarkDistance.Length);
            copylength += MarkDistance.Length;
            Array.Copy(Recvdata, copylength, AlignResult, 0, AlignResult.Length);
            copylength += AlignResult.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_MeasureResult = BitConverter.ToInt32(MeasureResult, 0);
            double Result_Mark1Point1 = BitConverter.ToDouble(Mark1Point1, 0);
            double Result_Mark1Point2 = BitConverter.ToDouble(Mark1Point2, 0);
            double Result_Mark2Point1 = BitConverter.ToDouble(Mark2Point1, 0);
            double Result_Mark2Point2 = BitConverter.ToDouble(Mark2Point2, 0);
            double Result_Mark3Point1 = BitConverter.ToDouble(Mark3Point1, 0);
            double Result_Mark3Point2 = BitConverter.ToDouble(Mark3Point2, 0);
            double Result_Mark4Point1 = BitConverter.ToDouble(Mark4Point1, 0);
            double Result_Mark4Point2 = BitConverter.ToDouble(Mark4Point2, 0);
            double Result_MarkDistance = BitConverter.ToDouble(MarkDistance, 0);
            int Result_AlignResult = BitConverter.ToInt32(AlignResult, 0);
 
            Ack = new MeasurementResultAck(Result_MsgIndex, Result_ModuleIdx, Result_MeasureResult, Result_Mark1Point1, Result_Mark1Point2, Result_Mark2Point1, Result_Mark2Point2, Result_Mark3Point1, Result_Mark3Point2, Result_Mark4Point1, Result_Mark4Point2, Result_MarkDistance, Result_AlignResult);
        }
 
        public void Recv_WidthMeasurement_Result(byte[] Recvdata, out WidthMeasurementResultAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] MeasureResult = new byte[4]; //0 : Fail, 1 : Success
            byte[] Mark1Width = new byte[8]; //Mark1의 넓이
            byte[] Mark2Width = new byte[8]; //Mark2의 넓이
            byte[] Mark3Width = new byte[8]; //Mark1의 넓이
            byte[] Mark4Width = new byte[8]; //Mark2의 넓이
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, MeasureResult, 0, MeasureResult.Length);
            copylength += MeasureResult.Length;
            Array.Copy(Recvdata, copylength, Mark1Width, 0, Mark1Width.Length);
            copylength += Mark1Width.Length;
            Array.Copy(Recvdata, copylength, Mark2Width, 0, Mark2Width.Length);
            copylength += Mark2Width.Length;
            Array.Copy(Recvdata, copylength, Mark3Width, 0, Mark3Width.Length);
            copylength += Mark3Width.Length;
            Array.Copy(Recvdata, copylength, Mark4Width, 0, Mark4Width.Length);
            copylength += Mark4Width.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_MeasureResult = BitConverter.ToInt32(MeasureResult, 0);
            double Result_Mark1Width = BitConverter.ToDouble(Mark1Width, 0);
            double Result_Mark2Width = BitConverter.ToDouble(Mark2Width, 0);
            double Result_Mark3Width = BitConverter.ToDouble(Mark3Width, 0);
            double Result_Mark4Width = BitConverter.ToDouble(Mark4Width, 0);
 
            Ack = new WidthMeasurementResultAck(Result_MsgIndex, Result_ModuleIdx, Result_MeasureResult, Result_Mark1Width, Result_Mark2Width, Result_Mark3Width, Result_Mark4Width);
        }
 
        public void Recv_Fine_Align_Result(byte[] Recvdata, out FineAlignResultAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] AlignResult = new byte[4]; //0 : Align Fail, 1 : Align Success
            byte[] AlignX = new byte[8]; //Align Offset X
            byte[] AlignY = new byte[8]; //Align Offset Y
            byte[] AlignAngle = new byte[8]; //Align Angle
            byte[] CenterAxis = new byte[4]; //제품 중심 좌표 (예비)
            byte[] Mark_Distance = new byte[8]; //Mark간 거리
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, AlignResult, 0, AlignResult.Length);
            copylength += AlignResult.Length;
            Array.Copy(Recvdata, copylength, AlignX, 0, AlignX.Length);
            copylength += AlignX.Length;
            Array.Copy(Recvdata, copylength, AlignY, 0, AlignY.Length);
            copylength += AlignY.Length;
            Array.Copy(Recvdata, copylength, AlignAngle, 0, AlignAngle.Length);
            copylength += AlignAngle.Length;
            Array.Copy(Recvdata, copylength, CenterAxis, 0, CenterAxis.Length);
            copylength += CenterAxis.Length;
            Array.Copy(Recvdata, copylength, Mark_Distance, 0, Mark_Distance.Length);
            copylength += Mark_Distance.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_AlignResult = BitConverter.ToInt32(AlignResult, 0);
            double Result_AlignX = BitConverter.ToDouble(AlignX, 0);
            double Result_AlignY = BitConverter.ToDouble(AlignY, 0);
            double Result_AlignAngle = BitConverter.ToDouble(AlignAngle, 0);
            int Result_CenterAxis = BitConverter.ToInt32(CenterAxis, 0);
            double Result_Mark_Distance = BitConverter.ToDouble(Mark_Distance, 0);
 
            Ack = new FineAlignResultAck(Result_MsgIndex, Result_SeqType, Result_ModuleIdx, Result_AlignResult, Result_AlignX, Result_AlignY, Result_AlignAngle, Result_CenterAxis, Result_Mark_Distance);
        }
        public void Recv_Motor_Pos_Move_Req(byte[] Recvdata, out MotorPosMoveReq Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] SeqType = new byte[4]; //물류 Sequence Type
            byte[] ModuleIdx = new byte[4]; //카메라 Module Idx (0: Left, 1: Right)
            byte[] GrabIdx = new byte[4]; //영상 취득 Idx (0: Mark1, 1: Mark2)
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, SeqType, 0, SeqType.Length);
            copylength += SeqType.Length;
            Array.Copy(Recvdata, copylength, ModuleIdx, 0, ModuleIdx.Length);
            copylength += ModuleIdx.Length;
            Array.Copy(Recvdata, copylength, GrabIdx, 0, GrabIdx.Length);
            copylength += GrabIdx.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Reuslt_SeqType = BitConverter.ToInt32(SeqType, 0);
            int Result_ModuleIdx = BitConverter.ToInt32(ModuleIdx, 0);
            int Result_GrabIdx = BitConverter.ToInt32(GrabIdx, 0);
 
            Ack = new MotorPosMoveReq(Result_MsgIndex, Reuslt_SeqType, Result_ModuleIdx, Result_GrabIdx);
        }
        
        public void Recv_User_Command_Ack(byte[] Recvdata, out UserCommandAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] Return = new byte[4]; //0: 실패, 1: 성공
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, Return, 0, Return.Length);
            copylength += Return.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_Return = BitConverter.ToInt32(Return, 0);
 
            Ack = new UserCommandAck(Result_MsgIndex, Result_Return);
        }
 
        public void Recv_System_Time_Sync_Ack(byte[] Recvdata, out SystemTimeSyncAck Ack)
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] Return = new byte[4]; //0: 실패, 1: 성공
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, Return, 0, Return.Length);
            copylength += Return.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_Return = BitConverter.ToInt32(Return, 0);
 
            Ack = new SystemTimeSyncAck(Result_MsgIndex, Result_Return);
        }
 
        public void Recv_Vision_Alive(byte[] Recvdata, out VisionAliveAck Ack )
        {
            byte[] size = new byte[4];
            byte[] command = new byte[2];
            byte[] MsgIndex = new byte[4]; //TimeStamp (HHMMSSmsmsms)
            byte[] Controller = new byte[4]; //PC구분 ( 1: Align, 2: AOI )
            byte[] HeartBeat = new byte[4]; //Toggle ( 0 -> 1 -> 0 …)
 
            int copylength = 0;
            Array.Copy(Recvdata, size, size.Length);
            copylength += size.Length;
            Array.Copy(Recvdata, copylength, command, 0, command.Length);
            copylength += command.Length;
            Array.Copy(Recvdata, copylength, MsgIndex, 0, MsgIndex.Length);
            copylength += MsgIndex.Length;
            Array.Copy(Recvdata, copylength, Controller, 0, Controller.Length);
            copylength += Controller.Length;
            Array.Copy(Recvdata, copylength, HeartBeat, 0, HeartBeat.Length);
            copylength += HeartBeat.Length;
 
            int Result_MsgIndex = BitConverter.ToInt32(MsgIndex, 0);
            int Result_Controller = BitConverter.ToInt32(Controller, 0);
            int Result_HeartBeat = BitConverter.ToInt32(HeartBeat, 0);
 
            Ack = new VisionAliveAck(Result_MsgIndex, Result_Controller, Result_HeartBeat);
        }
        #endregion
    }
}