public void readDeviceInfo() { /* * Read SW Version */ byte[] result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_READ_SW_VERSION, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read SW Version"); tTxt_Logs.AppendText(Environment.NewLine); return; } int offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int major = result[offset]; int minor = result[offset + 1]; int built = Utility.getU16FromByteA(result, offset + 2); string SWVersion = major.ToString() + "." + minor.ToString() + "." + built.ToString(); tTxt_Logs.AppendText("Device SW Version : " + SWVersion); tTxt_Logs.AppendText(Environment.NewLine); tTxt_DeviceSWVersion.Text = SWVersion; /* * Read EEPROM Version */ result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_EEPROM_VER, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read EERPOM Version"); tTxt_Logs.AppendText(Environment.NewLine); return; } byte E2PVer = result[(int)PACKET_CONF.COMM_POS_PAYLOAD + 3]; tTxt_Logs.AppendText("SENSOR EEPROM : " + E2PVer); tTxt_Logs.AppendText(Environment.NewLine); tTxt_SensorEEPROM.Text = E2PVer.ToString(); /* * Read Device SN */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_READ_DEVICE_SN, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Device SN"); tTxt_Logs.AppendText(Environment.NewLine); return; } string DeviceSN = Encoding.Default.GetString(QuattroProtocol.getResponseValueData(result)).Trim('\0'); tTxt_Logs.AppendText("Device SN : " + DeviceSN); tTxt_Logs.AppendText(Environment.NewLine); tTxt_DeviceSerialNumber.Text = DeviceSN; /* * Read Output Type */ result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_OUTPUT_DEVICE_TYPE, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Board SN"); tTxt_Logs.AppendText(Environment.NewLine); return; } offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int OutputType = result[offset]; int Relay = result[offset + 1]; int BLEModule = result[offset + 2]; tTxt_Logs.AppendText("Output Type : " + OutputType); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Relay Type: " + Relay); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("BLE Fitted : " + BLEModule); tTxt_Logs.AppendText(Environment.NewLine); if (OutputType == 0) { tTxt_OutputDeviceType.Text = "mA Output"; } else { tTxt_OutputDeviceType.Text = "Modbus"; } if (Relay == 0) { tTxt_RealyOption.Text = "Not Fitted"; } else { tTxt_RealyOption.Text = "Fitted"; } if (BLEModule == 0) { tTxt_BLEModule.Text = "Not Fitted"; } else { tTxt_BLEModule.Text = "Fitted"; } /* * Read Sensor Info */ result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_SENSOR_INFO, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Sensor Information"); tTxt_Logs.AppendText(Environment.NewLine); return; } offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int sensorType = result[offset]; int gasType = result[offset + 1]; int cellID = result[offset + 2]; switch (sensorType) { case (int)SENSOR_TPYE.ECC: { tTxt_SensorType.Text = "ECC"; break; } case (int)SENSOR_TPYE.FL_CAT: { tTxt_SensorType.Text = "FLM CAT"; break; } case (int)SENSOR_TPYE.IR: { tTxt_SensorType.Text = "IR"; break; } case (int)SENSOR_TPYE.PID: { tTxt_SensorType.Text = "PID"; break; } case (int)SENSOR_TPYE.MOS: { tTxt_SensorType.Text = "MOS"; break; } default: { tTxt_SensorType.Text = "N/A"; break; } } switch (gasType) { case (int)GAS_TYPE.FLAMMABLE: { tTxt_GasType.Text = "Flammable"; break; } case (int)GAS_TYPE.TOXIC: { tTxt_GasType.Text = "Toxic"; break; } case (int)GAS_TYPE.O2: { tTxt_GasType.Text = "O2"; break; } case (int)GAS_TYPE.VOC: { tTxt_GasType.Text = "VOC"; break; } default: { tTxt_GasType.Text = "N/A"; break; } } tCmb_CellID.SelectedIndex = cellID; tTxt_Logs.AppendText("Sensor Type : " + sensorType); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Gas Type: " + gasType); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Cell ID : " + cellID); tTxt_Logs.AppendText(Environment.NewLine); /* * Read Gas Info */ byte[] channelByte = { 0x00 }; result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_READ_GAS_INFO, channelByte, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Gas Information"); tTxt_Logs.AppendText(Environment.NewLine); return; } offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int channel = result[offset]; int measurementUnit = result[offset + 1]; int resolution = result[offset + 2]; float fullScale = Utility.getF32FromByteA(result, offset + 3); tTxt_Channel.Text = channel.ToString(); switch (measurementUnit) { case 0: { tTxt_MeasuremetUnits.Text = "blank"; break; } case 1: { tTxt_MeasuremetUnits.Text = "%LEL"; break; } case 2: { tTxt_MeasuremetUnits.Text = "mA"; break; } case 3: { tTxt_MeasuremetUnits.Text = "mg/m3"; break; } case 4: { tTxt_MeasuremetUnits.Text = "g/m3"; break; } case 5: { tTxt_MeasuremetUnits.Text = "%Vol"; break; } case 6: { tTxt_MeasuremetUnits.Text = "ppm"; break; } case 7: { tTxt_MeasuremetUnits.Text = "kppm"; break; } case 8: { tTxt_MeasuremetUnits.Text = "LEL.m"; break; } case 9: { tTxt_MeasuremetUnits.Text = "A"; break; } case 10: { tTxt_MeasuremetUnits.Text = "dB"; break; } case 11: { tTxt_MeasuremetUnits.Text = "dBA"; break; } case 12: { tTxt_MeasuremetUnits.Text = "ppm.m"; break; } default: { tTxt_MeasuremetUnits.Text = ""; break; } } switch (resolution) { case 0: { tTxt_DecimalPlace.Text = "1 " + tTxt_MeasuremetUnits.Text; break; } case 1: { tTxt_DecimalPlace.Text = "0.1 " + tTxt_MeasuremetUnits.Text; break; } case 2: { tTxt_DecimalPlace.Text = "0.01 " + tTxt_MeasuremetUnits.Text; break; } case 3: { tTxt_DecimalPlace.Text = "0.001 " + tTxt_MeasuremetUnits.Text; break; } default: { tTxt_DecimalPlace.Text = "1 " + tTxt_MeasuremetUnits.Text; resolution = 0; break; } } double DfullScale = Math.Round(fullScale, resolution); tTxt_FullScaleRange.Text = DfullScale.ToString() + " " + tTxt_MeasuremetUnits.Text; tTxt_Logs.AppendText("Channel : " + channel); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Measurement Unit: " + measurementUnit); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Decimal Point : " + resolution); tTxt_Logs.AppendText(Environment.NewLine); tTxt_Logs.AppendText("Full Scale : " + DfullScale); tTxt_Logs.AppendText(Environment.NewLine); }
public void getBLEInfo() { /* * Read BLE Name */ byte[] result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_GET_BLE_DEVICE_NAME, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_BLEInfo.AppendText("ERROR - Read BLE Name"); tTxt_BLEInfo.AppendText(Environment.NewLine); return; } string BLEname = Encoding.Default.GetString(QuattroProtocol.getResponseValueData(result)).Trim('\0'); tTxt_BLEInfo.AppendText("BLE Device Name : " + BLEname); tTxt_BLEInfo.AppendText(Environment.NewLine); tTxt_BLEDeviceName.Text = BLEname; /* * Read BLE Mac Address */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_GET_BLE_MAC_ADDR, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_BLEInfo.AppendText("ERROR - Read BLE Mac Addreess"); tTxt_BLEInfo.AppendText(Environment.NewLine); return; } string BLEMacAddr = BitConverter.ToString(QuattroProtocol.getResponseValueData(result)).Replace("-", ":"); tTxt_BLEInfo.AppendText("BLE MAC Address : " + BLEMacAddr); tTxt_BLEInfo.AppendText(Environment.NewLine); tTxt_BLEMacAddress.Text = BLEMacAddr; /* * Read BLE SW Version */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_GET_BLE_SW_VER, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_BLEInfo.AppendText("ERROR - Read BLE SW Version"); tTxt_BLEInfo.AppendText(Environment.NewLine); return; } string BLESWVersion = Encoding.Default.GetString(QuattroProtocol.getResponseValueData(result)).Trim('\0'); tTxt_BLEInfo.AppendText("BLE SW Version : " + BLESWVersion); tTxt_BLEInfo.AppendText(Environment.NewLine); tTxt_BLESWVersion.Text = BLESWVersion; /* * Read BLE TX Power */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_GET_BLE_TX_POWER, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_BLEInfo.AppendText("ERROR - Read BLE TW Power"); tTxt_BLEInfo.AppendText(Environment.NewLine); return; } byte BLETXPower = result[(int)PACKET_CONF.COMM_POS_PAYLOAD + 3]; tTxt_BLEInfo.AppendText("BLE TX Power : " + BLETXPower); tTxt_BLEInfo.AppendText(Environment.NewLine); tTxt_BLETXPower.Text = BLETXPower.ToString(); /* * Read BLE Instrument ID */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_GET_BLE_INST_ID, ref err); if (err != ERROR_LIST.ERROR_NONE) { tTxt_BLEInfo.AppendText("ERROR - Read Instrument ID"); tTxt_BLEInfo.AppendText(Environment.NewLine); return; } string BLEInstID = BitConverter.ToString(QuattroProtocol.getResponseValueData(result)).Replace("-", ":"); tTxt_BLEInfo.AppendText("BLE Instrument Id : " + BLEInstID); tTxt_BLEInfo.AppendText(Environment.NewLine); tTxt_BLEInstID.Text = BLEInstID; }
private void readConfiguartion() { /* * Read Configuration */ INNCOM_CONF_LIST param = (INNCOM_CONF_LIST)tCmb_Param.SelectedItem; byte[] result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_CONFIG, DeviceConfiguration.configurationToByteArray(param), ref err, 300); if (err != ERROR_LIST.ERROR_NONE) { tTxt_Logs.AppendText("ERROR - Read Configurations"); tTxt_Logs.AppendText(Environment.NewLine); return; } int offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + 3; byte[] value = QuattroProtocol.getResponseValueData(result); int type = result[offset]; byte[] IDA = new byte[2]; Array.Copy(value, 0, IDA, 0, 2); string ID = BitConverter.ToString(IDA).Replace("-", string.Empty); byte[] ParamValue = new byte[value.Length - IDA.Length]; Array.Copy(value, IDA.Length, ParamValue, 0, value.Length - IDA.Length); string str = ""; switch (type) { case (int)PARAMETER_TYPE.PARAM_TYPE_STR: { str = Encoding.Default.GetString(ParamValue).Trim('\0'); break; }; case (int)PARAMETER_TYPE.PARAM_TYPE_U8: { str = (ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U8A: { str = Encoding.Default.GetString(ParamValue).Trim('\0'); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_S8: { str = Convert.ToSByte(ParamValue[0]).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U32: { if (ParamValue.Length < 4) { byte[] temp = new byte[4 - ParamValue.Length]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getU32FromByteA(ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_U16: { if (ParamValue.Length == 1) { byte[] temp = new byte[1]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getU16FromByteA(ParamValue, 0).ToString(); break; } case (int)PARAMETER_TYPE.PARAM_TYPE_F32: { if (ParamValue.Length < 4) { byte[] temp = new byte[4 - ParamValue.Length]; ParamValue = Utility.mergeByteArray(temp, ParamValue); } str = Utility.getF32FromByteA(ParamValue, 0).ToString(); break; } default: { str = BitConverter.ToString(ParamValue).Replace("-", string.Empty); break; } } tTxt_Logs.AppendText("Parameter ID : 0x" + ID + " , Value : " + str); tTxt_Logs.AppendText(Environment.NewLine); }
private string getDeviceVersion() { string str = ""; /* * Read Device SN */ byte[] result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_READ_DEVICE_SN, ref err); if (err != ERROR_LIST.ERROR_NONE) { MessageBox.Show("ERROR - Read Device SN"); return(null); } string DeviceSN = Encoding.Default.GetString(QuattroProtocol.getResponseValueData(result)).Trim('\0'); str += "DeviceSN : " + DeviceSN + ","; /* * Read SW Version */ result = QuattroProtocol.sendCommand(COMM_COMMAND_LIST.COMM_CMD_READ_SW_VERSION, ref err); if (err != ERROR_LIST.ERROR_NONE) { MessageBox.Show("ERROR - Read SW Version"); return(null); } int offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + 3; int major = result[offset]; int minor = result[offset + 1]; int built = Utility.getU16FromByteA(result, offset + 2); tTxt_FirmVersion.Text = major.ToString() + "." + minor.ToString() + "." + built.ToString(); str += "SW Version : " + major.ToString() + "." + minor.ToString() + "." + built.ToString() + ","; /* * Read EEPROM Version */ result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_EEPROM_VER, ref err); if (err != ERROR_LIST.ERROR_NONE) { MessageBox.Show("ERROR - Read EERPOM Version");; return(null); } byte E2PVer = result[(int)PACKET_CONF.COMM_POS_PAYLOAD + 3]; tTxt_SensorDataVersion.Text = E2PVer.ToString(); str += "EEPROM : " + E2PVer.ToString() + ","; /* * Read Output Type */ result = QuattroProtocol.sendCommand(INNCOM_COMMAND_LIST.COMM_CMD_READ_OUTPUT_DEVICE_TYPE, ref err); if (err != ERROR_LIST.ERROR_NONE) { MessageBox.Show("ERROR - Read Board SN"); return(null); } offset = (int)PACKET_CONF.COMM_POS_PAYLOAD + (int)PACKET_CONF.COMM_RESPONSE_SZ; int OutputType = result[offset]; int Relay = result[offset + 1]; int BLEModule = result[offset + 2]; if (OutputType == 0) { str += "OutPut Type : mA Output,"; } else { str += "OutPut Type : Modbus,"; } if (Relay == 0) { str += "Relay : Not Fitted,"; } else { str += "Relay : Fitted,"; } if (BLEModule == 0) { str += "BLE : Not Fitted"; } else { str += "BLE : Not Fitted"; } return(str); }