示例#1
0
        private J2534Status GetVersion()
        {
            J2534Status Status           = new J2534Status();
            IntPtr      pFirmwareVersion = Marshal.AllocHGlobal(80);
            IntPtr      pDllVersion      = Marshal.AllocHGlobal(80);
            IntPtr      pApiVersion      = Marshal.AllocHGlobal(80);

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.ReadVersion(DeviceID, pFirmwareVersion, pDllVersion, pApiVersion);

                if (Status.IsOK)
                {
                    FirmwareVersion = Marshal.PtrToStringAnsi(pFirmwareVersion);
                    LibraryVersion  = Marshal.PtrToStringAnsi(pDllVersion);
                    APIVersion      = Marshal.PtrToStringAnsi(pApiVersion);
                }
                else
                {
                    Status.Description = Library.GetLastError();
                    //No exception is thrown because this method is used as a 'Ping' and I don't
                    //want exceptions occuring just because a ping failed for any reason.
                }
                Marshal.FreeHGlobal(pFirmwareVersion);
                Marshal.FreeHGlobal(pDllVersion);
                Marshal.FreeHGlobal(pApiVersion);
            }
            return(Status);
        }
示例#2
0
        public int StartPeriodicMessage(PeriodicMsg PeriodicMessage)
        {
            J2534Status  Status    = new J2534Status();
            J2534HeapInt MessageID = new J2534HeapInt();

            J2534HeapMessage PeriodicMessageHeap = new J2534HeapMessage(ProtocolID,
                                                                        PeriodicMessage.Message.TxFlags,
                                                                        PeriodicMessage.Message.Data);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StartPeriodicMsg(ChannelID,
                                                                  PeriodicMessageHeap.Ptr,
                                                                  MessageID.Ptr,
                                                                  PeriodicMessage.Interval);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                PeriodicMessage.MessageID = MessageID;
                PeriodicMsgList.Add(PeriodicMessage);
            }
            return(PeriodicMsgList.IndexOf(PeriodicMessage));
        }
示例#3
0
        /// <summary>
        /// Starts a single message filter and if successful, adds it to the FilterList.
        /// </summary>
        /// <param name="Filter"></param>
        /// <returns>Returns false if successful</returns>
        public int StartMsgFilter(MessageFilter Filter)
        {
            J2534Status  Status   = new J2534Status();
            J2534HeapInt FilterID = new J2534HeapInt();

            J2534HeapMessage Mask        = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.Mask);
            J2534HeapMessage Pattern     = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.Pattern);
            J2534HeapMessage FlowControl = new J2534HeapMessage(ProtocolID, Filter.TxFlags, Filter.FlowControl);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StartMsgFilter(ChannelID,
                                                                (int)Filter.FilterType,
                                                                Mask.Ptr,
                                                                Pattern.Ptr,
                                                                Filter.FilterType == J2534FILTER.FLOW_CONTROL_FILTER ? FlowControl.Ptr : IntPtr.Zero,
                                                                FilterID.Ptr);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                filterlist.Add(Filter);
            }
            return(filterlist.IndexOf(Filter));
        }
示例#4
0
        public GetMessageResults MessageTransaction(List <J2534Message> TxMessages, int NumOfRxMsgs, Predicate <J2534Message> Comparer)
        {
            lock (MessageSieve) MessageSieve.AddScreen(10, Comparer);
            J2534Status Status = SendMessages(TxMessages);

            if (Status.IsOK)
            {
                return(GetMessages(NumOfRxMsgs, DefaultRxTimeout, Comparer, true));
            }
            throw new J2534Exception(Status);
        }
示例#5
0
        public GetMessageResults MessageTransaction(IEnumerable <byte> TxMessageData, int NumOfRxMsgs, Predicate <J2534Message> Comparer)
        {
            MessageSieve.AddScreen(10, Comparer);
            J2534Status Status = SendMessage(TxMessageData.ToArray());

            if (Status.IsOK)
            {
                return(GetMessages(NumOfRxMsgs, DefaultRxTimeout, Comparer, true));
            }
            throw new J2534Exception(Status);
        }
示例#6
0
        public void SetProgrammingVoltage(J2534PIN PinNumber, int Voltage)
        {
            J2534Status Status = new J2534Status();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.SetProgrammingVoltage(DeviceID, (int)PinNumber, Voltage);
                if (Status.IsNotOK)
                {
                    Status.Description = Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#7
0
        public void ClearFunctMsgLookupTable()
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.CLEAR_FUNCT_MSG_LOOKUP_TABLE, IntPtr.Zero, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#8
0
        internal J2534Status GetNextCarDAQ_RESET()
        {
            J2534Status Status = new J2534Status();

            lock (API_LOCK)
            {
                Status.Code = API.GetNextCarDAQ(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = GetLastError();
                }
            }
            return(Status);
        }
示例#9
0
        public void DisconnectDevice()
        {
            J2534Status Status = new J2534Status();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.Close(DeviceID);
                if (Status.IsNotOK)
                {
                    Status.Description = Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#10
0
        public void ClearMsgFilters()
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.CLEAR_MSG_FILTERS, IntPtr.Zero, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#11
0
        /// <summary>
        /// Stops the periodic message in 'PeriodicMsgList' referenced by 'Index'.
        /// </summary>
        /// <param name="Index"></param>
        /// <returns>Returns 'false' if successful</returns>
        public void StopPeriodicMsg(int Index)
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StopPeriodicMsg(ChannelID, PeriodicMsgList[Index].MessageID);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#12
0
        internal GetNextCarDAQResults GetNextCarDAQ()
        {
            J2534Status Status = new J2534Status();
            IntPtr      pName  = Marshal.AllocHGlobal(4);
            IntPtr      pAddr  = Marshal.AllocHGlobal(4);
            IntPtr      pVer   = Marshal.AllocHGlobal(4);

            lock (API_LOCK)
            {
                Status.Code = API.GetNextCarDAQ(pName, pVer, pAddr);


                if (Status.Code == J2534ERR.FUNCTION_NOT_ASSIGNED || Marshal.ReadIntPtr(pName) == IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pName);
                    Marshal.FreeHGlobal(pVer);
                    Marshal.FreeHGlobal(pAddr);
                    return(new GetNextCarDAQResults()
                    {
                        Exists = false
                    });
                }
                else if (Status.IsNotOK)
                {
                    Status.Description = GetLastError();
                    Marshal.FreeHGlobal(pName);
                    Marshal.FreeHGlobal(pVer);
                    Marshal.FreeHGlobal(pAddr);
                    throw new J2534Exception(Status);
                }

                byte[] b = new byte[3];
                Marshal.Copy(pVer, b, 0, 3);

                GetNextCarDAQResults Result = new GetNextCarDAQResults()
                {
                    Exists  = true,
                    Name    = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(pName)),
                    Version = string.Format("{2}.{1}.{0}", b[0], b[1], b[2]),
                    Address = Marshal.PtrToStringAnsi(Marshal.ReadIntPtr(pAddr))
                };

                Marshal.FreeHGlobal(pName);
                Marshal.FreeHGlobal(pAddr);
                Marshal.FreeHGlobal(pVer);

                return(Result);
            }
        }
示例#13
0
        public void AddToFunctMsgLookupTable(byte Addr)
        {
            J2534Status    Status     = new J2534Status();
            HeapSByteArray SByteArray = new HeapSByteArray(Addr);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.ADD_TO_FUNCT_MSG_LOOKUP_TABLE, SByteArray.Ptr, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#14
0
        public void SetConfig(List <SConfig> SConfig)
        {
            J2534Status      Status      = new J2534Status();
            HeapSConfigArray SConfigList = new HeapSConfigArray(SConfig);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.SET_CONFIG, SConfigList.Ptr, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#15
0
        /// <summary>
        /// Sends a single message 'Message'
        /// </summary>
        /// <param name="Message"></param>
        /// <returns>Returns 'false' if successful</returns>
        public J2534Status SendMessage(byte[] Message)
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                HeapMessageArray.InsertSingle(ProtocolID, DefaultTxFlag, Message);
                Status.Code = Device.Library.API.WriteMsgs(ChannelID, HeapMessageArray.Ptr, HeapMessageArray.Length.Ptr, DefaultTxTimeout);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                }
            }
            return(Status);
        }
示例#16
0
        public void StopMsgFilter(int Index)
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.StopMsgFilter(ChannelID, filterlist[Index].FilterId);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                filterlist.RemoveAt(Index);
            }
        }
示例#17
0
        /// <summary>
        /// Sends all messages contained in 'MsgList'
        /// </summary>
        /// <returns>Returns 'false' if successful</returns>
        public J2534Status SendMessages(J2534MessageList Messages)
        {
            J2534Status Status = new J2534Status();

            lock (Device.Library.API_LOCK)
            {
                HeapMessageArray.DeepCopy(Messages);
                Status.Code = Device.Library.API.WriteMsgs(ChannelID, HeapMessageArray.Ptr, HeapMessageArray.Length.Ptr, DefaultTxTimeout);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                }
            }
            return(Status);
        }
示例#18
0
        public void DeleteFromFunctMsgLookupTable(IEnumerable <byte> AddressList)
        {
            J2534Status    Status     = new J2534Status();
            HeapSByteArray SByteArray = new HeapSByteArray(AddressList.ToArray());

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE, SByteArray.Ptr, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
            }
        }
示例#19
0
        public int GetConfig(J2534PARAMETER Parameter)
        {
            J2534Status      Status       = new J2534Status();
            HeapSConfigArray SConfigArray = new HeapSConfigArray(new J2534.SConfig(Parameter, 0));

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.GET_CONFIG, SConfigArray.Ptr, IntPtr.Zero);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                return(SConfigArray[0].Value);
            }
        }
示例#20
0
        public int MeasureProgrammingVoltage()
        {
            J2534Status  Status  = new J2534Status();
            J2534HeapInt Voltage = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.IOCtl(DeviceID, (int)J2534IOCTL.READ_PROG_VOLTAGE, IntPtr.Zero, Voltage);
                if (Status.IsNotOK)
                {
                    Status.Description = Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                return(Voltage);
            }
        }
示例#21
0
        public byte[] FiveBaudInit(byte TargetAddress)
        {
            J2534Status    Status = new J2534Status();
            HeapSByteArray Input  = new HeapSByteArray(new byte[] { TargetAddress });
            HeapSByteArray Output = new HeapSByteArray(new byte[2]);

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.FIVE_BAUD_INIT, Input.Ptr, Output.Ptr);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                return(Output);
            }
        }
示例#22
0
        public J2534Message FastInit(J2534Message TxMessage)
        {
            J2534Status      Status = new J2534Status();
            J2534HeapMessage Input  = new J2534HeapMessage(ProtocolID, TxMessage.TxFlags, TxMessage.Data);
            J2534HeapMessage Output = new J2534HeapMessage();

            lock (Device.Library.API_LOCK)
            {
                Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.FAST_INIT, Input.Ptr, Output.Ptr);
                if (Status.IsNotOK)
                {
                    Status.Description = Device.Library.GetLastError();
                    throw new J2534Exception(Status);
                }
                return(Output);
            }
        }
示例#23
0
 public int MeasureBatteryVoltage()
 {
     if (Device.Library.API_Signature.SAE_API == SAE_API.V202_SIGNATURE)
     {
         J2534Status  Status  = new J2534Status();
         J2534HeapInt Voltage = new J2534HeapInt();
         lock (Device.Library.API_LOCK)
         {
             Status.Code = Device.Library.API.IOCtl(ChannelID, (int)J2534IOCTL.READ_VBATT, IntPtr.Zero, Voltage.Ptr);
             if (Status.IsNotOK)
             {
                 Status.Description = Device.Library.GetLastError();
                 throw new J2534Exception(Status);
             }
             return(Voltage);
         }
     }
     return(Device.MeasureBatteryVoltage());
 }
示例#24
0
        public J2534Status ConnectToDevice(string Device)
        {
            J2534Status Status = new J2534Status();

            IntPtr pDeviceName = IntPtr.Zero;

            if (!string.IsNullOrEmpty(Device))
            {
                pDeviceName = Marshal.StringToHGlobalAnsi(Device);
            }
            else
            {
                DeviceName = string.Format("Device {0}", J2534Discovery.PhysicalDevices.FindAll(Listed => Listed.Library == this.Library).Count + 1);
            }

            J2534HeapInt DeviceID = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.Open(pDeviceName, DeviceID);

                Marshal.FreeHGlobal(pDeviceName);

                if (Status.IsOK || (Library.API_Signature.SAE_API == SAE_API.V202_SIGNATURE &&
                                    J2534Discovery.PhysicalDevices.FindAll(Listed => Listed.Library == this.Library).Count == 0 &&
                                    IsConnected))
                {
                    this.DeviceID = DeviceID;
                    ValidDevice   = true;
                    Status.Code   = J2534ERR.STATUS_NOERROR;
                    GetVersion();
                }
                else
                {
                    Status.Description = Library.GetLastError();
                }
                return(Status);
            }
        }
示例#25
0
        public int MeasureBatteryVoltage()
        {
            J2534Status Status = new J2534Status();

            J2534HeapInt Voltage = new J2534HeapInt();

            lock (Library.API_LOCK)
            {
                Status.Code = Library.API.IOCtl(DeviceID, (int)J2534IOCTL.READ_VBATT, IntPtr.Zero, Voltage);
                if (Status.IsNotOK)
                {
                    Status.Description = Library.GetLastError();
                    throw new J2534Exception(Status);
                }

                //The return was kept inside the lock here to ensure the conversion to INT is done before the
                //lock is released.  This is in case the API reuses the Ptr location for this data on subsequent
                //calls.  In that case, two back to back calls could interfere with each other of the second
                //call is allowed to execute before the first call marshals the Int from the heap.
                return(Voltage);
            }
        }
示例#26
0
 public GetMessageResults(List <J2534Message> Messages, J2534Status Status)
 {
     this.Status   = Status;
     this.Messages = Messages;
 }
示例#27
0
 public GetMessageResults(J2534Status Status)
 {
     Messages    = new List <J2534Message>();
     this.Status = Status;
 }
示例#28
0
 public J2534Exception(J2534Status Status, string Message, Exception Inner) : base(Message, Inner)
 {
     this.Status = Status;
 }
示例#29
0
 public J2534Exception(J2534Status Status, string Message) : base(Message)
 {
     this.Status = Status;
 }
示例#30
0
 public J2534Exception(J2534Status Status)
 {
     this.Status = Status;
 }