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); }
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)); }
/// <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)); }
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); }
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); }
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); } } }
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); } } }
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); }
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); } } }
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); } } }
/// <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); } } }
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); } }
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); } } }
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); } } }
/// <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); }
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); } }
/// <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); }
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); } } }
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); } }
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); } }
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); } }
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); } }
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()); }
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); } }
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); } }
public GetMessageResults(List <J2534Message> Messages, J2534Status Status) { this.Status = Status; this.Messages = Messages; }
public GetMessageResults(J2534Status Status) { Messages = new List <J2534Message>(); this.Status = Status; }
public J2534Exception(J2534Status Status, string Message, Exception Inner) : base(Message, Inner) { this.Status = Status; }
public J2534Exception(J2534Status Status, string Message) : base(Message) { this.Status = Status; }
public J2534Exception(J2534Status Status) { this.Status = Status; }