Sample.Form1.CmdReadVoltageClick C# (CSharp) Method

CmdReadVoltageClick() private method

private CmdReadVoltageClick ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void CmdReadVoltageClick(object sender, EventArgs e)
        {
            J2534Extended passThru = null;// = Loader.Lib;
            double voltage = 0;

            // Find all of the installed J2534 passthru devices
            List<J2534Device> availableJ2534Devices = J2534Detect.ListDevices();
            if (availableJ2534Devices.Count == 0)
            {
                MessageBox.Show("Could not find any installed J2534 devices.");
                return;
            }

            ObdComm comm = new ObdComm(passThru);
            if (!comm.DetectProtocol())
            {
                MessageBox.Show(String.Format("Error connecting to device. Error: {0}", comm.GetLastError()));
                comm.Disconnect();
                return;
            }
            if (!comm.GetBatteryVoltage(ref voltage))
            {
                MessageBox.Show(String.Format("Error reading voltage.  Error: {0}", comm.GetLastError()));
                comm.Disconnect();
                return;
            }
            comm.Disconnect();

            // When we are done with the device, we can free the library.
            passThru.FreeLibrary();
            txtVoltage.Text = voltage + @" V";
        }