public void DoUpdateRegs() { inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs); UpdateMainUIInvoke umi = new UpdateMainUIInvoke(UpdateUIData); if (this.IsHandleCreated) { BeginInvoke(umi, modbusRegs); } }
public void DoUpdateRegs() { try { inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs); UpdateMainUIInvoke umi = new UpdateMainUIInvoke(UpdateUIData); if (this.IsHandleCreated) { BeginInvoke(umi, modbusRegs); } } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); //MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } }
public void DoUpdateRegs() { //Thread.Sleep(1000); //inputCommPortSingleton.GetInstance().initComm(); //if (false == inputCommPortSingleton.GetInstance().openComm()) //{ // btnStop_Click(null, null); //} //Random random = new Random(); while (m_updateDataFlg) { try { int ret = inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs); if (ret != inputCommPortSingleton.RET_OK) { if (ret == inputCommPortSingleton.RET_TIMEOUT) { continue; } else { // set label communication error } break; } UpdateMainUIInvoke umi = new UpdateMainUIInvoke(UpdateUIData); while (!this.IsHandleCreated) { Thread.Sleep(100); } BeginInvoke(umi, modbusRegs); if (modbusRegs.stReg[CHECKFINISH].getHighReg() != 0 && !l_report_flg) { byte[] imageLeft = WindowManager.GetInstance().wrd1.getImageData(); //byte[] imageRight = WindowManager.GetInstance().wrd2.getImageData(); //Left room string sql1 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('left','" + DateTime.Now + "', '" + textBoxTime0.Text + "', '" + coldfilterpoint0.ToString() + "', '" + textBoxNo0.Text + "', '" + textBoxOp0.Text + "', @imageLeft)"; OleDbParameter[] pars = new OleDbParameter[1]; OleDbParameter p = new OleDbParameter("@imageLeft", OleDbType.VarBinary, imageLeft.Length); p.Value = imageLeft; pars[0] = p; int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql1, pars); //Right room //string sql2 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('right','" + DateTime.Now + "', '" + textBoxTime2.Text + "','" + coldfilterpoint1.ToString() + "', '" + textBoxNo2.Text + "', '" + textBoxOp2.Text + "', @imageRight)"; //OleDbParameter[] pars2 = new OleDbParameter[1]; // OleDbParameter p2 = new OleDbParameter("@imageRight", OleDbType.VarBinary, imageRight.Length); //p2.Value = imageRight; //pars2[0] = p2; //i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql2, pars2); //stopUpdateRegs(); saveXMLFile(ROOMNUM_LEFT); saveExcelFile(ROOMNUM_LEFT); byte[] serverData = getAsciiData(coldfilterpoint0.ToString(), textBoxTime0.Text, textBoxNo0.Text, textBoxName0.Text, textBoxDevNo0.Text, textBoxOp0.Text); transResultToServer(serverData); //getAsciiData("", "", "", "", "", ""); l_report_flg = true; } if (modbusRegs.stReg[CHECKFINISH].getLowReg() != 0 && !r_report_flg) { //byte[] imageLeft = WindowManager.GetInstance().wrd1.getImageData(); byte[] imageRight = WindowManager.GetInstance().wrd2.getImageData(); //Left room //string sql1 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('left','" + DateTime.Now + "', '" + textBoxTime1.Text + "', '" + coldfilterpoint0.ToString() + "', '" + textBoxNo1.Text + "', '" + textBoxOp1.Text + "', @imageLeft)"; //OleDbParameter[] pars = new OleDbParameter[1]; //OleDbParameter p = new OleDbParameter("@imageLeft", OleDbType.VarBinary, imageLeft.Length); //p.Value = imageLeft; //pars[0] = p; //int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql1, pars); //Right room string sql2 = "insert into ModbusResultTable(room, TestDate, TestTime, TestResult, TestNo, Operator, [TestImage]) values('right','" + DateTime.Now + "', '" + textBoxTime1.Text + "','" + coldfilterpoint1.ToString() + "', '" + textBoxNo1.Text + "', '" + textBoxOp1.Text + "', @imageRight)"; OleDbParameter[] pars2 = new OleDbParameter[1]; OleDbParameter p2 = new OleDbParameter("@imageRight", OleDbType.VarBinary, imageRight.Length); p2.Value = imageRight; pars2[0] = p2; int i = AccessHelper.ExecuteNonQuery(AccessHelper.ConnString, sql2, pars2); //stopUpdateRegs(); saveXMLFile(ROOMNUM_RIGHT); saveExcelFile(ROOMNUM_RIGHT); byte[] serverData = getAsciiData(coldfilterpoint1.ToString(), textBoxTime1.Text, textBoxNo1.Text, textBoxName1.Text, textBoxDevNo1.Text, textBoxOp1.Text); transResultToServer(serverData); r_report_flg = true; } Thread.Sleep(1000); } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } while (m_updateDataFlg) { try { Thread.Sleep(1000); } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); } } inputCommPortSingleton.GetInstance().closeComm(); }
public void DoUpdateRegs() { while (m_updateDataFlg) { try { if (input_method == INPUT_METHOD_SERIAL) { int ret = inputCommPortSingleton.GetInstance().readRegister(ref modbusRegs); if (ret != inputCommPortSingleton.RET_OK) { if (ret == inputCommPortSingleton.RET_TIMEOUT) { continue; } else { // set label communication error } break; } } else { //modbusNetworkSingleton.GetInstance().writeMultiRegisters(modbusRegs); int ret = modbusNetworkSingleton.GetInstance().readRegister(ref modbusRegs); if (ret != modbusNetworkSingleton.RET_OK) { if (ret == modbusNetworkSingleton.RET_TIMEOUT) { continue; } else { // set label communication error } break; } } UpdateMainUIInvoke umi = new UpdateMainUIInvoke(UpdateUIData); while (!this.IsHandleCreated) { Thread.Sleep(100); } BeginInvoke(umi, modbusRegs); Thread.Sleep(1000); } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); //MessageBox.Show(ex.ToString(), "Error - No Ports available", MessageBoxButtons.OK, MessageBoxIcon.Error); break; } } while (m_updateDataFlg) { try { Thread.Sleep(1000); } catch (Exception ex) { LogClass.GetInstance().WriteExceptionLog(ex); } } if (input_method == INPUT_METHOD_SERIAL) { inputCommPortSingleton.GetInstance().closeComm(); } else { modbusNetworkSingleton.GetInstance().closeComm(); } }