Ejemplo n.º 1
0
        private void cmdConnect_Click(object sender, EventArgs e)
        {
            bool failed = false;

            if (bConnected)
            {
                if (J1587inst != null)
                {
                    J1587inst = null;
                }
                if (J1939inst != null)
                {
                    J1939inst = null;
                }

                if (RxLogger != null)
                {
                    RxLogger.Close();
                }
                if (RxLogFileStream != null)
                {
                    RxLogFileStream.Close();
                }

                chkJ1587Enable.Enabled = true;
                chkJ1939Enable.Enabled = true;
                chkLogToFile.Enabled   = true;
                cmdConnect.Text        = "Connect";
                bConnected             = false;
                tmrJ1939.Enabled       = false;
            }
            else
            {
                if (chkLogToFile.Checked)
                {
                    SaveFileDialog newLogFile = new SaveFileDialog();

                    newLogFile.Filter           = "dgd files (*.dgd)|*.dgd|All files (*.*)|*.*";
                    newLogFile.FilterIndex      = 2;
                    newLogFile.RestoreDirectory = true;

                    if (newLogFile.ShowDialog() == DialogResult.OK)
                    {
                        if ((RxLogFileStream = newLogFile.OpenFile()) != null)
                        {
                            RxLogger = new StreamWriter(RxLogFileStream);
                        }
                    }
                }

                if (chkJ1939Enable.Checked)
                {
                    J1939inst = new RP121032(cmbDriverList.SelectedItem.ToString());
                    try
                    {
                        //J1939inst.RP1210_ClientConnect((short)150, new StringBuilder("J1939"), 0, 0, 0);
                        DeviceInfo selectedDevice = (DeviceInfo)cmbDeviceList.SelectedValue;
                        J1939inst.RP1210_ClientConnect(selectedDevice.DeviceId, new StringBuilder("J1939"), 0, 0, 0);
                        txtStatus.Text = "SUCCESS - UserDevice= " + J1939inst.nClientID;
                        try
                        {
                            J1939inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);

                            try
                            {
                                J1939AddressClaim();
                            }
                            catch (Exception err)
                            {
                                failed = true;
                                throw new Exception(err.Message);
                            }
                        }
                        catch (Exception err)
                        {
                            failed = true;
                            throw new Exception(err.Message);
                        }
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }
                }
                if (chkJ1587Enable.Checked)
                {
                    J1587inst = new RP121032(cmbDriverList.SelectedItem.ToString());
                    try
                    {
                        J1587inst.RP1210_ClientConnect((short)cmbDeviceList.SelectedItem, new StringBuilder("J1708"), 0, 0, 0);
                        txtStatus.Text = "SUCCESS - UserDevice= " + J1587inst.nClientID;
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }

                    try
                    {
                        J1587inst.RP1210_SendCommand(RP1210_Commands.RP1210_Set_All_Filters_States_to_Pass, new StringBuilder(""), 0);
                    }
                    catch (Exception err)
                    {
                        failed         = true;
                        txtStatus.Text = "FAILURE - " + err.Message;
                    }
                }

                if (!failed)
                {
                    chkJ1587Enable.Enabled = false;
                    chkJ1939Enable.Enabled = false;
                    chkLogToFile.Enabled   = false;
                    cmdConnect.Text        = "Disconnect";
                    bConnected             = true;
                    tmrJ1939.Enabled       = true;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads RP12010 Device Parameters from the driver specific INI file. This file is also located in the
        /// %SystemRoot% Directory with the rp121032.ini file.
        /// </summary>
        /// <param name="strDeviceIniPath"></param>
        /// <returns></returns>
        public static RP1210BDriverInfo LoadDeviceParameters(string strDeviceIniPath)
        {
            RP1210BDriverInfo driverInfo = new RP1210BDriverInfo();

            IniParser deviceIniParser = new IniParser(strDeviceIniPath);

            try
            {
                driverInfo.DriverVersion = deviceIniParser.GetSetting("VendorInformation", "Version");
            }
            catch
            {
                driverInfo.DriverVersion = "Unknown";
            }

            try
            {
                driverInfo.VendorName = deviceIniParser.GetSetting("VendorInformation", "Name");
            }
            catch
            {
                driverInfo.VendorName = "Unknown";
            }

            try
            {   //Should return A or B. We want B.
                driverInfo.RP1210Version = deviceIniParser.GetSetting("VendorInformation", "RP1210");
            }
            catch
            {   //Default to B and hope for the best.
                driverInfo.RP1210Version = "B";
            }

            try
            {   //Sets up the common timebase for the device
                driverInfo.TimestampWeight = Convert.ToInt16(deviceIniParser.GetSetting("VendorInformation", "TimestampWeight"));
            }
            catch
            {   //Assume a normal resolution if it is not specified
                driverInfo.TimestampWeight = 1000;
            }

            try
            {
                string strTemp = deviceIniParser.GetSetting("VendorInformation", "CANFormatsSupported");
                driverInfo.CANFormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x)));
            }
            catch
            {   // RP1210A Defaults
                driverInfo.CANFormatsSupported = new List <short>(new short[] { 4 });
            }

            try
            {   // RP1210A Defaults
                string strTemp = deviceIniParser.GetSetting("VendorInformation", "J1939FormatsSupported");
                driverInfo.J1939FormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x)));
            }
            catch
            {   // RP1210A Defaults
                driverInfo.J1939FormatsSupported = new List <short>(new short[] { 2 });
            }

            try
            {
                string strTemp = deviceIniParser.GetSetting("VendorInformation", "J1708FormatsSupported");
                driverInfo.J1708FormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x)));
            }
            catch
            {   // RP1210A Defaults
                driverInfo.J1708FormatsSupported = new List <short>(new short[] { 2 });
            }

            try
            {
                string strTemp = deviceIniParser.GetSetting("VendorInformation", "ISO15765FormatsSupported");
                driverInfo.CANFormatsSupported = new List <short>(Array.ConvertAll(strTemp.Split(new char[] { ',' }), x => Convert.ToInt16(x)));
            }
            catch
            {   // RP1210A Defaults
                driverInfo.ISO15765FormatsSupported = new List <short>(new short[] { 2 });
            }

            //Comma delimited list of device numbers
            string        strDevices  = deviceIniParser.GetSetting("VendorInformation", "Devices");
            List <string> listDevices = new List <string>(strDevices.Split(new char[] { ',' }));

            foreach (string temp in listDevices)
            {
                DeviceInfo devTemp = new DeviceInfo();
                devTemp.DeviceId          = Convert.ToInt16(deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceId"));
                devTemp.DeviceDescription = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceDescription");
                devTemp.DeviceName        = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceName");
                devTemp.DeviceParams      = deviceIniParser.GetSetting("DeviceInformation" + temp, "DeviceParams");
                driverInfo.RP1210Devices.Add(devTemp);
            }

            //Comma delimited list of supported protocols
            string        strProtocols  = deviceIniParser.GetSetting("VendorInformation", "Protocols");
            List <string> listProtocols = new List <string>(strProtocols.Split(new char[] { ',' }));

            foreach (string temp in listProtocols)
            {
                ProtocolInfo protoTemp = new ProtocolInfo();
                protoTemp.ProtocolString      = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolString");
                protoTemp.ProtocolDescription = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolDescription");
                protoTemp.ProtocolParams      = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolParams");
                try //Protocol speed isn't always defined
                {
                    string strProtoSpeeds = deviceIniParser.GetSetting("ProtocolInformation" + temp, "ProtocolSpeed");
                    protoTemp.ProtocolSpeed = new List <string>(strProtoSpeeds.Split(new char[] { ',' }));
                }
                catch
                {
                }

                string        strProtoDevs = deviceIniParser.GetSetting("ProtocolInformation" + temp, "Devices");
                List <string> devlistTemp  = new List <string>(strProtoDevs.Split(new char[] { ',' }));
                foreach (string devTemp in devlistTemp)
                {
                    driverInfo.RP1210Devices.Find(x => x.DeviceId == Convert.ToInt16(devTemp)).SupportedProtocols.Add(protoTemp);
                }
            }
            return(driverInfo);
        }