示例#1
0
        /// <summary>
        /// Test Solenoid procedure
        /// </summary>
        /// <returns></returns>
        private async Task <int> TestSolenoid()
        {
            for (int j = 0; j < 15; j++)
            {
                MessageFromUnit = "";
                MySerialPort.DiscardInBuffer();
                MySerialPort.WriteLine(DeviceCommand.HCM_TEST_SOLENOID);
                await DelayTime(500);

                MessageFromUnit = MySerialPort.ReadExisting();
                if (MessageFromUnit.Contains("HT-TESTS,180"))
                {
                    Solenoid        = true;
                    MessageFromUnit = MessageFromUnit.RemoveLineBreaks();
                    string[] temp = MessageFromUnit.Split(',');
                    SolenoidResult = Convert.ToInt32(temp[3]);
                    break;
                }
            }

            return(SolenoidResult);
        }
示例#2
0
        /// <summary>
        /// Get the information from the device once it is connected
        /// </summary>
        public async void Connect()
        {
            HCM = new Device();

            for (int j = 0; j < 15; j++)
            {
                MessageFromUnit = "";
                MySerialPort.DiscardInBuffer();
                MySerialPort.WriteLine(DeviceCommand.DEVICE_INFORMATION);
                await DelayTime(200);

                MessageFromUnit = MySerialPort.ReadExisting();
                string[] temp = MessageFromUnit.Split(',');
                if (temp.Length >= 6)
                {
                    if (MessageFromUnit.Contains("HT-DEVIC,001,HCM001"))
                    {
                        if (temp[3].Length == 9)
                        {
                            temp[3] = temp[3].Substring(1, 8);
                        }
                        HCM.SerialNumber     = temp[3];
                        HCM.RegistrationDate = RegistrationDate.GetRegistrationDate(temp[3]);
                        HCM.HardwareVersion  = temp[4];
                        HCM.FirmwareVersion  = temp[5].RemoveLineBreaks();
                        EnableButtons        = false;
                        break;
                    }
                }
            }


            if (!EnableButtons)
            {
                for (int j = 0; j < 5; j++)
                {
                    MySerialPort.DiscardInBuffer();
                    MySerialPort.DiscardOutBuffer();
                    MySerialPort.WriteLine(DeviceCommand.HCM_DATA_MODE);
                    await DelayTime(200);

                    MessageFromUnit = MySerialPort.ReadExisting();
                    if (MessageFromUnit.Contains("HT-CALIB,001"))
                    {
                        break;
                    }
                }

                for (int j = 0; j < 5; j++)
                {
                    MessageFromUnit = "";
                    MySerialPort.DiscardInBuffer();
                    MySerialPort.WriteLine("HT-DEVIC,060");
                    await DelayTime(200);

                    MessageFromUnit = MySerialPort.ReadExisting();
                    if (MessageFromUnit.Contains("HT-DEVIC,060"))
                    {
                        string[] temp = MessageFromUnit.Split(',');
                        HCM.MACAddress = (temp[2]).RemoveLineBreaks();
                        break;
                    }
                }

                for (int j = 0; j < 5; j++)
                {
                    MessageFromUnit = "";
                    MySerialPort.DiscardInBuffer();
                    MySerialPort.WriteLine("HT-DEVIC,056");
                    await DelayTime(200);

                    MessageFromUnit = MySerialPort.ReadExisting();
                    if (MessageFromUnit.Contains("HT-DEVIC,056"))
                    {
                        string[] temp = MessageFromUnit.Split(',');
                        temp[3]       = temp[3].RemoveLineBreaks();
                        HCM.BuildDate = temp[2] + " - " + temp[3];
                        break;
                    }
                }

                for (int j = 0; j < 5; j++)
                {
                    MessageFromUnit = "";
                    MySerialPort.DiscardInBuffer();
                    MySerialPort.WriteLine(DeviceCommand.HCM_GET_LAST_CALIBRATED_DATE);
                    await DelayTime(200);

                    MessageFromUnit = MySerialPort.ReadExisting();
                    if (MessageFromUnit.Contains("HT-CALIB,007"))
                    {
                        string[] temp = MessageFromUnit.Split(',');
                        HCM.LastCalibratedDate = temp[4] + "/" + temp[5] + "/20" + temp[3];
                        break;
                    }
                }

                for (int j = 0; j < 5; j++)
                {
                    MessageFromUnit = "";
                    MySerialPort.DiscardInBuffer();
                    MySerialPort.WriteLine(DeviceCommand.HCM_GET_NEXT_CALIBRATION_DATE);
                    await DelayTime(200);

                    MessageFromUnit = MySerialPort.ReadExisting();
                    if (MessageFromUnit.Contains("HT-CALIB,007"))
                    {
                        string[] temp = MessageFromUnit.Split(',');
                        HCM.NextCalibrationDate = temp[4] + "/" + temp[5] + "/20" + temp[3];
                        break;
                    }
                }

                HCM.BootloaderVersion = "1400";

                DisplayMessage("Completed", MessageTypeEnum.Info);
            }
            else
            {
                DisplayMessage("Cannot set device into data mode", MessageTypeEnum.Critical);
            }
        }