천호석
2022-12-02 0ea3c195df71c3e26bf341d095d209b4d8e4c562
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
using Keyence.AutoID.SDK;
using Navigation;
using System;
using System.Threading;
using System.Windows.Forms;
 
namespace SHARP_CLAS_UI.Screen
{
    public partial class Form_Maintenance_Control : Form
    {
        #region Field
        delegate void UI_Update_Delegate();
 
        Form_Frame _Parent;
        Thread UI_Update_Th;
 
        Axis Selected_Axis;
 
        LiveviewForm Load_BCR_View;
        bool update_check;
        #endregion
 
        #region Construct
        public Form_Maintenance_Control(Form_Frame _Parent)
        {
            InitializeComponent();
            this._Parent = _Parent;
 
            Init_Axis_Name();
            Init_Thread();
        }
        #endregion
 
        #region Form Function
        private void cbb_Axis_SelectedIndexChanged(object sender, EventArgs e)
        {
            MotorAxis axis;
            if (Enum.TryParse((string)cbb_Axis.SelectedItem, true, out axis))
            {
                Selected_Axis = _Parent._equip.Board_Control.Motors[axis];
            }
        }
 
        private void btn_Amp_On_Click(object sender, EventArgs e)
        {
            Selected_Axis.Amp_On();
        }
 
        private void btn_Amp_Off_Click(object sender, EventArgs e)
        {
            Selected_Axis.Amp_Off();
        }
 
        private void btn_Reset_Click(object sender, EventArgs e)
        {
            Selected_Axis.MC_Error_Reset();
        }
 
        private void btn_Stop_Click(object sender, EventArgs e)
        {
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
            Selected_Axis.Move_Stop(velocity);
        }
 
        private void btn_Home_Click(object sender, EventArgs e)
        {
            Selected_Axis.Home();
        }
 
        private void btn_Move_Abs_Click(object sender, EventArgs e)
        {
            double position;
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
 
            if (double.TryParse(tb_Position.Text, out position))
            {
                Selected_Axis.Move_Absolute_Pos(position, velocity);
            }
        }
 
        private void btn_Move_Rel_Click(object sender, EventArgs e)
        {
 
            double position;
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
 
            if (double.TryParse(tb_Position.Text, out position))
            {
                Selected_Axis.Move_Relative_Pos(position, velocity);
            }
        }
 
        private void btn_Negative_Jog_MouseDown(object sender, MouseEventArgs e)
        {
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
            Selected_Axis.Negative_Zog(velocity);
        }
 
        private void btn_Negative_Jog_MouseUp(object sender, MouseEventArgs e)
        {
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
            Selected_Axis.Move_Stop(velocity);
        }
 
        private void btn_Positive_Jog_MouseDown(object sender, MouseEventArgs e)
        {
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
            Selected_Axis.Positive_Zog(velocity);
        }
 
        private void btn_Positive_Jog_MouseUp(object sender, MouseEventArgs e)
        {
            double velocity;
 
            velocity = double.Parse(nud_Velocity.Value.ToString("F3"));
            Selected_Axis.Move_Stop(velocity);
        }
 
        private void btn_Show_Vision_Test_Click(object sender, EventArgs e)
        {
            _Parent.Screen_Vision_Test.Show();
 
            _Parent.Screen_Vision_Test.TopMost = true;
            _Parent.Screen_Vision_Test.TopMost = false;
        }
 
        private void btn_Sequence_View_Shot_Click(object sender, EventArgs e)
        {
            _Parent.Screen_Sequence_Viewer.Show();
 
            _Parent.Screen_Sequence_Viewer.TopMost = true;
            _Parent.Screen_Sequence_Viewer.TopMost = false;
        }
 
        private void btn_Scanner_Run_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                return;
 
            Scanner scanner = _Parent._equip.scanner;
 
            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 (!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 (!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
            {
                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.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}");
                    scanner.Set_Mark_Abs(info.x, info.y);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine($"JUMP : {info.x}, {info.y}");
                    scanner.Set_Jump_Abs(info.x, info.y);
                }
            }
 
            scanner.Set_End_Of_List();
            scanner.Set_Excute_List(1);
 
            do
            {
                scanner.Get_Busy(out moving);
            } while (moving);
 
        }
 
        private void btn_Scanner_test_Click(object sender, EventArgs e)
        {
            if (_Parent._equip.Cur_Main_Recipe.process_info == null)
                return;
 
            Scanner scanner = _Parent._equip.scanner;
            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 (!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 (!scanner.Set_Power(frequency, power))
                return;
 
            scanner.Squire_Marking();
 
            bool moving;
            do
            {
                scanner.Get_Busy(out moving);
            } while (moving);
        }
 
        private void btn_Scanner_View_Click(object sender, EventArgs e)
        {
            _Parent.Screen_Scanner_View.Show();
            _Parent.Screen_Scanner_View.TopMost = true;
            _Parent.Screen_Scanner_View.TopMost = false;
        }
 
        private void btn_All_Error_Reset_Click(object sender, EventArgs e)
        {
            foreach (Axis axis in _Parent._equip.Board_Control.Motors.Values)
            {
                axis.MC_Error_Reset();
            }
        }
 
        private void btn_All_Amp_On_Click(object sender, EventArgs e)
        {
            foreach (Axis axis in _Parent._equip.Board_Control.Motors.Values)
            {
                axis.Amp_On();
            }
        }
        #endregion
 
        #region Function
        public void Set_Language()
        {
            try
            {
                lb_Motor_Control.Text = resLanguage.Motor_Control;
 
                gb_Board_Status.Text = resLanguage.BOARD_STATUS;
                lb_Board_Init.Text = resLanguage.Board_init;
                lb_Board_Id.Text = resLanguage.Board_ID;
                lb_Board_Status.Text = resLanguage.Board_Status1;
 
                gb_Motor_Select.Text = resLanguage.Motor_Select;
 
                gb_Axis_Control.Text = resLanguage.Axis_Control;
                btn_Amp_On.Text = resLanguage.AMP_On;
                btn_Reset.Text = resLanguage.RESET;
                btn_Amp_Off.Text = resLanguage.AMP_Off;
                btn_Home.Text = resLanguage.Home;
                btn_Move_Abs.Text = resLanguage.ABS;
                btn_Move_Rel.Text = resLanguage.REL;
                btn_Stop.Text = resLanguage.Stop;
                lb_Position_1.Text = resLanguage.POSITION;
                lb_Velocity_1.Text = resLanguage.Velocity;
 
                gb_Motor_Status.Text = resLanguage.MOTOR_STATUS;
                lb_Name.Text = resLanguage.Name;
                lb_Axis.Text = resLanguage.AXIS;
                lb_Position.Text = resLanguage.POSITION;
                lb_Velocity.Text = resLanguage.Velocity;
                lb_Error_ID.Text = resLanguage.Error_ID;
                lb_Error_Info_0.Text = resLanguage.Error_info_0;
                lb_Error_Info_1.Text = resLanguage.Error_info_1;
 
                btn_Show_Vision_Test.Text = resLanguage.VISION_TEST;
                btn_Sequence_View_Shot.Text = resLanguage.SEQUENCE_VIEW;
                btn_Scanner_View.Text = resLanguage.SCANNER_VIEW;
 
                btn_All_Error_Reset.Text = resLanguage.All_Error_Reset;
                btn_All_Amp_On.Text = resLanguage.All_Amp_On;
            }
            catch(Exception ex)
            {
 
            }
        }
 
        private void Init_Axis_Name()
        {
            cbb_Axis.Items.Clear();
 
            foreach (string motor_name in Enum.GetNames(typeof(MotorAxis)))
            {
                cbb_Axis.Items.Add(motor_name);
            }
 
            cbb_Axis.SelectedIndex = 0;
        }
 
        private void Init_Live_View_Form()
        {
            Load_BCR_View = new LiveviewForm();
 
            this.Load_BCR_View.BackColor = System.Drawing.Color.Black;
            this.Load_BCR_View.BinningType = LiveviewForm.ImageBinningType.OneQuarter;
            this.Load_BCR_View.Dock = DockStyle.Fill;
            this.Load_BCR_View.ImageFormat = LiveviewForm.ImageFormatType.Jpeg;
            this.Load_BCR_View.ImageQuality = 5;
            this.Load_BCR_View.IpAddress = "192.168.100.100";
            this.Load_BCR_View.Location = new System.Drawing.Point(4, 35);
            this.Load_BCR_View.Name = "Load_BCR_View";
            this.Load_BCR_View.PullTimeSpan = 100;
            this.Load_BCR_View.Size = new System.Drawing.Size(325, 236);
            this.Load_BCR_View.TabIndex = 4;
            this.Load_BCR_View.TimeoutMs = 2000;
 
            panel5.Controls.Add(Load_BCR_View);
            _Parent._equip.LD_Tray_BCR.Add_Liveview_Form(Load_BCR_View);
            Load_BCR_View.EndReceive();
            Load_BCR_View.IpAddress = _Parent._equip.LD_Tray_BCR.Ip;
            Load_BCR_View.BeginReceive();
        }
 
        private void Init_Thread()
        {
            UI_Update_Th = new Thread(UI_Update_Th_Set);
            UI_Update_Th.Start();
        }
 
        private void UI_Update_Th_Set()
        {
            while (!this.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
                {
 
                    if (_Parent._equip.Board_Control.BoardInit)
                    {
                        tb_Board_Init.Text = "Success";
                        tb_Board_Init.BackColor = System.Drawing.Color.Lime;
                    }
                    else
                    {
                        tb_Board_Init.Text = "Fail";
                        tb_Board_Init.BackColor = System.Drawing.Color.Green;
                    }
 
                    tb_Board_ID.Text = $"{_Parent._equip.Board_Control.BoardID}";
                    tb_Board_Status.Text = $"{_Parent._equip.Board_Control.BoardMode}";
 
                    tb_Error_ID.Text = $"{ Selected_Axis.ErrorID}";
                    tb_Error_Info_0.Text = $"{ Selected_Axis.ErrorInfo0}";
                    tb_Error_Info_1.Text = $"{ Selected_Axis.ErrorInfo1}";
 
                    tb_Real_Position.Text = $"{ Selected_Axis.Position}";
                    tb_Real_Velocity.Text = $"{ Selected_Axis.Velocity}";
 
                    lb_Limit_Switch_Pos.BackColor = Selected_Axis.LimitSwitchPos ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Home_Abs_Switch.BackColor = Selected_Axis.HomeAbsSwitch ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Limit_Switch_Pos_Event.BackColor = Selected_Axis.LimitSwitchPosEvent ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Limit_Switch_Neg_Event.BackColor = Selected_Axis.LimitSwitchNegEvent ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Drive_Fault.BackColor = Selected_Axis.DriveFault ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Sensor_Stop.BackColor = Selected_Axis.SensorStop ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Ready_For_Power_On.BackColor = Selected_Axis.ReadyForPowerOn ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Power_On.BackColor = Selected_Axis.PowerOn ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Is_Homed.BackColor = Selected_Axis.IsHomed ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Axis_Waring.BackColor = Selected_Axis.AxisWarning ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Motion_Complete.BackColor = Selected_Axis.MotionComplete ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Gearing.BackColor = Selected_Axis.Gearing ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Group_Motion.BackColor = Selected_Axis.GroupMotion ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Buffer_Full.BackColor = Selected_Axis.BufferFull ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Reserved_30.BackColor = Selected_Axis.Reserved_as_30 ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Reserved_31.BackColor = Selected_Axis.Reserved_as_31 ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Limit_Switch_Neg.BackColor = Selected_Axis.LimitSwitchNeg ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Direction_Negative.BackColor = Selected_Axis.DirectionNegative ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Direction_Positive.BackColor = Selected_Axis.DirectionPositive ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Descelerating.BackColor = Selected_Axis.Decelerating ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Accelerating.BackColor = Selected_Axis.Accelerating ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Contstant_Velocity.BackColor = Selected_Axis.ConstantVelocity ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Reserved_9.BackColor = Selected_Axis.Reserved_as_9 ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Reserved_8.BackColor = Selected_Axis.Reserved_as_8 ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Homing.BackColor = Selected_Axis.Homing ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Synchro_Motion.BackColor = Selected_Axis.SynchroMotion ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Continuous_Motion.BackColor = Selected_Axis.ContinuousMotion ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Discreate_Motion.BackColor = Selected_Axis.DiscreteMotion ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Stand_Still.BackColor = Selected_Axis.StandStill ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Stopping.BackColor = Selected_Axis.Stopping ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Disabled.BackColor = Selected_Axis.Disabled ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                    lb_Error_Stop.BackColor = Selected_Axis.ErrorStop ? System.Drawing.Color.Lime : System.Drawing.Color.Green;
                }
                catch (Exception)
                {
 
                }
                finally
                {
                    update_check = false;
                }
            }
        }
 
        public void Set_User_Level(Navigator.User_Level level)
        {
            if (_Parent._equip.User.Level <= En_User_Level.Operator)
            {
                btn_Move_Abs.Enabled = false;
                btn_Move_Rel.Enabled = false;
 
                btn_Negative_Jog.Enabled = false;
                btn_Positive_Jog.Enabled = false;
 
                btn_Show_Vision_Test.Enabled = false;
                btn_Scanner_View.Enabled = false;
 
                btn_Show_Vision_Test.Enabled = false;
                btn_Scanner_View.Enabled = false;
 
                btn_Scanner_Run.Enabled = false;
                btn_Scanner_test.Enabled = false;
 
                panel2.Enabled = false;
                panel3.Enabled = false;
                panel5.Enabled = false;
                panel6.Enabled = false;
            }
            else
            {
                btn_Move_Abs.Enabled = true;
                btn_Move_Rel.Enabled = true;
 
                btn_Negative_Jog.Enabled = true;
                btn_Positive_Jog.Enabled = true;
 
                btn_Show_Vision_Test.Enabled = true;
                btn_Scanner_View.Enabled = true;
 
                btn_Show_Vision_Test.Enabled = true;
                btn_Scanner_View.Enabled = true;
 
                btn_Scanner_Run.Enabled = true;
                btn_Scanner_test.Enabled = true;
 
                panel2.Enabled = true;
                panel3.Enabled = true;
                panel5.Enabled = true;
                panel6.Enabled = true;
            }
        }
        #endregion
    }
}