Exemplo n.º 1
0
        public bool ResetECU()
        {
            PassThruMsg txMsg = new PassThruMsg();
            int         timeout;
            var         value = new byte[0];

            txMsg.ProtocolID = ProtocolId;
            switch (ProtocolId)
            {
            case ProtocolID.ISO15765:
                txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;

                txMsg.SetBytes(new byte[] { 0, 0, 0x07, 0xE0, 0x11, 0x02, 0, 0 });

                timeout = 50;
                break;

            case ProtocolID.J1850PWM:
            case ProtocolID.J1850VPW:
            case ProtocolID.ISO9141:
            case ProtocolID.ISO14230:
            default:
                return(false);
            }

            J2534Interface.ClearRxBuffer(ChannelId);

            int numMsgs = 1;

            J2534Status = J2534Interface.PassThruWriteMsgs(ChannelId, txMsg.ToIntPtr(), ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != J2534Status)
            {
                return(false);
            }

            //Attempt to read at least 1 message as a reply
            List <PassThruMsg> messages;

            J2534Status = J2534Interface.ReadAllMessages(ChannelId, 1, _defaultTimeout, out messages, true);

            if (messages.Count <= 0)
            {
                return(false);
            }
            var response1 = messages[0].GetBytes();
            var response2 = messages[1].GetBytes();   //needs to respond with 00 00 07 e8 67 03 xx xx xx
            var code      = response2[6];

            if (response2[4] != 0x7F)
            {
                return(true);
            }
            return(false);
        }
Exemplo n.º 2
0
        private bool ReadObdPid(byte mode, byte pid, ProtocolID protocolId, ref List <byte> value)
        {
            PassThruMsg txMsg = new PassThruMsg();
            int         timeout;

            txMsg.ProtocolID = protocolId;
            switch (protocolId)
            {
            case ProtocolID.ISO15765:
                txMsg.TxFlags = TxFlag.ISO15765_FRAME_PAD;
                if (mode == 0x03 || mode == 0x04)
                {
                    txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode });
                }
                else
                {
                    txMsg.SetBytes(new byte[] { 0x00, 0x00, 0x07, 0xdf, mode, pid });
                }
                timeout = 50;
                break;

            case ProtocolID.J1850PWM:
            case ProtocolID.J1850VPW:
            case ProtocolID.ISO9141:
            case ProtocolID.ISO14230:
                byte protocolByte = (byte)((protocolId == ProtocolID.J1850PWM) ? 0x61 : 0x68);
                txMsg.TxFlags = TxFlag.NONE;
                txMsg.SetBytes(new byte[] { protocolByte, 0x6A, 0xF1, mode, pid });
                timeout = 100;
                break;

            default:
                return(false);
            }

            m_j2534Interface.ClearRxBuffer(m_channelId);

            int numMsgs = 1;

            m_status = m_j2534Interface.PassThruWriteMsgs(m_channelId, txMsg.ToIntPtr(), ref numMsgs, timeout);
            if (J2534Err.STATUS_NOERROR != m_status)
            {
                return(false);
            }

            IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)) * numMsgs);

            numMsgs = 1;
            while (J2534Err.STATUS_NOERROR == m_status)
            {
                m_status = m_j2534Interface.PassThruReadMsgs(m_channelId, rxMsgs, ref numMsgs, timeout * 4);
            }

            if (J2534Err.ERR_BUFFER_EMPTY == m_status || J2534Err.ERR_TIMEOUT == m_status)
            {
                if (numMsgs > 0)
                {
                    // Select the last value
                    PassThruMsg msg = rxMsgs.AsMsgList(numMsgs).Last();
                    value = msg.GetBytes().ToList();
                    value.RemoveRange(0, txMsg.GetBytes().Length);
                    return(true);
                }
                return(false);
            }
            return(false);
        }