Ejemplo n.º 1
0
 private void ThrowIfError(J2534Err status)
 {
     if (status != J2534Err.STATUS_NOERROR)
     {
         throw PassThruInterface.GetPassThruException();
     }
 }
Ejemplo n.º 2
0
        public int ReadBatteryVoltage()
        {
            int voltage = 0;
            var status  = PassThruInterface.ReadBatteryVoltage(DeviceId, ref voltage);

            return(voltage);
        }
Ejemplo n.º 3
0
        public void Disconnect()
        {
            if (Connected)
            {
                PassThruInterface.PassThruDisconnect(ChannelId);
            }

            Connected = false;
        }
Ejemplo n.º 4
0
        public void ClearRxBuffer()
        {
            if (!Connected)
            {
                throw new Exception("Pass thru device not connected");
            }

            PassThruInterface.ClearRxBuffer(channelId);
        }
Ejemplo n.º 5
0
        public unsafe void WriteMsgs(int timeout, params PassThruMsg[] msgs)
        {
            int numMsgs = 1;

            fixed(void *ptr = &msgs[0])
            {
                var status = PassThruInterface.PassThruWriteMsgs(channelId, new IntPtr(ptr), ref numMsgs, timeout);

                ThrowIfError(status);
            }
        }
Ejemplo n.º 6
0
        public void Connect()
        {
            if (!Opened)
            {
                throw new Exception("Pass thru device not opened");
            }
            var status = PassThruInterface.PassThruConnect(DeviceId, protocolID, ConnectFlag.CAN_29BIT_ID, BaudRate.CAN_500000, ref channelId);

            ThrowIfError(status);

            Connected = true;
        }
Ejemplo n.º 7
0
        public unsafe PassThruMsg[] ReadMsgs(int timeout, int numMsgs)
        {
            var msgs = new PassThruMsg[numMsgs];

            fixed(void *ptr = &msgs[0])
            {
                var status = PassThruInterface.PassThruReadMsgs(channelId, new IntPtr(ptr), ref numMsgs, timeout);

                ThrowIfError(status);
            }

            return(msgs);
        }
Ejemplo n.º 8
0
        public void Close()
        {
            if (Connected)
            {
                Disconnect();
            }

            if (Opened)
            {
                PassThruInterface.PassThruClose(DeviceId);
            }

            Opened = false;
        }
Ejemplo n.º 9
0
        public void Open()
        {
            var name = J2534Device.Name;
            var ptr  = Marshal.AllocHGlobal(name.Length);

            try
            {
                var status = PassThruInterface.PassThruOpen(J2534Device.Name, ref deviceId);

                ThrowIfError(status);

                Opened = true;
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
            }
        }
Ejemplo n.º 10
0
        public void ReadInfo()
        {
            if (!Connected)
            {
                throw new Exception("Pass thru device not connected");
            }

            var firmwareVersion = new StringBuilder(80);
            var dllVersion      = new StringBuilder(80);
            var apiVersion      = new StringBuilder(80);

            var status = PassThruInterface.PassThruReadVersion(DeviceId, firmwareVersion, dllVersion, apiVersion);

            FirmwareVersion = firmwareVersion.ToString();
            DllVersion      = dllVersion.ToString();
            ApiVersion      = apiVersion.ToString();

            ThrowIfError(status);
        }