private void ThreadRefreshStaHandler() { HiPerfTimer timer = new HiPerfTimer(); System.Threading.Thread.Sleep(1000); int iStep = 0; while (true) { System.Threading.Thread.Sleep(1); switch (iStep) { case 0: { timer.Start(); iStep = 10; } break; case 10: { if (timer.TimeUp(1)) { timer.Start(); for (int i = 0; i < 128; i++) { _bArrayInputSta[i] = true; } iStep = 20; } } break; case 20: { if (timer.TimeUp(1)) { for (int i = 0; i < 128; i++) { _bArrayInputSta[i] = false; } iStep = 0; } } break; default: break; } } }
/// <summary> /// 获取条码 /// </summary> /// <param name="m_strCurrentBarCode">条码</param> /// <returns></returns> private bool Get1DSN(ref string m_strCurrentBarCode) { string strRecieve = ""; char[] charArray = new char[1]; charArray[0] = ','; lock (lockObj) { try { timeM.Start(); while (true) { try { if (bCodeReady) { strRecieve = strRemaid + strRecieve + serialPort.ReadExisting(); if (strRecieve.IndexOf("\r") > -1) { //strRecieve = strRecieve.Trim(); m_strCurrentBarCode = strRecieve.Substring(0, strRecieve.IndexOf("\r")); strRecieve = strRecieve.Substring(strRecieve.IndexOf("\r") + 2); strRemaid = strRecieve; RecieveMessageAction?.Invoke(); break; } if (timeM.TimeUp(0.2)) { return(false); } } } catch { return(false); } System.Threading.Thread.Sleep(1); } } catch { return(false); } } return(true); }
private void ResetDown() { if (MainModule.FormMain.bAuto) { return; } // resetTimer.Start(); resetTimer.Start(); // MainModule.FormMain.bResetPress = false; if (startHoming) { return; } if (resetTimer.TimeUp(2)) { DateSave.Instance().Production.IsStop = false; bJetTestStart = false; jetTestStep = -1; bMarkTestStart = false; markTestStep = -1; // Program.ccdStationA.Clear(); Program.num = 0; MainModule.FormMain.bEstop = false; //if (IOManage.INPUT("ESTOP").On) //{ DateSave.Instance().Production.StationMaterial = false;//工位有无料标志 // } // MainControls.StationMaterial = false;//工位有无料标志 // m_FeederTask.taskInfo.iTaskStep = 0; // m_FeederTask.taskInfo.bTaskOnGoing = false; //m_MarkTask.taskInfo.iTaskStep = 0; // m_MarkTask.taskInfo.bTaskOnGoing = false; // m_TransferTask.taskInfo.iTaskStep = 0; // m_TransferTask.taskInfo.bTaskOnGoing = false; // m_JetTask.taskInfo.iTaskStep = 0; // m_JetTask.taskInfo.bTaskOnGoing = false; MainControls.taskInfo.iTaskStep = 0; MainControls.taskInfo.bTaskOnGoing = false; ControlPlatformLib.Global.logger.Info("长按复位:" + DateTime.Now.ToString("yyyy/MM/dd/ HH : mm : ss")); } }
public bool ReadHeightValue(ref double m_dHeight) { string strReceive = string.Empty; string[] strArray; char[] charArray = new char[1]; string strSend = string.Empty; charArray[0] = ' '; lock (objLock) { try { serialPort.ReadExisting(); strSend = m_cStx.ToString() + "MEASURE" + m_cEnd.ToString() + "\r\n"; serialPort.Write(strSend); hptimer.Start(); strReceive = serialPort.ReadExisting(); while (true) { strReceive += serialPort.ReadExisting(); if (strReceive.IndexOf("\r\n") > -1) { strReceive = strReceive.Trim(); strArray = strReceive.Split(charArray, StringSplitOptions.RemoveEmptyEntries); m_sHeightValue = strArray[1]; m_dHeight = double.Parse(m_sHeightValue); return(true); } if (hptimer.TimeUp(0.5)) { this.adhereForm.Invoke( new Action(() => { LabelHeight.Text = "Error"; LabelHeight.BackColor = Color.Red; } ) ); return(false); } } } catch { this.adhereForm.Invoke( new Action(() => { LabelHeight.Text = "Error"; LabelHeight.BackColor = Color.Red; } ) ); return(false); } } }
public bool ReadPressue(ref double PressureValue) { string strReceive = string.Empty; string[] strArray; char[] charArray = new char[1]; charArray[0] = ','; lock (lockObj) { try { serialPort.ReadExisting(); serialPort.Write("READ\r\n"); hptimer.Start(); strReceive = serialPort.ReadExisting(); while (true) { strReceive += serialPort.ReadExisting(); if (strReceive.IndexOf("\r\n") > -1) { strReceive = strReceive.Trim(); strArray = strReceive.Split(charArray, StringSplitOptions.RemoveEmptyEntries); m_strPressureValue = strArray[2]; PressureValue = double.Parse(m_strPressureValue); break; } if (hptimer.TimeUp(0.5)) { this.adhereForm.Invoke( new Action(() => { labelPressure.Text = "Error"; labelPressure.BackColor = Color.Red; } ) ); return(false); } } } catch { this.adhereForm.Invoke( new Action(() => { labelPressure.Text = "Error"; labelPressure.BackColor = Color.Red; } ) ); return(false); } } return(true); }
private bool GetData(ref string m_hight) { string strRecieve = ""; char[] charArray = new char[1]; charArray[0] = ','; lock (lockObj) { try { timeM.Start(); while (true) { try { strRecieve = strRemaid + strRecieve + serialPort.ReadExisting(); if (strRecieve.IndexOf("\r") > -1) { //strRecieve = strRecieve.Trim(); m_hight = strRecieve.Substring(0, strRecieve.IndexOf("\r")); strRecieve = strRecieve.Substring(strRecieve.IndexOf("\r") + 2); strRemaid = strRecieve; break; } if (timeM.TimeUp(1)) { return(false); } } catch { return(false); } System.Threading.Thread.Sleep(1); } } catch { return(false); } } return(true); }
internal CodeReaderRes ReadByTcpClient(out string strRecv, bool bAsync, int iTimeout) { strRecv = string.Empty; _strRecvData = string.Empty; try { if (null == codeReaderData || null == _tcpClient || !_tcpClient.IsConnected) { return(CodeReaderRes.INITFAIL); } if (!_tcpClient.Send(codeReaderData.strTriggerCmd + "\r\n")) { return(CodeReaderRes.ERROR); } if (bAsync) { return(CodeReaderRes.SUCCESS); } //sync HiPerfTimer hiPerfTimer = new HiPerfTimer(); hiPerfTimer.Start(); while (true) { if (!string.IsNullOrEmpty(_strRecvData)) { break; } if (hiPerfTimer.TimeUp((double)((double)iTimeout / 1000.0))) { return(CodeReaderRes.TIMEOUT); } } strRecv = _strRecvData; return(CodeReaderRes.SUCCESS); } catch (Exception) { return(CodeReaderRes.ERROR); } }
internal CodeReaderRes ReadByRS232(out string strRecv, int iTimeout) { strRecv = string.Empty; if (!bInitOk) { return(CodeReaderRes.INITFAIL); } HiPerfTimer hiPerfTimer = new HiPerfTimer(); string strTemp = ""; lock (_objLock) { try { _port.ReadExisting(); System.Threading.Thread.Sleep(1); _port.Write(codeReaderData.strTriggerCmd + "\r\n"); System.Threading.Thread.Sleep(1); strTemp = _port.ReadExisting(); hiPerfTimer.Start(); while (true) { strTemp += _port.ReadExisting(); if (strRecv.Contains(codeReaderData.strEndCode)) { strRecv = strTemp; return(CodeReaderRes.SUCCESS); } if (hiPerfTimer.TimeUp(iTimeout)) { return(CodeReaderRes.TIMEOUT); } System.Threading.Thread.Sleep(10); } } catch (Exception) { return(CodeReaderRes.ERROR); } } }
private void btnConnect_Click(object sender, EventArgs e) { if (btnConnect.Text.Equals("Connect")) { try { if (null == driver) { throw new Exception(); } HiPerfTimer hTimer = new HiPerfTimer(); driver.Init(codeReaderData); hTimer.Start(); while (true) { if (driver.IsConnected()) { break; } if (hTimer.TimeUp(2)) { break; } } if (!driver.IsConnected()) { MessageBox.Show("Failure to connected to code reader " + codeReaderData.Name, "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } } catch (Exception) { MessageBox.Show("Failure to connected to code reader " + codeReaderData.Name, "", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.ServiceNotification); } } else { } }