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
using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace SHARP_CLAS_UI
{
    public partial class Form_Scanner_View : Form
    {
        #region Field
        delegate void UI_Update_Delegate();
 
        Form_Frame _Parent;
 
        Thread UI_Update_Th;
 
        bool update_check;
 
        bool scanner_Init;
        #endregion
        public Form_Scanner_View(Form_Frame _Parent)
        {
            InitializeComponent();
 
            this._Parent = _Parent;
 
            UI_Update_Th = new Thread(UI_Update_Th_Set);
            UI_Update_Th.Start();
        }
 
        #region Form_Function
        private void Form_Scanner_View_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!_Parent.IsDisposed)
            {
                e.Cancel = true;
 
                this.Hide();
            }
        }
        #endregion
 
        #region Function
        private void UI_Update_Th_Set()
        {
            while (!_Parent.IsDisposed)
            {
                Thread.Sleep(100);
                if (!update_check)
                {
                    update_check = true;
                    UI_Update();
                }
            }
        }
 
        private void UI_Update()
        {
            if (InvokeRequired)
            {
                BeginInvoke(new UI_Update_Delegate(UI_Update));
                return;
            }
            else
            {
                try
                {
                    DateTime dt = DateTime.Now;
 
                    bool laser_on, busy;
 
                    if (_Parent._equip.Cur_Main_Recipe == null || _Parent._equip.Cur_Main_Recipe.process_info == null)
                    {
                        tb_Process_Info_Name.Text = "";
 
                        lb_Busy.BackColor = Color.Green;
                        btn_Scanner_Init.BackColor = Color.Green;
                        btn_Laser_On.BackColor = Color.Green;
                        btn_Laser_Off.BackColor = Color.Green;
 
                        tb_Set_Jump_Speed.Text = "";
                        tb_Set_Mark_Speed.Text = "";
                        tb_Set_Laser_On_Delay.Text = "";
                        tb_Set_Laser_Off_Delay.Text = "";
                        tb_Set_Jump_Delay.Text = "";
                        tb_Set_Mark_Delay.Text = "";
 
                        tb_Work_Area_X.Text = "";
                        tb_Work_Area_Y.Text = "";
 
                        tb_Process_Area_X.Text = "";
                        tb_Process_Area_Y.Text = "";
 
                        tb_Distance.Text = "";
                        tb_Jump_Repeat.Text = "";
                        tb_Jump_Range.Text = "";
 
                        tb_Waveform_Style.Text = "";
                    }
                    else
                    {
                        tb_Process_Info_Name.Text = _Parent._equip.Cur_Main_Recipe.process_info.Name;
 
                        _Parent._equip.scanner.Get_Busy(out busy);
                        _Parent._equip.scanner.Get_Laser_On(out laser_on);
 
                        lb_Busy.BackColor = busy ? Color.Lime : Color.Green;
                        btn_Scanner_Init.BackColor = scanner_Init ? Color.Lime : Color.Green;
                        btn_Laser_On.BackColor = laser_on ? Color.Lime : Color.Green;
                        btn_Laser_Off.BackColor = laser_on ? Color.Green : Color.Lime;
 
                        tb_Set_Jump_Speed.Text = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Speed.ToString();
                        tb_Set_Mark_Speed.Text = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Speed.ToString();
                        tb_Set_Laser_On_Delay.Text = _Parent._equip.Cur_Main_Recipe.process_info.Laser_On_Delay.ToString();
                        tb_Set_Laser_Off_Delay.Text = _Parent._equip.Cur_Main_Recipe.process_info.Laser_Off_Delay.ToString();
                        tb_Set_Jump_Delay.Text = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Delay.ToString();
                        tb_Set_Mark_Delay.Text = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Delay.ToString();
 
                        tb_Work_Area_X.Text = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_X.ToString();
                        tb_Work_Area_Y.Text = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_Y.ToString();
 
                        tb_Distance.Text = _Parent._equip.Cur_Main_Recipe.process_info.Hatch_Distance.ToString();
                        tb_Jump_Repeat.Text = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Repeat.ToString();
                        tb_Jump_Range.Text = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Range.ToString();
 
                        tb_Waveform_Style.Text = ((Scanner_Recipe.Ablation_Style)_Parent._equip.Cur_Main_Recipe.process_info.Waveform).ToString();
                    }
 
                    bool isInPosition = false;
                    if (_Parent._equip.Cur_Main_Recipe != null && _Parent._equip.Cur_Main_Recipe.process_info != null && _Parent._equip.Cur_Main_Recipe.panel_type_info != null)
                    {
                        double scannerA1Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_X_A1 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_X_A1;
                        double scannerA2Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_X_A2 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_X_A2;
                        double scannerB1Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_X_B1 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_X_B1;
                        double scannerB2Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_X_B2 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_X_B2;
 
                        double stageA1Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_Y_A1 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_Y_A1;
                        double stageA2Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_Y_A2 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_Y_A2;
                        double stageB1Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_Y_B1 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_Y_B1;
                        double stageB2Position = _Parent._equip.Cur_Main_Recipe.process_info.Scanner_Y_B2 + _Parent._equip.Cur_Main_Recipe.panel_type_info.Scanner_Offset_Y_B2;
 
                        object value;
                        _Parent._equip.sm.Get_Value(RS_Automation_Motor_Address.Ablation_X_Actual_Position, out value);
                        double scannerPosition = double.Parse($"{value}");
 
                        _Parent._equip.sm.Get_Value(RS_Automation_Motor_Address.Ablation_Y_1_Actual_Position, out value);
                        double stageAPosition = double.Parse($"{value}");
                        _Parent._equip.sm.Get_Value(RS_Automation_Motor_Address.Ablation_Y_2_Actual_Position, out value);
                        double stageBPosition = double.Parse($"{value}");
 
                        isInPosition |= (scannerA1Position - 10 <= scannerPosition && scannerPosition <= scannerA1Position + 10) && (stageA1Position - 10 <= stageAPosition && stageAPosition <= stageA1Position + 10);
                        isInPosition |= (scannerA2Position - 10 <= scannerPosition && scannerPosition <= scannerA2Position + 10) && (stageA2Position - 10 <= stageAPosition && stageAPosition <= stageA2Position + 10);
                        isInPosition |= (scannerB1Position - 10 <= scannerPosition && scannerPosition <= scannerB1Position + 10) && (stageB1Position - 10 <= stageBPosition && stageBPosition <= stageB1Position + 10);
                        isInPosition |= (scannerB2Position - 10 <= scannerPosition && scannerPosition <= scannerB2Position + 10) && (stageB2Position - 10 <= stageBPosition && stageBPosition <= stageB2Position + 10);
                        isInPosition |= _Parent._equip.process.ablation.Get_Is_Position_X_Power_Meter() && _Parent._equip.process.ablation.Get_Is_Position_Z_Power_Meter();
                    }
                    else
                    {
                        isInPosition |= _Parent._equip.process.ablation.Get_Is_Position_X_Power_Meter() && _Parent._equip.process.ablation.Get_Is_Position_Z_Power_Meter();
                    }
 
                    foreach (Control control in Controls)
                    {
                        control.Enabled = isInPosition;
                    }
 
                    TimeSpan ts = DateTime.Now - dt;
                }
                catch (Exception ex)
                {
 
                }
                finally
                {
                    update_check = false;
                }
            }
        }
        #endregion
 
        private void btn_Run_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                return;
            
            _Parent._equip.scanner.Initialize(_Parent._equip.Cur_Main_Recipe.process_info.CTB_File_Path);
 
            double jump_speed = 0, mark_speed = 0;
            short laseron_delay = 0, laseroff_delay = 0;
            ushort jump_delay = 0, mark_delay = 0, polygon_delay = 0;
 
            jump_speed = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Speed;
            mark_speed = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Speed;
            laseron_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_On_Delay;
            laseroff_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_Off_Delay;
            jump_delay = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Delay;
            mark_delay = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Delay;
            polygon_delay = 0;
 
            if (!_Parent._equip.scanner.Set_Process_Datas(jump_speed, mark_speed, laseron_delay, laseroff_delay, jump_delay, mark_delay, polygon_delay))
                return;
 
            int frequency = _Parent._equip.Cur_Main_Recipe.process_info.Frequency;
            double power = _Parent._equip.Cur_Main_Recipe.process_info.Power;
 
            if (!_Parent._equip.scanner.Set_Power(frequency, power))
                return;
 
            float process_area_x, process_area_y, work_area_x, work_area_y, distance;
            int repeat, range, waveform;
            process_area_x = 0;
            process_area_y = 0;
            work_area_x = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_X;
            work_area_y = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_Y;
            distance = _Parent._equip.Cur_Main_Recipe.process_info.Hatch_Distance;
            repeat = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Repeat;
            range = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Range;
            waveform = _Parent._equip.Cur_Main_Recipe.process_info.Waveform;
 
            bool moving;
 
            do
            {
                _Parent._equip.scanner.Get_Busy(out moving);
            } while (moving);
 
            Scanner_Recipe rec = new Scanner_Recipe(work_area_x, work_area_y, process_area_x, process_area_y, distance, repeat, range, (Scanner_Recipe.Ablation_Style)waveform);
            //Scanner_Recipe rec = new Scanner_Recipe(work_area_x, work_area_y, process_area_x, process_area_y, distance, repeat, range,0,0,0,0,0,0,0, (Scanner_Recipe.Ablation_Style)waveform);
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
        }
 
        private void btn_Rectangle_Run_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                return;
 
            _Parent._equip.scanner.Initialize(_Parent._equip.Cur_Main_Recipe.process_info.CTB_File_Path);
 
            double jump_speed = 0, mark_speed = 0;
            short laseron_delay = 0, laseroff_delay = 0;
            ushort jump_delay = 0, mark_delay = 0, polygon_delay = 0;
 
            jump_speed = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Speed;
            mark_speed = 300;
            laseron_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_On_Delay;
            laseroff_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_Off_Delay;
            jump_delay = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Delay;
            mark_delay = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Delay;
            polygon_delay = 0;
 
            if (!_Parent._equip.scanner.Set_Process_Datas(jump_speed, mark_speed, laseron_delay, laseroff_delay, jump_delay, mark_delay, polygon_delay))
                return;
 
            int frequency = _Parent._equip.Cur_Main_Recipe.process_info.Frequency;
            double power = _Parent._equip.Cur_Main_Recipe.process_info.Power;
 
            if (!_Parent._equip.scanner.Set_Power(frequency, power))
                return;
 
            _Parent._equip.scanner.Squire_Marking();
 
            bool moving;
            do
            {
                _Parent._equip.scanner.Get_Busy(out moving);
            } while (moving);
        }
 
        private void btn_Scanner_Init_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                return;
 
            if (_Parent._equip.scanner.Initialize(_Parent._equip.Cur_Main_Recipe.process_info.CTB_File_Path)) scanner_Init = true;
            else scanner_Init = false;
        }
 
        private void btn_Laser_On_Click(object sender, EventArgs e)
        {
            _Parent._equip.scanner.Set_Laser_On();
        }
 
        private void btn_Laser_Off_Click(object sender, EventArgs e)
        {
            _Parent._equip.scanner.Set_Laser_Off();
        }
 
        private void btn_Home_Click(object sender, EventArgs e)
        {
            _Parent._equip.scanner.Home();
        }
 
        private void btn_Stop_Click(object sender, EventArgs e)
        {
            _Parent._equip.scanner.Set_Stop();
        }
 
        #region Laser가공 Test
        private void btn_TestStart_Click(object sender, EventArgs e)
        {
            LaserRunwork();
        }
 
        //레이저 가공 쓰레드
        public async Task LaserRunwork()
        {
            await Task.Run(() => LaserStart());
        }
 
 
        int Count = 0;
        public void LaserStart()
        {
            try
            {
                DateTime Time;
                Time = DateTime.Now;
                if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                    return;
 
                _Parent._equip.scanner.Initialize(_Parent._equip.Cur_Main_Recipe.process_info.CTB_File_Path);
 
                double jump_speed = 0, mark_speed = 0;
                short laseron_delay = 0, laseroff_delay = 0;
                ushort jump_delay = 0, mark_delay = 0, polygon_delay = 0;
 
                jump_speed = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Speed;
                mark_speed = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Speed;
                laseron_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_On_Delay;
                laseroff_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_Off_Delay;
                jump_delay = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Delay;
                mark_delay = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Delay;
                polygon_delay = 0;
 
                if (!_Parent._equip.scanner.Set_Process_Datas(jump_speed, mark_speed, laseron_delay, laseroff_delay, jump_delay, mark_delay, polygon_delay))
                    return;
 
                int frequency = _Parent._equip.Cur_Main_Recipe.process_info.Frequency;
                double power = _Parent._equip.Cur_Main_Recipe.process_info.Power;
 
                if (!_Parent._equip.scanner.Set_Power(frequency, power))
                    return;
 
                int startcount = 0;
                Count = 0;
                float start1_x, start1_y, width_1, height_1, distance_1, dis_end;
                float start2_x, start2_y, width_2, height_2, distance_2;
                float start3_x, start3_y, width_3, height_3, distance_3;
                float start4_x, start4_y, width_4, height_4, dis_start;
                int repeat, range, rep_start, rep_end, repeat_2, repeat_3;
 
                start1_x = float.Parse(tb_Start1_X.Text);
                start2_x = float.Parse(tb_Start2_X.Text);
                start3_x = float.Parse(tb_Start3_X.Text);
                start4_x = float.Parse(tb_Start4_X.Text);
 
                start1_y = float.Parse(tb_Start1_Y.Text);
                start2_y = float.Parse(tb_Start2_Y.Text);
                start3_y = float.Parse(tb_Start3_Y.Text);
                start4_y = float.Parse(tb_Start4_Y.Text);
 
                width_1 = float.Parse(tb_Process1_Width.Text);
                width_2 = float.Parse(tb_Process2_Width.Text);
                width_3 = float.Parse(tb_Process3_Width.Text);
                width_4 = float.Parse(tb_Process4_Width.Text);
 
                height_1 = float.Parse(tb_Process1_Height.Text);
                height_2 = float.Parse(tb_Process2_Height.Text);
                height_3 = float.Parse(tb_Process3_Height.Text);
                height_4 = float.Parse(tb_Process4_Height.Text);
 
                distance_1 = float.Parse(tb_Distance.Text);
                dis_start = float.Parse(tb_Distance_run.Text);
                dis_end = float.Parse(tb_Distance_end.Text);
 
                distance_2= float.Parse(tb_Distance_2.Text);
                distance_3 = float.Parse(tb_Distance_3.Text);
 
                repeat = int.Parse(tb_Jump_Repeat.Text);
                rep_start = int.Parse(tb_Repeat_Start.Text);
                rep_end = int.Parse(tb_Repeat_End.Text);
                repeat_2 = int.Parse(tb_Repeat_2.Text);
                repeat_3 = int.Parse(tb_Repeat_3.Text);
 
                range = int.Parse(tb_Jump_Range.Text);
 
                if (cb_box1.Checked == true)
                {
                    Count += 1;
                }
                if (cb_box2.Checked == true)
                {
                    Count += 1;
                }
                if (cb_box3.Checked == true)
                {
                    Count += 1;
                }
                if (cb_box4.Checked == true)
                {
                    Count += 1;
                }
 
                bool moving;
                while (startcount < Count)
                {
                    do
                    {
                        _Parent._equip.scanner.Get_Busy(out moving);
                    } while (moving);
 
                    if (cb_box1.Checked == true)
                    {
                        Run_1(start1_x, start1_y, width_1, height_1, distance_1, repeat, range, dis_start, rep_start, 1);
                    }
                    else if (cb_box2.Checked == true)
                    {
                        Run3(start3_x, start3_y, width_3, height_3, distance_1, repeat, range, distance_2, repeat_2, 3);
                    }
                    else if (cb_box3.Checked == true)
                    {
                        Run2(start2_x, start2_y, width_2, height_2, distance_1, repeat, range, distance_3, repeat_3, 2);
                    }
                    else if (cb_box4.Checked == true)
                    {
                        Run4(start4_x, start4_y, width_4, height_4, distance_1, repeat, range, dis_end, rep_end, 4);
                    }
                    startcount++;
                }
                
                MessageBox.Show("가공 완료 {0}" + Convert.ToString(DateTime.Now - Time));
            }
            catch
            {
 
            }
        }
 
        public void Run2(float st_x, float st_y, float widt, float heig, float distan, int repea, int ran, float dis_2, int rep_2, int count)
        {
            float start_x, start_y, width, height, distance, distance_2;
            int repeat, range, waveform, repeat_2;
 
            start_x = st_x; start_y = st_y; width = widt; height = heig;
            distance = distan; repeat = repea; range = ran;
            distance_2 = dis_2; repeat_2 = rep_2;
            waveform = _Parent._equip.Cur_Main_Recipe.process_info.Waveform;
            Scanner_Recipe rec = new Scanner_Recipe((float)252.2, (float)252.2, start_x, start_y, width, height, distance, repeat, range, distance_2, 0, repeat_2, 0, (Scanner_Recipe.Ablation_Style)waveform);
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in /*Recipe_info*/rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
        }
        public void Run3(float st_x, float st_y, float widt, float heig, float distan, int repea, int ran, float dis_3, int rep_3, int count)
        {
            float start_x, start_y, width, height, distance, distance_3;
            int repeat, range, waveform, repeat_3;
 
            start_x = st_x; start_y = st_y; width = widt; height = heig;
            distance = distan; repeat = repea; range = ran;
            distance_3 = dis_3; repeat_3 = rep_3;
            waveform = _Parent._equip.Cur_Main_Recipe.process_info.Waveform;
            Scanner_Recipe rec = new Scanner_Recipe((float)252.2, (float)252.2, start_x, start_y, width, height, distance, repeat, range, distance_3, 0, repeat_3, 0, (Scanner_Recipe.Ablation_Style)waveform);
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in /*Recipe_info*/rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
        }
 
 
        public void Run_1(float st_x, float st_y, float widt, float heig, float distan, int repea, int ran, float dis_start, int rep_start, int count)
        {
            float start_x, start_y, width, height, distance, Dis_start;
            int repeat, range, Rep_start, waveform;
 
            start_x = st_x; start_y = st_y; width = widt; height = heig;
            distance = distan; repeat = repea; range = ran;
            Dis_start = dis_start;
            Rep_start = rep_start;
            waveform = _Parent._equip.Cur_Main_Recipe.process_info.Waveform;
            //Scanner_Recipe rec = new Scanner_Recipe(250, 250, start_x, start_y, width, height, distance, repeat, range);
            Scanner_Recipe rec = new Scanner_Recipe((float)252.2, (float)252.2, start_x, start_y, width, height, distance, repeat, range, Dis_start, 0, Rep_start, 0, (Scanner_Recipe.Ablation_Style)waveform);
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in /*Recipe_info*/rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
 
        }
 
        public void Run4(float st_x, float st_y, float widt, float heig, float distan, int repea, int ran, float dis_end, int rep_end, int count)
        {
            float start_x, start_y, width, height, distance, Dis_end;
            int repeat, range, Rep_end, waveform;
 
            start_x = st_x; start_y = st_y; width = widt; height = heig;
            distance = distan; repeat = repea; range = ran;
            Dis_end = dis_end;
            Rep_end = rep_end;
            waveform = _Parent._equip.Cur_Main_Recipe.process_info.Waveform;
            //Scanner_Recipe rec = new Scanner_Recipe(250, 250, start_x, start_y, width, height, distance, repeat, range);
            Scanner_Recipe rec = new Scanner_Recipe((float)252.2, (float)252.2, start_x, start_y, width, height, distance, repeat, range, 0, Dis_end, 0, Rep_end, (Scanner_Recipe.Ablation_Style)waveform);
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in /*Recipe_info*/rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
        }
        #endregion
 
        private void button1_Click(object sender, EventArgs e)
        {
            double dgree = 0;
 
            if(!double.TryParse(tb_Run_Degree.Text, out dgree))
            {
                Interlock_Manager.Add_Interlock_Msg("Scanner test faile.", "Please set degree right value");
                return;
            }
 
            Thread Ablation_Run_Th;
            if (_Parent._equip.scanner.Initialize(_Parent._equip.Cur_Main_Recipe.process_info.CTB_File_Path))
            {
                double jump_speed = 0, mark_speed = 0;
                short laseron_delay = 0, laseroff_delay = 0;
                ushort jump_delay = 0, mark_delay = 0, polygon_delay = 0;
 
                jump_speed = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Speed;
                mark_speed = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Speed;
                laseron_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_On_Delay;
                laseroff_delay = _Parent._equip.Cur_Main_Recipe.process_info.Laser_Off_Delay;
                jump_delay = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Delay;
                mark_delay = _Parent._equip.Cur_Main_Recipe.process_info.Mark_Delay;
                polygon_delay = 0;
 
                if (!_Parent._equip.scanner.Set_Process_Datas(jump_speed, mark_speed, laseron_delay, laseroff_delay, jump_delay, mark_delay, polygon_delay))
                    return;
 
                int frequency = _Parent._equip.Cur_Main_Recipe.process_info.Frequency;
                double power = _Parent._equip.Cur_Main_Recipe.process_info.Power;
 
                if (!_Parent._equip.scanner.Set_Power(frequency, power))
                    return;
            }
        
            Ablation_Run_Th = new Thread(() => Ablation_Run(dgree));
            Ablation_Run_Th.Start();
 
            while (true)
            {
                if (Ablation_Run_Th.ThreadState == ThreadState.Stopped)
                {
                    MessageBox.Show("End");
                    break;
                }
            }
 
        }
 
        private void Ablation_Run(double degree)
        {
            bool moving;
 
            do
            {
                _Parent._equip.scanner.Get_Busy(out moving);
            } while (moving);
 
            Thread th;
            if (_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_1.Draw)
            {
                th = new Thread(() => Ablation_Run(_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_1, degree));
                th.Start();
                while (th.ThreadState != ThreadState.Stopped) { }
            }
 
            if (_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_2.Draw)
            {
                th = new Thread(() => Ablation_Run(_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_2, degree));
                th.Start();
                while (th.ThreadState != ThreadState.Stopped) { }
            }
 
            if (_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_3.Draw)
            {
                th = new Thread(() => Ablation_Run(_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_3, degree));
                th.Start();
                while (th.ThreadState != ThreadState.Stopped) { }
            }
 
            if (_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_4.Draw)
            {
                th = new Thread(() => Ablation_Run(_Parent._equip.Cur_Main_Recipe.process_info.Draw_Info_4, degree));
                th.Start();
                while (th.ThreadState != ThreadState.Stopped) { }
            }
        }
 
        private void Ablation_Run(Process_Draw_Info draw_info, double degree)
        {
            Scanner_Recipe rec;
 
            bool moving;
 
            float work_area_x, work_area_y;
            float start_x, end_x, start_y, end_y, distance, draw_distance;
            int repeat, range, draw_repeat;
 
            Scanner_Recipe.Ablation_Style waveform;
 
            work_area_x = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_X;
            work_area_y = _Parent._equip.Cur_Main_Recipe.process_info.Work_Area_Y;
 
            start_x = draw_info.Start_X;
            end_x = draw_info.End_X;
            start_y = draw_info.Start_Y;
            end_y = draw_info.End_Y;
 
            distance = _Parent._equip.Cur_Main_Recipe.process_info.Hatch_Distance;
            repeat = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Repeat;
            range = _Parent._equip.Cur_Main_Recipe.process_info.Jump_Range;
 
            draw_distance = draw_info.Distance;
            draw_repeat = draw_info.Repeat;
 
            waveform = (Scanner_Recipe.Ablation_Style)_Parent._equip.Cur_Main_Recipe.process_info.Waveform;
 
            if (draw_info.Reverse)
            {
                rec = new Scanner_Recipe(work_area_x, work_area_y, start_x, start_y, end_x, end_y, distance, repeat, range, 0, draw_distance, 0, draw_repeat, waveform, degree, draw_info.Reverse);
            }
            else
            {
                rec = new Scanner_Recipe(work_area_x, work_area_y, start_x, start_y, end_x, end_y, distance, repeat, range, draw_distance, 0, draw_repeat, 0, waveform, degree, draw_info.Reverse);
            }
 
            do
            {
                _Parent._equip.scanner.Get_Busy(out moving);
            } while (moving);
 
            _Parent._equip.scanner.Set_Start_List(1);
 
            foreach (Scanner_Position_Info info in rec.Recipe_Pos_Info)
            {
                if (info.mark)
                {
                    System.Diagnostics.Debug.WriteLine($"MARK : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    _Parent._equip.scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            _Parent._equip.scanner.Set_End_Of_List();
            _Parent._equip.scanner.Set_Excute_List(1);
 
            do
            {
                _Parent._equip.scanner.Get_Busy(out moving);
            } while (moving);
        }
 
        private void btn_Power_Set_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info != null)
            {
                int frequency = _Parent._equip.Cur_Main_Recipe.process_info.Frequency;
                double power = _Parent._equip.Cur_Main_Recipe.process_info.Power;
 
                _Parent._equip.scanner.Set_Power(frequency, power);
            }
        }
    }
}