public void Read() { // Read sensor data from instrument. string message = TrySendingCommand(CreateMessage(CMDS.GET_LIVE_DATA)); // Parse the response. G2StatusInfo g2StatusInfo = AnalyzeLiveData(message); switch (GasSelection) { case Gas.Methane: // TODO: Parse the response. //Readings[VariableType.GasConcentration] = g2StatusInfo.SensorLiveData[0].Reading; break; case Gas.Oxygen: // TODO: Parse the response. //Readings[VariableType.GasConcentration] = g2StatusInfo.SensorLiveData[1].Reading; break; default: throw new DeviceSettingNotSupportedException("Gas selection " + GasSelection.ToString() + " is not supported."); } // TODO: Parse the reading and add it to the response queue. }
private G2StatusInfo AnalyzeLiveData(string message) { // Split the string using commas to separate each word. char[] separators = new char[] { ',', '*', '\n' }; string[] words = message.Split(separators, StringSplitOptions.RemoveEmptyEntries); int max_values = words.GetUpperBound(0); int i = 2; // str[0] = "$#" // str[1] = CMD.GET_INSTRUMENT_INFO G2StatusInfo g2Status = new G2StatusInfo(); g2Status.DeviceState = (DEVICE_STATE)ushort.Parse(words[i++]); g2Status.SensorState = (SENSOR_STATE)ushort.Parse(words[i++]); g2Status.DeviceMode = (DEVICE_MODE)ushort.Parse(words[i++]); g2Status.CalibrationDue = Convert.ToBoolean(int.Parse(words[i++])); g2Status.BatteryLow = Convert.ToBoolean(int.Parse(words[i++])); g2Status.TickState = (TICK_STATE)ushort.Parse(words[i++]); // For each sensor in the instrument... for (int j = 0; j < 4; j++) { if (i >= max_values - 1) { break; } G2SensorReading sr = new G2SensorReading(); sr.SensorID = (SENSOR_ID)ushort.Parse(words[i++]); sr.Reading = int.Parse(words[i++]); sr.UnitOfMeasure = (UNIT)ushort.Parse(words[i++]); sr.SensorState = (SENSOR_STATE)ushort.Parse(words[i++]); sr.AlarmState = (ALARM_STATE)ushort.Parse(words[i++]); g2Status.SensorLiveData.Add(sr); } return(g2Status); }
private G2StatusInfo AnalyzeStatusInfo(string message) { // Split the string using commas to separate each word. char[] separators = new char[] { ',', '*', '\n' }; string[] words = message.Split(separators, StringSplitOptions.RemoveEmptyEntries); int i = 2; // str[0] = "$#" // str[1] = CMD.GET_INSTRUMENT_INFO G2StatusInfo g2Status = new G2StatusInfo(); if (words.Length >= i + 1) { g2Status.DeviceState = (DEVICE_STATE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.SensorState = (SENSOR_STATE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.DeviceMode = (DEVICE_MODE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.CalibrationDue = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.BatteryLow = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.TickState = (TICK_STATE)ushort.Parse(words[i++]); } return(g2Status); }
private G2StatusInfo AnalyzeInstrumentInfo(string message) { // Split the string using commas to separate each word. char[] separators = new char[] { ',', '*', '\n' }; string[] words = message.Split(separators, StringSplitOptions.RemoveEmptyEntries); int max_values = words.GetUpperBound(0); int i = 2; // words[0] = "$#" // words[1] = CMD.GET_INSTRUMENT_INFO G2StatusInfo g2Status = new G2StatusInfo(); if (words.Length >= i + 1) { g2Status.DeviceState = (DEVICE_STATE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.SensorState = (SENSOR_STATE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.DeviceMode = (DEVICE_MODE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.CalibrationDue = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.BatteryLow = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.TickState = (TICK_STATE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.ModelName = words[i++]; } if (words.Length >= i + 1) { g2Status.SerialNumber = ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.FirmwareRev = words[i++]; } if (words.Length >= i + 1) { g2Status.NatProMode = (TC_MODE)ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.LELEquivalent = ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.BarholeEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.LeakSearchEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.PurgeTestEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.COTestEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.CFTestEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.NSCEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.NSREnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.FlowBlockVisible = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.LELUnit = (LEL_UNIT)Enum.Parse(typeof(LEL_UNIT), words[i++]); //(LEL_MODE)UInt16.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.ExPPMRange = ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.LeakSearchPPM = ushort.Parse(words[i++]); } if (words.Length >= i + 1) { g2Status.SensorCount = ushort.Parse(words[i++]); } // For each sensor in the instrument... for (int j = 0; j < g2Status.SensorCount; j++) { if (i >= max_values - 1) { break; } if (words.Length < i + 4) { break; } G2SensorConfig sensorConfig = new G2SensorConfig { SensorID = (SENSOR_ID)ushort.Parse(words[i++]), LowAlarm = ushort.Parse(words[i++]), HighAlarm = ushort.Parse(words[i++]), MaxValue = ushort.Parse(words[i++]), }; g2Status.Sensors.Add(sensorConfig); } if (words.Length >= i + 1) { g2Status.WDPKTestEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.InertModeTestEnable = Convert.ToBoolean(int.Parse(words[i++])); } if (words.Length >= i + 1) { g2Status.StandbyEnable = Convert.ToBoolean(int.Parse(words[i++])); } #region "Firmware Version Specific Conditions" // Firmware versions greater than 2.02 contain CO test. // For versions less than this, consider the CO test disabled. if (Convert.ToDouble(g2Status.FirmwareRev) < 2.02) { g2Status.COTestEnable = g2Status.CFTestEnable = false; } #endregion return(g2Status); }