private void DataReceived_Client1(object sender, SuperSimpleTcp.DataReceivedEventArgs e)
var tact_time = System.Diagnostics.Stopwatch.StartNew();
var tact_time2 = System.Diagnostics.Stopwatch.StartNew();
string tempDataRecv = Encoding.UTF8.GetString(e.Data.Array, 0, e.Data.Count);
HienLenTextBox("Motion 1 --> Vision: " + tempDataRecv);
if (tempDataRecv == "check")
pDoc.ImgOrigin[0] = null;
pDoc.ChuoiGuiClient1 = "";
pDoc.resultDeviation1 = "";
if (cameraDino[0].IsOpen || cameraBasler[0].IsOpen || cameraHIK[0].IsOpen || cameraIMI[0].IsOpen)
if (pDoc._Type[0] == "Trigger" && cbUsing_Light1.Checked)
int.TryParse(pDoc.Value_Ch1[1], out nVal1);
int.TryParse(pDoc.Value_Ch2[1], out nVal2);
int.TryParse(pDoc.Value_Ch3[1], out nVal3);
int.TryParse(pDoc.Value_Ch4[1], out nVal4);
strVal1 = nVal1 > 20 ? strRep : pDoc.Value_Ch1[1];
strVal2 = nVal2 > 20 ? strRep : pDoc.Value_Ch2[1];
strVal3 = nVal3 > 20 ? strRep : pDoc.Value_Ch3[1];
strVal4 = nVal4 > 20 ? strRep : pDoc.Value_Ch4[1];
LightOn(serialPort1, Properties.Settings.Default.m_type1, pDoc.Value_Ch1[0], pDoc.Value_Ch2[0], pDoc.Value_Ch3[0], pDoc.Value_Ch4[0], pDoc.Value_Ch5[0], pDoc.Value_Ch6[0], pDoc.Value_Ch7[0], pDoc.Value_Ch8[0]);
LightOn(serialPort2, Properties.Settings.Default.m_type2, strVal1, strVal2, strVal3, strVal4, pDoc.Value_Ch5[1], pDoc.Value_Ch6[1], pDoc.Value_Ch7[1], pDoc.Value_Ch8[1]);
LightOff(serialPort1, Properties.Settings.Default.m_type1);
LightOff(serialPort2, Properties.Settings.Default.m_type2);
Creat_Image_Regions_Cam(pDoc.ImgOrigin[pDoc.CameraSelect], pDoc.CameraSelect);
ttTakeImg = tact_time2.ElapsedMilliseconds / 1000.0;
if (pDoc.ImgOrigin[0] == null)
HienLenTextBox("Camera 1 can not take image");
Mat image = pDoc.ImgOrigin[0].Clone();
Task task = Task.Run(() => WorkerThread1.ImageProcessThread(image));
var watch = System.Diagnostics.Stopwatch.StartNew();
StatusLabel.Text = "Processing...";
if (watch.ElapsedMilliseconds >= 10000)
HienLenTextBox("Time out 10000ms Camera 1! ");
if (lbModelName.Text.Trim().ToLower() == "model: dryrun")
pDoc.ChuoiGuiClient1 = "OK_OK_OK_OK_OK_OK_OK_OK_OK_OK";
Sent_to_Client(pDoc.ChuoiGuiClient1);
HienLenTextBox(strDryRun + "Camera 1 complete. " + pDoc.resultDeviation1);
HienlenDataCam1(pDoc.ChuoiGuiClient1);
if (pDoc.ChuoiGuiClient1.Contains("NG") || pDoc.ChuoiGuiClient1.Contains("NO"))
HienLenTextBox("Client phản hồi không đúng định dạng: " + tempDataRecv);
double cycleTime = tact_time.ElapsedMilliseconds / 1000.0;
cycleTime1.Invoke(new MethodInvoker(() =>
cycleTime1.Text = cycleTime.ToString("F3") + " s";
HienLenTextBox("Tact time Cam 1 : take " + ttTakeImg.ToString("F3") + " >> process " + (cycleTime - ttTakeImg).ToString("F3") + " >> " + cycleTime.ToString("F3") + " s");
GC.WaitForPendingFinalizers();
MessageBox.Show("Lỗi ở DataReceived TCP/IP" + ex, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);