private void Work() { try { int tgr_id = 0; int ack_id = 0; string data; int idx; int ii = 0; char head; int cnt = 0; Random rnd = new Random(); //plc 값 초기화 _opc.WriteOrder(vari.plc.Add_Ack, 0); _opc.WriteOrder(vari.plc.Add_Trigger, 0); _opc.WriteOrder(vari.plc.Add_Data, 0); while (true) { tgr_id = _opc.GetValueInt(vari.plc.Add_Trigger); ack_id = _opc.GetValueInt(vari.plc.Add_Ack); //같으면 다음 데이터 보낸다. if (tgr_id == ack_id) { tgr_id++; vari.iTestSeq++; cnt++; if (cnt > 99999) { cnt = 1; } if (tgr_id > 9999) { tgr_id = 1; } if (vari.iTestSeq > 9999) { vari.iTestSeq = 1; } //data를 만든다. data = $"A{cnt:D5}"; data += $"{vari.iTestSeq:D4}"; data += $"VIN{vari.iTestSeq:D14} "; idx = rnd.Next(1, 3); data += cond_cartype[idx]; idx = rnd.Next(0, 10); data += idx == 1 ? cond_result[2] : cond_result[1]; ii++; if (ii > 999) { ii = 1; } for (int x = 0; x < 25; x++) { head = Convert.ToChar(65 + x); for (int y = 0; y < 3; y++) { switch (y) { case 0: data += $"{head}{ii:D3}"; break; case 1: data += $"{ii:D3}{head}"; break; default: idx = rnd.Next(0, 10); data += idx == 1 ? cond_result[2] : cond_result[1]; break; } } } _opc.WriteOrder(vari.plc.Add_Data, data); _opc.WriteOrder(vari.plc.Add_Trigger, tgr_id); Function.form.control.Invoke_Control_SetProperty(inpWorkCnt, "Value", iWorkCnt.ToString()); Function.form.control.Invoke_Control_SetProperty(inpSeq, "Value", $"{vari.iTestSeq:D4}"); Function.form.control.Invoke_Control_SetProperty(inpWorkCnt, "Value", $"{cnt} / {iWorkCnt}"); } Function.form.control.Invoke_Control_SetProperty(inpID, "Value", $"{tgr_id:D4} / {ack_id:D4}"); if (iWorkCnt > 0 && iWorkCnt <= cnt) { btnRun_Click(null, null); break; } if (bWorkCancel) { break; } Application.DoEvents(); Thread.Sleep(iInterval); } } catch { } }
private void Work_Plc(object obj) { if (vari.OpMode != vari.enOpMode.Monitoring) { return; } if (isWork) { return; } try { isWork = true; int trg_id = opc.GetValueInt(vari.plc.Add_Trigger); int ack_id = opc.GetValueInt(vari.plc.Add_Ack); int confirm_id = opc.GetValueInt(vari.plc.Add_Confirm); if (trg_id == ack_id && ack_id == confirm_id) { return; } Console.WriteLine($"[Work_Plc] 체크 [Trg]{trg_id} [Ack]{ack_id} [Confirm]{confirm_id}"); clsLog.WLog($"[Work_Plc] 체크 [Trg]{trg_id} [Ack]{ack_id} [Confirm]{confirm_id}"); //트리거 id 변경 opc.WriteOrder(vari.plc.Add_Ack, trg_id); string info = opc.GetValueString(vari.plc.Add_Info); string data = opc.GetValueHex(vari.plc.Add_Data); string dd = string.Empty; string tmp; for (int i = 0; i < 4; i++) { tmp = Fnc.StringGet(ref data, 4); } while (data.Length > 11) { //torque tmp = Fnc.StringGet(ref data, 4); dd += tmp; //angle tmp = Fnc.StringGet(ref data, 4); dd += tmp; //result tmp = Fnc.StringGet(ref data, 4); if (tmp.Equals("0001")) { dd += "NG"; } else { dd += "OK"; } } Data_Proc(info, dd); //컨펌 id 변경 opc.WriteOrder(vari.plc.Add_Confirm, trg_id); Console.WriteLine($"[Work_Plc] 체크완료"); } catch (Exception ex) { ProcException(ex, "Work_Plc", false); } finally { isWork = false; } }