Example #1
0
 public void DeviceStatusReceived(DeviceStatus deviceStatus)
 {
     this.deviceStatus = deviceStatus;  // save the information locally
     this.PostDeviceStatusToUI(deviceStatus);
 }
Example #2
0
        public void UpdateDeviceStatus(DeviceStatus deviceStatus)
        {
            this.firmwareVersionLabel.Text = "v" + deviceStatus.versionMajor.ToString() +
                                             "." + deviceStatus.versionMinor.ToString() +
                                             "." + deviceStatus.versionBuild.ToString();
            this.dateLabel.Text = deviceStatus.dateMonth.ToString() + "/" +
                                  deviceStatus.dateDay.ToString() + "/" +
                                  deviceStatus.dateYear.ToString("00");
            this.timeLabel.Text = deviceStatus.timeHour.ToString() + ":" +
                                  deviceStatus.timeMin.ToString("00") + ":" +
                                  deviceStatus.timeSec.ToString("00");
            this.CurrentScreen     = deviceStatus.currentScreen;
            this.boardSerialNumber = deviceStatus.boardSerialNumber;

            // We're using the analog O2 sensor, which does not report pressure

            /*
             * if (deviceStatus.ambientPressure > 700)
             * {
             *  this.pressureAmbient.Text = deviceStatus.ambientPressure.ToString("N0");
             * } else
             * {
             *  this.pressureAmbient.Text = "N/C";
             *  this.pressureAmbient.BackColor = Color.LightGray;
             * }
             */
            this.o2Status = deviceStatus.o2Status.ToString();
            if (deviceStatus.o2Status == 0)
            {
                this.o2SensorAvg.BackColor          = Color.Red;
                this.o2SensorStatusDescription.Text = "Sensor Off";
            }
            else if (deviceStatus.o2Status == 1)
            {
                if (deviceStatus.o2CalibrationStatus == 1)
                {
                    this.o2SensorAvg.BackColor          = Color.LightYellow;
                    this.o2SensorStatusDescription.Text = "Calibrating O2...";
                }
                else if (deviceStatus.o2CalibrationStatus == 2)
                {
                    this.o2SensorAvg.BackColor          = Color.LightBlue;
                    this.o2SensorStatusDescription.Text = "Warming up, Calibration Complete";
                }
                else if (Convert.ToDouble(this.o2SensorAvg.Text) < 5.0)
                {
                    this.o2SensorAvg.BackColor          = Color.Yellow;
                    this.o2SensorStatusDescription.Text = "Warming Up";
                }
                else
                {
                    this.o2SensorAvg.BackColor          = Color.LightGreen;
                    this.o2SensorStatusDescription.Text = "Running";
                }
            }
            else if (deviceStatus.o2Status == 2)
            {
                if (deviceStatus.o2CalibrationStatus == 1)
                {
                    this.o2SensorAvg.BackColor          = Color.LightYellow;
                    this.o2SensorStatusDescription.Text = "Calibrating O2...";
                }
                else if (deviceStatus.o2CalibrationStatus == 2)
                {
                    this.o2SensorAvg.BackColor          = Color.LightBlue;
                    this.o2SensorStatusDescription.Text = "Running, Calibration Complete";
                }
                else
                {
                    this.o2SensorAvg.BackColor          = Color.Red;
                    this.o2SensorStatusDescription.Text = "Bad Sensor or Bad Interface Board - replace";
                }
            }
            else if (deviceStatus.o2Status == 3)
            {
                this.o2SensorAvg.BackColor          = Color.Red;
                this.o2SensorStatusDescription.Text = "Incorrect or damaged Sensor - replace";
            }
            this.BatteryCharge     = deviceStatus.batteryCharge;
            this.BatteryCurrent    = deviceStatus.batteryCurrent;
            this.batteryVolts.Text = deviceStatus.batteryVoltage.ToString("N1");
            this.lockScreenStatus  = deviceStatus.screenLockStatus;
            this.alarmMuteStatus   = deviceStatus.alarmMuteStatus;
        }
Example #3
0
        public void Run()
        { // endless loop
            byte[] readBuffer    = new byte[4];
            bool   clearBuffOnce = true;

            while (true)
            {
                if (this.connectionIsOpen)
                {
                    try
                    {
                        // After opening connection, discard whatever is in buffer
                        if (clearBuffOnce)
                        {
                            clearBuffOnce = false;
                            this.DiscardBytes();
                        }
                        // read one byte
                        int bytesRead = 0;
                        while (bytesRead == 0)
                        {
                            bytesRead = this.serialPort.Read(readBuffer, 0, 1);
                        }
                        char c = Convert.ToChar(readBuffer[0]);

                        switch (c)
                        {
                        // CR -- end of message from device
                        case '\r':
                            if ((this.deviceResponse != this.kDeviceReadyMsg) && (this.deviceResponse != "sendstatus") && (this.deviceResponse.Length > 1))
                            {
                                this.PublishDeviceResponse(this.deviceResponse);
                                if (this.deviceResponse.StartsWith(","))
                                {
                                    formVar.logData(this.deviceResponse);
                                }
                            }
                            this.deviceResponse        = "";
                            this.readingDeviceResponse = false;
                            break;

                        // newline -- ignore
                        case '\n':
                            break;

                        case '&':
                            if (this.readingDeviceResponse)
                            { // normal char inside device response
                                this.deviceResponse += c;
                            }
                            else
                            {
                                DeviceData deviceData = new DeviceData();

                                if (this.ParseDataStream(ref deviceData))
                                {
                                    this.PublishDataResponse(deviceData);
                                }
                            }
                            break;

                        case '!':
                            if (this.readingDeviceResponse)
                            { // normal char inside device response
                                this.deviceResponse += c;
                            }
                            else
                            {
                                DeviceStatus deviceStatus = new DeviceStatus();

                                if (this.ParseStatusStream(ref deviceStatus))
                                {
                                    this.PublishStatusResponse(deviceStatus);
                                }
                            }
                            break;

                        // normal character -- add to the device response
                        default:
                            //if the character is not printable (<=0x1F or > 0x7E) except tab 0x09 - then the entire deviceResponse is bogus
                            if (c != 0x09 && (c < 0x20 || c > 0x7E))
                            {
                                this.deviceResponse        = "";
                                this.readingDeviceResponse = false;
                            }
                            else
                            {
                                this.deviceResponse       += c;
                                this.readingDeviceResponse = true;
                            }
                            break;
                        }
                    }
                    // if a read error occurred, connection is probably dead; post error msg and close com port
                    catch (Exception e)
                    {
                        this.PublishEvent(Event.ReadFailure);
                        if (ErrorPrintsEnabled)
                        {
                            Console.WriteLine("Reader thread exception: " + e.Message);
                        }
                    }
                }
                else
                {
                    clearBuffOnce = true;
                    // communication not yet established -- wait and try again
                    Thread.Sleep(100);
                }
            }
        }