Exemple #1
0
        private Loader()
        {
            AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            j2534library = new J2534Extended();

            var list = J2534Detect.ListDevices();

            j2534Device = list.FirstOrDefault(d => d.Name == Config.Instance.DeviceName);
            if (j2534Device == null)
            {
                if (list.Count == 1)
                {
                    j2534Device = list.Single();
                }
                else
                {
                    var sd = new SelectDevice();
                    if (sd.ShowDialog() == DialogResult.OK)
                    {
                        j2534Device = sd.Device;
                    }
                }
            }

            j2534library.LoadLibrary(j2534Device);
        }
Exemple #2
0
        private Loader()
        {
            AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            j2534library = new J2534Extended();

            var list = J2534Detect.ListDevices();

            if (list.Count == 1)
            {
                j2534Device = list.Single();
            }
            else
            {
                var sd = new SelectDevice();
                if (sd.ShowDialog() == DialogResult.OK)
                {
                    j2534Device = sd.Device;
                }
                else
                {
                    return;
                }
            }

            j2534library.LoadLibrary(j2534Device);
        }
Exemple #3
0
        /*
         *  Example 1:
         *      Detect J2534 devices
         *
         */
        private void CmdDetectDevicesClick(object sender, EventArgs e)
        {
            // Calling J2534.GetAvailableDevices() will return a list of installed J2534 devices
            List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices();

            if (availableJ2534Devices.Count == 0)
            {
                MessageBox.Show("Could not find any installed J2534 devices.");
                return;
            }

            foreach (J2534Device device in availableJ2534Devices)
            {
                txtDevices.Text += device.Name + ", " + device.Vendor + "\r\n\r\n";
                txtDevices.Text += "\tConfig Application:\t" + device.ConfigApplication + "\r\n";
                txtDevices.Text += "\tFunction Library:\t" + device.FunctionLibrary + "\r\n\r\n";
                txtDevices.Text += "\tProtocol\t\tChannels\r\n";
                txtDevices.Text += "\tCAN\t\t" + device.CANChannels + "\r\n";
                txtDevices.Text += "\tISO15765\t" + device.ISO15765Channels + "\r\n";
                txtDevices.Text += "\tISO14230\t" + device.ISO14230Channels + "\r\n";
                txtDevices.Text += "\tISO9141\t\t" + device.ISO9141Channels + "\r\n";
                txtDevices.Text += "\tJ1850PWM\t" + device.J1850PWMChannels + "\r\n";
                txtDevices.Text += "\tJ1850PWM\t" + device.J1850VPWChannels + "\r\n";
                txtDevices.Text += "\tSCI_A_ENGINE\t" + device.SCI_A_ENGINEChannels + "\r\n";
                txtDevices.Text += "\tSCI_A_TRANS\t" + device.SCI_A_TRANSChannels + "\r\n";
                txtDevices.Text += "\tSCI_B_ENGINE\t" + device.SCI_B_ENGINEChannels + "\r\n";
                txtDevices.Text += "\tSCI_B_TRANS\t" + device.SCI_B_TRANSChannels + "\r\n\r\n";
            }
        }
Exemple #4
0
        /*
         *
         *  Use the J2534 protocol to read voltage
         *
         */
        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";
        }
Exemple #5
0
 public SuitableJ2534Devices()
 {
     foreach (J2534Device Dev in J2534Detect.ListDevices())
     {
         if (Dev.IsDiCECompatible)
         {
             DiCEDevicesList.Add(Dev);
         }
         //DiCEDevicesList.Add(Dev);
     }
 }
Exemple #6
0
        private static void InitUnity()
        {
            Console.WriteLine("Find PassThru devices:");
            var passThruDevices = J2534Detect.ListDevices();

            passThruDevices.ForEach(device => Console.Write(device.ToString() + " "));
            Console.WriteLine();

            unityContainer = new UnityContainer();
            unityContainer.RegisterInstance(passThruDevices.Last());
            unityContainer.RegisterInstance <IUnityContainer>(unityContainer);

            unityContainer.RegisterType <EsPassThruDevice>();
            unityContainer.RegisterType <EsDiagnosticModule>();
            unityContainer.RegisterType <ILoggerFacade, DebugLogger>();
        }
Exemple #7
0
        public bool Connect()
        {
            // Find all of the installed J2534 passthru devices
            List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices();

            J2534Device j2534Device;
            var         sd = new SelectDevice();

            if (sd.ShowDialog() == DialogResult.OK)
            {
                j2534Device = sd.Device;
            }
            else
            {
                return(false);
            }

            // We will always choose the first J2534 device in the list, if there are multiple devices
            //   installed, you should do something more intelligent.
            m_j2534Interface.LoadLibrary(j2534Device);

            // Attempt to open a communication link with the pass thru device
            int deviceId = 0;

            m_status = m_j2534Interface.PassThruOpen(IntPtr.Zero, ref deviceId);

            if (m_status != J2534Err.STATUS_NOERROR)
            {
                return(false);
            }

            if (ConnectSWCan(deviceId, ref m_swChannelId) && ConnectDWCan(deviceId, ref m_dwChannelId))
            {
                m_isConnected = true;
                SetNullFilters(m_swChannelId, m_dwChannelId);
                return(true);
            }

            return(false);
        }
Exemple #8
0
        private void CmdReadVinClick(object sender, EventArgs e)
        {
            J2534Extended passThru = new J2534Extended();
            string        vin      = "";

            // 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;
            }

            // We will always choose the first J2534 device in the list, if there are multiple devices
            //   installed, you should do something more intelligent.
            passThru.LoadLibrary(availableJ2534Devices[0]);

            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.GetVin(ref vin))
            {
                MessageBox.Show(String.Format("Error reading VIN.  Error: {0}", comm.GetLastError()));
                comm.Disconnect();
                return;
            }
            comm.Disconnect();

            // When we are done with the device, we can free the library.
            passThru.FreeLibrary();
            txtReadVin.Text = vin;
        }
Exemple #9
0
        public static new string[] GetAdapterNames()
        {
            // Find all of the installed J2534 passthru devices
            availableJ2534Devices = J2534Detect.ListDevices();

            // List available devices
            string[]      all   = new string[availableJ2534Devices.Count];
            List <string> names = new List <string>();

            for (int i = 0; i < availableJ2534Devices.Count; i++)
            {
                if (availableJ2534Devices[i].IsCANSupported)
                {
                    names.Add(availableJ2534Devices[i].Name);
                    logger.Debug(String.Format("Found device with CAN support {0}", availableJ2534Devices[i].Name));
                }
                else
                {
                    logger.Debug(String.Format("Skipped device without CAN support {0}", availableJ2534Devices[i].Name));
                }
            }
            return(names.ToArray());
        }
 public static List <J2534Device> GetAvailableDevices()
 {
     return(J2534Detect.ListDevices());
 }
Exemple #11
0
        /*
         *
         *  Example 2:
         *      Use the J2534 protocol to send and receive a message (w/o error checking)
         *
         */
        private void SendReceiveNoErrorChecking(object sender, EventArgs e)
        {
            J2534Extended passThru = new J2534Extended();

            // Find all of the installed J2534 passthru devices
            List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices();

            J2534Device j2534Device;
            var         sd = new SelectDevice();

            if (sd.ShowDialog() == DialogResult.OK)
            {
                j2534Device = sd.Device;
            }
            else
            {
                return;
            }

            // We will always choose the first J2534 device in the list, if there are multiple devices
            //   installed, you should do something more intelligent.
            passThru.LoadLibrary(j2534Device);

            // Attempt to open a communication link with the pass thru device
            int deviceId = 0;

            passThru.PassThruOpen(IntPtr.Zero, ref deviceId);

            // Open a new channel configured for ISO15765 (CAN)
            int channelId = 0;

            passThru.PassThruConnect(deviceId, ProtocolID.ISO15765, ConnectFlag.NONE, BaudRate.ISO15765, ref channelId);

            // Set up a message filter to watch for response messages
            int         filterId = 0;
            PassThruMsg maskMsg  = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0xff, 0xff, 0xff, 0xff });
            PassThruMsg patternMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xE8 });
            PassThruMsg flowControlMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xE0 });

            IntPtr maskMsgPtr        = maskMsg.ToIntPtr();
            IntPtr patternMsgPtr     = patternMsg.ToIntPtr();
            IntPtr flowControlMsgPtr = flowControlMsg.ToIntPtr();

            passThru.PassThruStartMsgFilter(channelId, FilterType.FLOW_CONTROL_FILTER, maskMsgPtr, patternMsgPtr, flowControlMsgPtr, ref filterId);

            // Clear out the response buffer so we know we're getting the freshest possible data
            passThru.ClearRxBuffer(channelId);

            // Finally we can send the message!
            PassThruMsg txMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xdf, 0x01, 0x00 });
            var txMsgPtr = txMsg.ToIntPtr();
            int numMsgs  = 1;

            passThru.PassThruWriteMsgs(channelId, txMsgPtr, ref numMsgs, 50);

            // Read messages in a loop until we either timeout or we receive data
            numMsgs = 1;
            IntPtr   rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs);
            J2534Err status = J2534Err.STATUS_NOERROR;

            while (J2534Err.STATUS_NOERROR == status)
            {
                status = passThru.PassThruReadMsgs(channelId, rxMsgs, ref numMsgs, 200);
            }

            // If we received data, we want to extract the data of interest.  I'm removing the reflection of the transmitted message.
            if ((J2534Err.ERR_BUFFER_EMPTY == status || J2534Err.ERR_TIMEOUT == status) && numMsgs > 0)
            {
                foreach (PassThruMsg msg in rxMsgs.AsList <PassThruMsg>(numMsgs))
                {
                    //
                    //
                    // Now do something with the data!
                    //
                    //
                }
            }


            // Disconnect this channel
            passThru.PassThruDisconnect(channelId);

            // When we are done with the device, we can free the library.
            passThru.FreeLibrary();
        }
Exemple #12
0
 private void SelectDevice_Load(object sender, EventArgs e)
 {
     deviceList.DataSource    = J2534Detect.ListDevices();
     deviceList.DisplayMember = "Name";
 }
Exemple #13
0
        /*
         *
         *  Example 2:
         *      Use the J2534 protocol to send and receive a message (w/o error checking)
         *
         */
        private void SendReceiveNoErrorChecking(object sender, EventArgs e)
        {
            J2534 passThru = new J2534();

            // Find all of the installed J2534 passthru devices
            List <J2534Device> availableJ2534Devices = J2534Detect.ListDevices();

            // We will always choose the first J2534 device in the list, if there are multiple devices
            //   installed, you should do something more intelligent.
            passThru.LoadLibrary(availableJ2534Devices[0]);

            // Attempt to open a communication link with the pass thru device
            int deviceId = 0;

            passThru.Open(ref deviceId);

            // Open a new channel configured for ISO15765 (CAN)
            int channelId = 0;

            passThru.Connect(deviceId, ProtocolID.ISO15765, ConnectFlag.NONE, BaudRate.ISO15765, ref channelId);

            // Set up a message filter to watch for response messages
            int         filterId = 0;
            PassThruMsg maskMsg  = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0xff, 0xff, 0xff, 0xff });
            PassThruMsg patternMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xE8 });
            PassThruMsg flowControlMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xE0 });

            passThru.StartMsgFilter(channelId, FilterType.FLOW_CONTROL_FILTER, ref maskMsg, ref patternMsg, ref flowControlMsg, ref filterId);

            // Clear out the response buffer so we know we're getting the freshest possible data
            passThru.ClearRxBuffer(channelId);

            // Finally we can send the message!
            PassThruMsg txMsg = new PassThruMsg(
                ProtocolID.ISO15765,
                TxFlag.ISO15765_FRAME_PAD,
                new byte[] { 0x00, 0x00, 0x07, 0xdf, 0x01, 0x00 });
            int numMsgs = 1;

            passThru.WriteMsgs(channelId, ref txMsg, ref numMsgs, 50);

            // Read messages in a loop until we either timeout or we receive data
            List <PassThruMsg> rxMsgs = new List <PassThruMsg>();
            J2534Err           status = J2534Err.STATUS_NOERROR;

            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == status)
            {
                status = passThru.ReadMsgs(channelId, ref rxMsgs, ref numMsgs, 200);
            }

            // If we received data, we want to extract the data of interest.  I'm removing the reflection of the transmitted message.
            List <byte> responseData;

            if ((J2534Err.ERR_BUFFER_EMPTY == status || J2534Err.ERR_TIMEOUT == status) && rxMsgs.Count > 1)
            {
                responseData = rxMsgs[rxMsgs.Count - 1].Data.ToList();
                responseData.RemoveRange(0, txMsg.Data.Length);
            }

            //
            //
            // Now do something with the data!
            //
            //

            // Disconnect this channel
            passThru.Disconnect(channelId);

            // When we are done with the device, we can free the library.
            passThru.FreeLibrary();
        }
Exemple #14
0
        bool LoadJ2534()
        {
            if (_passThru == null)
            {
                _passThru = new J2534Extended();
            }
            if (_passThru.IsLoaded)
            {
                return(true);
            }
            J2534Device j2534Device;

            // 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 in the Windows registry, have you installed the device drivers for your cable?");
                _passThru.FreeLibrary();
                return(false);
            }

            if (autoDetectCheckBox.Checked)
            {
                foreach (var lib in availableJ2534Devices)
                {
                    if (Path.GetFileName(lib.FunctionLibrary).Contains("J2534DotNet.Logger.dll"))
                    {
                        continue;
                    }
                    try {
                        j2534Device = new J2534Device();
                        if (!_passThru.LoadLibrary(lib))
                        {
                            j2534Device = null;
                            continue;
                        }

                        _comm = new UDSFord(_passThru);
                        _comm.Connect();

                        //if we get this far then we have successfully connected
                        _comm.Disconnect();
                        return(true);
                    } catch {
                        j2534Device = null;
                        continue;
                    }
                }
                _passThru.FreeLibrary();
                return(false);
            }

            if (checkBoxLogJ2534.Checked)
            {
                j2534Device = new J2534Device();
                j2534Device.FunctionLibrary = System.IO.Directory.GetCurrentDirectory() + "\\" + "J2534DotNet.Logger.dll";
                Thread.Sleep(10);
                var loaded = _passThru.LoadLibrary(j2534Device);
                if (!loaded)
                {
                    _passThru.FreeLibrary();
                }
                return(loaded);
            }

            //If there is only one DLL to choose from then load it
            if (availableJ2534Devices.Count == 1)
            {
                return(_passThru.LoadLibrary(availableJ2534Devices[0]));
            }
            else
            {
                var sd = new SelectDevice();
                if (sd.ShowDialog() == DialogResult.OK)
                {
                    j2534Device = sd.Device;
                    var loaded = _passThru.LoadLibrary(j2534Device);
                    if (!loaded)
                    {
                        _passThru.FreeLibrary();
                    }
                    return(loaded);
                }
            }

            return(false);
        }