Exemple #1
0
        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.
        }
Exemple #2
0
        public void Read()
        {
            try
            {
                switch (GasSelection)
                {
                case Gas.Methane:
                    // Read from the appropriate sensor.
                    Port.WriteLine("TCd");
                    break;

                case Gas.Oxygen:
                    // Read from the appropriate sensor.
                    Port.WriteLine("1dd");
                    break;

                case Gas.CarbonMonoxide:
                    // Read from the appropriate sensor.
                    Port.WriteLine("2dd");
                    break;

                case Gas.HydrogenSulfide:
                    // Read from the appropriate sensor.
                    Port.WriteLine("3dd");
                    break;

                case Gas.HydrogenCyanide:
                    // Read from the appropriate sensor.
                    Port.WriteLine("4dd");
                    break;

                default:
                    throw new DeviceSettingNotSupportedException("Gas selection " + GasSelection.ToString() + " is not supported.");
                }

                // Read from the serial port.
                Thread.Sleep(200);
                string message = string.Empty;
                while (Port.BytesToRead != 0)
                {
                    message += Port.ReadExisting();
                }

                // Flush the port.
                Port.DiscardInBuffer();

                // Save the whole string as a message to be logged.
                // Replace any newlines or tabs with spaces to avoid weird log files.
                Message = Regex.Replace(message, @"\t|\n|\r", " ");
            }
            catch (InvalidOperationException ex)
            {
                throw new DevicePortException("Could not read from G3."
                                              + Environment.NewLine + ex.Message);
            }
            catch (TimeoutException ex)
            {
                throw new DeviceCommunicationException("No response from G3."
                                                       + Environment.NewLine + ex.Message);
            }
            catch (Exception ex) when(ex is FormatException || ex is IndexOutOfRangeException)
            {
                throw new DeviceCommunicationException("Invalid response from G3."
                                                       + Environment.NewLine + ex.Message);
            }
        }
Exemple #3
0
        public void Read()
        {
            try
            {
                switch (GasSelection)
                {
                case Gas.Methane:
                    // Read from the appropriate sensor.
                    _serialPort.Write("1dd");
                    break;

                case Gas.Oxygen:
                    // Read from the appropriate sensor.
                    _serialPort.Write("2dd");
                    break;

                case Gas.CarbonMonoxide:
                    // Read from the appropriate sensor.
                    _serialPort.Write("3dd");
                    break;

                case Gas.HydrogenSulfide:
                    // Read from the appropriate sensor.
                    _serialPort.Write("4dd");
                    break;

                case Gas.HydrogenCyanide:
                    // Read from the appropriate sensor.
                    _serialPort.Write("5dd");
                    break;

                default:
                    throw new DeviceSettingNotSupportedException("Gas selection " + GasSelection.ToString() + " is not supported.");
                }

                // Read from the serial port.
                Thread.Sleep(200);
                string message = string.Empty;
                while (_serialPort.BytesToRead != 0)
                {
                    message += _serialPort.ReadExisting();
                }

                // Flush the port.
                _serialPort.DiscardInBuffer();

                // Parse the string.
                string[] words = message.Split(' ');

                // Parse the reading.
                Readings[VariableType.GasConcentration] = Convert.ToDouble(words[4]);
            }
            catch (InvalidOperationException ex)
            {
                throw new DevicePortException("Could not read from G3."
                                              + Environment.NewLine + ex.Message);
            }
            catch (TimeoutException ex)
            {
                throw new DeviceCommunicationException("No response from G3."
                                                       + Environment.NewLine + ex.Message);
            }
            catch (Exception ex) when(ex is FormatException || ex is IndexOutOfRangeException)
            {
                throw new DeviceCommunicationException("Invalid response from G3."
                                                       + Environment.NewLine + ex.Message);
            }
        }