Example #1
0
        /// <summary>
        /// Detects whether the meter is ON and connected to one of the COM ports
        /// </summary>
        /// <returns>Whether a meter was detected connected to the system</returns>
        bool autoDetectMeterCOMPort()
        {
            bool detected = false;

            string[] ports = SerialPort.GetPortNames();
            foreach (string portname in ports)
            {
                _meter = new MultiMeter(portname);
                try
                {
                    _meter.WaitForDsrHolding = false;
                    _meter.OpenComPort();
                    string idn = _meter.IDN();
                    _meter.CloseSerialPort();

                    if (idn.StartsWith("GWInstek,GDM8341"))
                    {
                        detected = true;
                        string msg = string.Format("Multimeter '{0}' communications port auto detected at {1}", idn.TrimEnd('\n'),
                                                   portname);
                        updateOutputStatus(msg);

                        break;
                    }
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                }
            }
            if (!detected)
            {
                string msg = string.Format("Unable to detect Multimeter communications port");
                updateOutputStatus(msg);
            }

            return(detected);
        }
Example #2
0
        /// <summary>
        /// Detects whether the meter is ON and connected to one of the COM ports
        /// If one is found, the serial port setting is changed automatically
        /// </summary>
        /// <returns>Whether a meter was detected connected to the system</returns>
        bool autoDetectMeterCOMPort()
        {
            bool detected = false;
            string[] ports = SerialPort.GetPortNames();
            foreach (string portname in ports)
            {
                MultiMeter meter = new MultiMeter(portname);
                try
                {
                    meter.WaitForDsrHolding = false;
                    meter.OpenComPort();
                    string idn = meter.IDN();
                    meter.CloseSerialPort();

                    if (
                        idn.StartsWith("HEWLETT-PACKARD,34401A") ||
                        idn.StartsWith("GWInstek,GDM8341")
                        )
                    {
                        detected = true;
                        Properties.Settings.Default.Meter_COM_Port_Name = portname;

                        Properties.Settings.Default.Meter_Manual_Measurement = false;
                        Properties.Settings.Default.PrePost_Test_Enabled = true;

                        Properties.Settings.Default.Save();
                        string msg = string.Format("Multimeter '{0}' communications port auto detected at {1}", idn.TrimEnd('\n'),
                            Properties.Settings.Default.Meter_COM_Port_Name);
                        updateOutputStatus(msg);
                        break;
                    }

                }
                catch (Exception ex)
                {
                    string msgx = ex.Message;
                }
                meter.CloseSerialPort();
            }
            if (!detected)
            {
                string msg = string.Format("Unable to detect Multimeter communications port. Using {0}.  Measurements set to manual mode",
                    Properties.Settings.Default.Meter_COM_Port_Name);

                Properties.Settings.Default.Meter_Manual_Measurement = true;
                Properties.Settings.Default.Save();

                updateOutputStatus(msg);
            }

            return detected;
        }