private void ReadDataDisplay(object sender, ReadDataEventAgrs e) { try { KEEP_ARRIVE_COUNT = 0; string[] str = e.Data.Split('|'); if (int.Parse(str[2]) < 10) { if (qty2 == 0) { this.Invoke((MethodInvoker)(() => btnTaskStop.PerformClick())); MessageBox.Show("작업이 완료되었습니다."); this.Invoke((MethodInvoker)(() => btnStop.PerformClick())); } qty3++; nowqty++; this.Invoke((MethodInvoker)(() => GOODQTY.Text = qty3.ToString())); qty2 = qty2 - 1; this.Invoke((MethodInvoker)(() => residualqty.Text = (qty2).ToString())); IF_SetValue(); } } catch (Exception err) { Log.WriteError(err.Message); } }
/// <summary> /// 수신된 데이터를 찍어주고, DB에 전송한다. /// </summary> private void DoingSchedule() { string lsRecvData; int liCnt; string lsTmpData; string[] laData; try { if (t_client == null || !t_client.client.Connected) { return; } if (t_client.client.Available > 0) { byte[] rcvTemp = new byte[t_client.client.Available]; recvData.Read(rcvTemp, 0, rcvTemp.Length); string readData = UTF7Encoding.UTF7.GetString(rcvTemp); this.Log.WriteInfo($"[RECV] : {readData}"); RECV_TMP_DATA += readData; liCnt = RECV_TMP_DATA.IndexOf(STX); if (liCnt >= 0) { lsRecvData = RECV_TMP_DATA.Substring(liCnt); if (lsRecvData.Substring(0, 1) == STX) { while (true) { liCnt = lsRecvData.IndexOf(ETX); if (liCnt >= 0) { lsTmpData = lsRecvData.Substring(0, liCnt); } else { break; } // ========= 도착한 데이타 처리 =================== //lsTmpData = STX|Date|TaskID|ProductID|Qty|BadQty|ETX //lsTmpData = STX|x|ETX laData = lsTmpData.Split('|'); if (laData.Length < 7) { break; } if (ReadData != null) { ReadDataEventAgrs args = new ReadDataEventAgrs(); args.Data = $"[{laData[1]}] |{laData[2]}|{laData[3]}|{laData[4]}|{laData[5]}"; ReadData(null, args); } switch (laData[1]) { case "X": case "x": //KeepArrive 수신 처리 //KEEP_ARRIVE_COUNT = 0; break; case "RESET": case "reset": break; default: //_SetValue($"[{laData[1]}] |{laData[2]}|{laData[3]}|{laData[4]}|{laData[5]}"); break; } lsRecvData = lsRecvData.Substring(liCnt + 1); liCnt = lsRecvData.IndexOf(STX); if (liCnt >= 0) { lsRecvData = lsRecvData.Substring(liCnt); RECV_TMP_DATA = lsRecvData; } else { if (lsRecvData.Length > 0) { lsRecvData = lsRecvData.Substring(0); RECV_TMP_DATA = lsRecvData; } } if (string.IsNullOrEmpty(lsRecvData.Trim())) { RECV_TMP_DATA = string.Empty; break; } } } } } } catch (Exception err) { Log.WriteError($"[RECV중 오류]:{err.Message}"); if (err.Message.Contains("Connection Error") || err.Message.Contains("개체")) { throw new Exception(err.Message); } } finally { Thread.Sleep(100); } }