private void m_btnRead_Click(object sender, EventArgs e) { try { //读取历史纪录 TOCTest.comm.CommPort objCommPort = comm.CommPort.Instance; string strCommand = "FF" + Convert.ToInt64(TOCTest.db.dbMrg.QueryDeviceNum(Main.ms_strDeviceName)).ToString("X2") + "0x00" + "0x07" + "0x52" + "0x48" + "00"; byte[] byCommand = TOCTest.utils.help.getCheckSum(strCommand); objCommPort.Send(byCommand); } catch (Exception ex) { utils.loghelp.log.Error(ex.Message, ex); } }
private void timerPollingInquiry_Tick(object sender, EventArgs e) { try { TOCTest.comm.CommPort objCommPort = TOCTest.comm.CommPort.Instance; string str = "FF" + "{0}" + "0x05" + "0x03" + "00"; str = string.Format(str, TOCTest.db.dbMrg.QueryDeviceNum(TOCTest.Main.ms_strDeviceName)); byte[] byDate = TOCTest.utils.help.getCheckSum(str); objCommPort.Send(byDate); TOCTest.utils.loghelp.log.Debug(string.Format("读取测试值{0}", TOCTest.utils.help.ByteToHexStr(byDate).ToString())); } catch (Exception ex) { TOCTest.utils.loghelp.log.Error(ex.Message, ex); } }
private void m_btnWrite_Click(object sender, EventArgs e) { try { TOCTest.comm.CommPort objCommPort = comm.CommPort.Instance; string Hisdatasum = m_dataGridViewList.Rows.Count.ToString("X4"); int nSum = m_dataGridViewList.Rows.Count; int histNum = 0; for (int i = 0; i < nSum; i++) { histNum++; string Hisdatacurnum = histNum.ToString("X4"); string mTreeView = Main.ms_strDeviceName.ToString(); string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=..\\..\\mdb\\HistoryData.mdb"; string strQuery = "Select * From {0} where [id]={1}"; strQuery = string.Format(strQuery, mTreeView, m_dataGridViewList.Rows[i].Cells[0].Value.ToString()); OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); OleDbCommand cmd = new OleDbCommand(strQuery, conn); OleDbDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { string strInfo = reader[9].ToString(); Int64 nNum = Convert.ToInt64(strInfo); Int64 nLength = 900 + 64; string strCom = "FF" + "01" + nLength.ToString("X4") + "0x57" + "0x48" + Hisdatasum + histNum.ToString("X4"); string strTest_type = TOCTest.utils.help.converStringHex(reader[1].ToString(), 1); strCom = strCom + strTest_type; string strTest_Psernum = TOCTest.utils.help.converStringHex(reader[2].ToString(), 16); strCom = strCom + strTest_Psernum; string strTest_OprationName = TOCTest.utils.help.converStringHex(reader[3].ToString(), 16); strCom = strCom + strTest_OprationName; string strTest_StartDt = TOCTest.utils.help.getDBDateTime(reader[4].ToString()); strCom = strCom + strTest_StartDt; string strBott_Amount = Convert.ToInt64(reader[5].ToString()).ToString("X2"); strCom = strCom + strBott_Amount; string strStart_Bott = Convert.ToInt64(reader[6].ToString()).ToString("X2"); strCom = strCom + strStart_Bott; string strDilu_Mult = Convert.ToInt64(reader[7].ToString()).ToString("X8"); strCom = strCom + strDilu_Mult; string strTest_EndDt = TOCTest.utils.help.getDBDateTime(reader[8].ToString()); strCom = strCom + strTest_EndDt; string Htest_testimes = nNum.ToString("X8"); strCom = strCom + Htest_testimes; strCom = strCom + getData(reader[10].ToString(), nNum); strCom = strCom + getData(reader[11].ToString(), nNum); strCom = strCom + getData(reader[12].ToString(), nNum); strCom = strCom + "00"; byte[] byDate = TOCTest.utils.help.getCheckSum(strCom); objCommPort.Send(byDate); } conn.Close(); } } catch (Exception ex) { utils.loghelp.log.Error(ex.Message, ex); } }
private void InitRS232() { try { CommPort com = CommPort.Instance; int found = 0; string[] portList = com.GetAvailablePorts(); for (int i = 0; i < portList.Length; ++i) { string name = portList[i]; comboBoxPortName.Items.Add(name); if (name == Settings.Port.PortName) { found = i; } } if (portList.Length > 0) { comboBoxPortName.SelectedIndex = found; } Int32[] baudRates = { 100, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 57600, 115200, 128000, 256000, 0 }; found = 0; for (int i = 0; baudRates[i] != 0; ++i) { comboBoxBaudRate.Items.Add(baudRates[i].ToString()); if (baudRates[i] == Settings.Port.BaudRate) { found = i; } } comboBoxBaudRate.SelectedIndex = found; comboBoxDataBits.Items.Add("5"); comboBoxDataBits.Items.Add("6"); comboBoxDataBits.Items.Add("7"); comboBoxDataBits.Items.Add("8"); comboBoxDataBits.SelectedIndex = Settings.Port.DataBits - 5; foreach (string s in Enum.GetNames(typeof(Parity))) { comboBoxParity.Items.Add(s); } comboBoxParity.SelectedIndex = (int)Settings.Port.Parity; foreach (string s in Enum.GetNames(typeof(StopBits))) { comboBoxStopBits.Items.Add(s); } comboBoxStopBits.SelectedIndex = (int)Settings.Port.StopBits; foreach (string s in Enum.GetNames(typeof(Handshake))) { comboBoxHandshake.Items.Add(s); } comboBoxHandshake.SelectedIndex = (int)Settings.Port.Handshake; com.StatusChanged += OnStatusChanged; //com.DataReceived += OnDataReceived; com.Open(); } catch (Exception ex) { utils.loghelp.log.Error(ex.Message, ex); } }