public LineaCameraTriggerable(SerialEntity serialEntity, int channle) { this.ttlSignalBoarCtr = new TTLSignalBoardControl(serialEntity); this.channle = channle; this.isDispsed = false; this.ttlSignalBoarCtr.SetTTLEnableState(EnableType.FLASH, false); }
private void simpleButton21_Click(object sender, EventArgs e) { WaitDialogForm wdf = new WaitDialogForm("命令执行中,请稍候......"); try { SerialEntity s = GetSerialParamFromPage(); SerialInstruction.WriteSerialParam(s, Gloab.AllData.Address, CommandCallback); Gloab.AllData.Serial = s; SetDebugStr("写入串口参数成功"); } catch (CommandException ex) { SetDebugStr("写入串口参数失败"); XtraMessageBox.Show(ex.Message); } catch (Exception exp) { SetDebugStr("写入串口参数失败"); log.Error(exp); } finally { wdf.Close(); } }
private SerialEntity GetSerialParamFromPage() { SerialEntity serial = new SerialEntity(); serial.SerialOneBaudRate.Name = comboBoxEdit1.Text; serial.SerialOneBaudRate.Value = Gloab.Config.BaudRate.First(c => c.Key == comboBoxEdit1.Text).Value; serial.SerialOnePortModel.Name = comboBoxEdit2.Text; serial.SerialOnePortModel.Value = Gloab.Config.SerialPortModel.First(c => c.Key == comboBoxEdit2.Text).Value; serial.SerialOneAddress = (short)spinEdit3.Value; serial.SerialOneInterval = (int)spinEdit4.Value; serial.SerialOneMN = textEdit29.Text; serial.SerialOnePW = textEdit33.Text; serial.SerialOneCN = textEdit32.Text; serial.SerialOneST = textEdit31.Text; serial.SerialTwoBaudRate.Name = comboBoxEdit3.Text; serial.SerialTwoBaudRate.Value = Gloab.Config.BaudRate.First(c => c.Key == comboBoxEdit3.Text).Value; serial.SerialTwoPortModel.Name = comboBoxEdit4.Text; serial.SerialTwoPortModel.Value = Gloab.Config.SerialPortModel.First(c => c.Key == comboBoxEdit4.Text).Value; serial.SerialTwoAddress = (short)spinEdit5.Value; serial.SerialTwoInterval = (int)spinEdit6.Value; serial.SerialTwoMN = textEdit36.Text; serial.SerialTwoPW = textEdit35.Text; serial.SerialTwoCN = textEdit34.Text; serial.SerialTwoST = textEdit28.Text; return(serial); }
private void SetSerialParamToPage(SerialEntity serial) { comboBoxEdit1.Text = serial.SerialOneBaudRate.Name; comboBoxEdit2.Text = serial.SerialOnePortModel.Name; spinEdit3.Value = serial.SerialOneAddress; spinEdit4.Value = serial.SerialOneInterval; textEdit29.Text = serial.SerialOneMN; textEdit33.Text = serial.SerialOnePW; textEdit32.Text = serial.SerialOneCN; textEdit31.Text = serial.SerialOneST; comboBoxEdit3.Text = serial.SerialTwoBaudRate.Name; comboBoxEdit4.Text = serial.SerialTwoPortModel.Name; spinEdit5.Value = serial.SerialTwoAddress; spinEdit6.Value = serial.SerialTwoInterval; textEdit36.Text = serial.SerialTwoMN; textEdit35.Text = serial.SerialTwoPW; textEdit34.Text = serial.SerialTwoCN; textEdit28.Text = serial.SerialTwoST; }
public static SerialEntity ReadSerialParam(byte address, CommonConfig config, Action <string> callback) { byte[] sendb = Command.GetReadSendByte(address, 0x00, 0x36, 82); callback(string.Format("T: {0}", CommandUnits.ByteToHexStr(sendb))); byte[] rbytes = PLAASerialPort.Read(sendb); callback(string.Format("R: {0}", CommandUnits.ByteToHexStr(rbytes))); SerialEntity serial = new SerialEntity(); Array.Reverse(rbytes, 3, 2); serial.SerialOneBaudRate.Value = BitConverter.ToInt16(rbytes, 3); serial.SerialOneBaudRate.Name = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialOneBaudRate.Value).Key; Array.Reverse(rbytes, 5, 2); serial.SerialOnePortModel.Value = BitConverter.ToInt16(rbytes, 5); serial.SerialOnePortModel.Name = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialOnePortModel.Value).Key; Array.Reverse(rbytes, 7, 2); serial.SerialOneAddress = BitConverter.ToInt16(rbytes, 7); Array.Reverse(rbytes, 9, 2); Array.Reverse(rbytes, 11, 2); serial.SerialOneInterval = BitConverter.ToInt32(rbytes, 9); List <byte> byteTemp = new List <byte>(); for (int i = 13; i < 13 + 48;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 61; i < 61 + 4;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 65; i < 65 + 8;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOneCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 73; i < 73 + 12;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialOnePW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); Array.Reverse(rbytes, 85, 2); serial.SerialTwoBaudRate.Value = BitConverter.ToInt16(rbytes, 85); serial.SerialTwoBaudRate.Name = config.BaudRate.FirstOrDefault(c => c.Value == serial.SerialTwoBaudRate.Value).Key; Array.Reverse(rbytes, 87, 2); serial.SerialTwoPortModel.Value = BitConverter.ToInt16(rbytes, 87); serial.SerialTwoPortModel.Name = config.SerialPortModel.FirstOrDefault(c => c.Value == serial.SerialTwoPortModel.Value).Key; Array.Reverse(rbytes, 89, 2); serial.SerialTwoAddress = BitConverter.ToInt16(rbytes, 89); Array.Reverse(rbytes, 91, 2); Array.Reverse(rbytes, 93, 2); serial.SerialTwoInterval = BitConverter.ToInt32(rbytes, 91); byteTemp = new List <byte>(); for (int i = 95; i < 95 + 48;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoMN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 143; i < 143 + 4;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoST = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 147; i < 147 + 8;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoCN = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); byteTemp = new List <byte>(); for (int i = 155; i < 155 + 12;) { if (rbytes[i + 1] != 0x00) { byteTemp.Add(rbytes[i + 1]); } i += 2; } serial.SerialTwoPW = ASCIIEncoding.ASCII.GetString(byteTemp.ToArray()); return(serial); }
public static void WriteSerialParam(SerialEntity serial, byte address, Action <string> callback) { List <byte> content = new List <byte>(); content.AddRange(BitConverter.GetBytes(serial.SerialOneBaudRate.Value).Reverse()); content.AddRange(BitConverter.GetBytes(serial.SerialOnePortModel.Value).Reverse()); content.AddRange(BitConverter.GetBytes(serial.SerialOneAddress).Reverse()); byte[] byteTemp = BitConverter.GetBytes(serial.SerialOneInterval); Array.Reverse(byteTemp, 0, 2); Array.Reverse(byteTemp, 2, 2); content.AddRange(byteTemp); byte[] byteMN = new byte[48]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneMN); for (int i = 0; i < byteTemp.Length; i++) { byteMN[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteMN); byte[] byteST = new byte[4]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneST); for (int i = 0; i < byteTemp.Length; i++) { byteST[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteST); byte[] byteCN = new byte[8]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOneCN); for (int i = 0; i < byteTemp.Length; i++) { byteCN[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteCN); byte[] bytePW = new byte[12]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialOnePW); for (int i = 0; i < byteTemp.Length; i++) { bytePW[i * 2 + 1] = byteTemp[i]; } content.AddRange(bytePW); content.AddRange(BitConverter.GetBytes(serial.SerialTwoBaudRate.Value).Reverse()); content.AddRange(BitConverter.GetBytes(serial.SerialTwoPortModel.Value).Reverse()); content.AddRange(BitConverter.GetBytes(serial.SerialTwoAddress).Reverse()); byteTemp = BitConverter.GetBytes(serial.SerialTwoInterval); Array.Reverse(byteTemp, 0, 2); Array.Reverse(byteTemp, 2, 2); content.AddRange(byteTemp); byte[] byteMN2 = new byte[48]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoMN); for (int i = 0; i < byteTemp.Length; i++) { byteMN2[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteMN2); byte[] byteST2 = new byte[4]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoST); for (int i = 0; i < byteTemp.Length; i++) { byteST2[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteST2); byte[] byteCN2 = new byte[8]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoCN); for (int i = 0; i < byteTemp.Length; i++) { byteCN2[i * 2 + 1] = byteTemp[i]; } content.AddRange(byteCN2); byte[] bytePW2 = new byte[12]; byteTemp = ASCIIEncoding.ASCII.GetBytes(serial.SerialTwoPW); for (int i = 0; i < byteTemp.Length; i++) { bytePW2[i * 2 + 1] = byteTemp[i]; } content.AddRange(bytePW2); byte[] sendb = Command.GetWiteSendByte(address, 0x00, 0x36, content.ToArray()); callback(string.Format("T: {0}", CommandUnits.ByteToHexStr(sendb))); PLAASerialPort.Write(sendb); }