├── car-diagnostics-icon-01-.jpg
├── Src
├── Common
│ ├── EnumHelper.cs
│ ├── BoolInterlock.cs
│ ├── ManagedDisposable.cs
│ └── UnmanagedDisposable.cs
├── Definitions
│ ├── UserFilterType.cs
│ ├── DrewTech_API.cs
│ ├── Const.cs
│ ├── SAE_API.cs
│ ├── Filter.cs
│ ├── Pin.cs
│ ├── TxFlag.cs
│ ├── RxFlag.cs
│ ├── ConnectFlag.cs
│ ├── DeviceParameter.cs
│ ├── ProtocolInfo.cs
│ ├── IOCTL.cs
│ ├── Baud.cs
│ ├── Protocol.cs
│ ├── Parameter.cs
│ ├── DeviceInfo.cs
│ └── ResultCode.cs
├── Properties
│ └── AssemblyInfo.cs
├── DataClasses
│ ├── HeapSParamArray.cs
│ ├── GetMessageResults.cs
│ ├── HeapSConfigArray.cs
│ ├── APIInfo.cs
│ ├── GetNextCarDAQResults.cs
│ ├── PeriodicMessage.cs
│ ├── SConfig.cs
│ ├── HeapIntPtr.cs
│ ├── J2534Exception.cs
│ ├── SParam.cs
│ ├── HeapString.cs
│ ├── HeapInt.cs
│ ├── Message.cs
│ ├── API_Signature.cs
│ ├── HeapSByteArray.cs
│ ├── HeapStructArray.cs
│ ├── MessageFilter.cs
│ ├── HeapMessage.cs
│ └── HeapMessageArray.cs
├── NativeMethods.cs
├── API_GetDeviceList.cs
├── API_v202Shim.cs
├── Device.cs
├── J2534-Sharp.csproj
├── APIFactory.cs
├── API.cs
├── API_Prototypes.cs
├── API_Delegates.cs
└── Channel.cs
├── J2534-Sharp.nuspec
├── J2534-Sharp.sln
├── LICENSE.md
├── .gitignore
└── README.md
/car-diagnostics-icon-01-.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/BrianHumlicek/J2534-Sharp/HEAD/car-diagnostics-icon-01-.jpg
--------------------------------------------------------------------------------
/Src/Common/EnumHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Linq;
4 |
5 | namespace Common
6 | {
7 | public class EnumHelper
8 | {
9 | public static string GetTypeDescription(Enum enumeration)
10 | {
11 | var enumerationtype = enumeration.GetType();
12 | var attribute = enumerationtype.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
13 | return ((DescriptionAttribute)attribute)?.Description ?? enumerationtype.ToString();
14 | }
15 |
16 | public static string GetMemberDescription(Enum enumeration)
17 | {
18 | string enumerationString = enumeration.ToString();
19 | var member = enumeration.GetType().GetMember(enumerationString).First();
20 | var attribute = member.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
21 | return ((DescriptionAttribute)attribute)?.Description ?? enumerationString;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/J2534-Sharp.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | J2534-Sharp
5 | $version$
6 | SAE J2534 Library
7 | BrianHumlicek
8 | Brian Humlicek
9 | https://raw.githubusercontent.com/BrianHumlicek/J2534-Sharp/master/LICENSE.md
10 | https://github.com/BrianHumlicek/J2534-Sharp.git
11 | https://raw.githubusercontent.com/BrianHumlicek/J2534-Sharp/master/car-diagnostics-icon-01-.jpg
12 | false
13 | J2534-Sharp provides an easy solution to working with unmanaged SAE J2534 spec libraries. It handles the heavy lifting by wrapping the SAE library with a C# friendly API
14 |
15 | Copyright 2023 Brian Humlicek. All rights reserved.
16 | J2534 2534 OBD OBD-II SAE Diagnostics Drewtech
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Src/Definitions/UserFilterType.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 |
24 | namespace SAE.J2534
25 | {
26 | public enum UserFilterType
27 | {
28 | NONE,
29 | PASS,
30 | PASSALL,
31 | BLOCK,
32 | STANDARDISO15765
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/Src/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("J2534-Sharp")]
9 | [assembly: AssemblyDescription("J2534 Library for C#")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("J2534-Sharp")]
13 | [assembly: AssemblyCopyright("Copyright 2023 Brian Humlicek")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1a143d12-28ee-4762-ba42-876966bed8d2")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapSParamArray.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapSParamArray : HeapStructArray
29 | {
30 | HeapSParamArray(SParam SParam) : base(SParam)
31 | {
32 | }
33 | HeapSParamArray(SParam[] SParamList) : base(SParamList)
34 | {
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Src/Definitions/DrewTech_API.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace SAE.J2534
26 | {
27 | [Flags]
28 | public enum DrewTech_API
29 | {
30 | NONE = 0x00,
31 | GETNEXTCARDAQ = 0x01,
32 | GETPOINTER = 0x02,
33 | READPCSETUP = 0x04,
34 | WRITEIPSETUP = 0x08,
35 | READIPSETUP = 0x10,
36 | RECOVERFIRMWARE = 0x20,
37 | LOADFIRMWARE = 0x40
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Src/DataClasses/GetMessageResults.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 |
24 | namespace SAE.J2534
25 | {
26 | public class GetMessageResults
27 | {
28 | public ResultCode Result { get; }
29 | public Message[] Messages { get; }
30 |
31 | public GetMessageResults(Message[] Messages, ResultCode Result)
32 | {
33 | this.Result = Result;
34 | this.Messages = Messages;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Src/Definitions/Const.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 |
24 | namespace SAE.J2534
25 | {
26 | public static class CONST
27 | {
28 | public const int J2534MESSAGESIZE = 4152; //Max message length in bytes
29 | internal const int HEAPMESSAGEBUFFERSIZE = 200; //Max number of messages that can be passed to/from the API in a single call
30 | public static int MAX_MESSAGES { get { return HEAPMESSAGEBUFFERSIZE; } }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapSConfigArray.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapSConfigArray : HeapStructArray
29 | {
30 | public HeapSConfigArray(SConfig SConfig) : base(SConfig)
31 | {
32 | }
33 | public HeapSConfigArray(SConfig[] SConfigList) : base(SConfigList)
34 | {
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Src/DataClasses/APIInfo.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | namespace SAE.J2534
24 | {
25 | public class APIInfo
26 | {
27 | public string Name { get; }
28 | public string Filename { get; }
29 | public string Details { get; }
30 | public APIInfo(string Name, string Filename, string Details)
31 | {
32 | this.Name = Name;
33 | this.Filename = Filename;
34 | this.Details = Details;
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Src/DataClasses/GetNextCarDAQResults.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | namespace SAE.J2534
24 | {
25 | public class GetNextCarDAQResults
26 | {
27 | public GetNextCarDAQResults(string Name, string Version, string Address)
28 | {
29 | this.Name = Name;
30 | this.Version = Version;
31 | this.Address = Address;
32 | }
33 | public string Name { get; }
34 | public string Version { get; }
35 | public string Address { get; }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/Src/NativeMethods.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal static class Kernal32
29 | {
30 | [DllImport("kernel32.dll")]
31 | public static extern IntPtr LoadLibrary(string Library);
32 |
33 | [DllImport("kernel32.dll")]
34 | public static extern IntPtr GetProcAddress(IntPtr pLibrary, string FunctionName);
35 |
36 | [DllImport("kernel32.dll")]
37 | public static extern bool FreeLibrary(IntPtr pLibrary);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Src/DataClasses/PeriodicMessage.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 |
24 | namespace SAE.J2534
25 | {
26 | public class PeriodicMessage : Message
27 | {
28 | public int MessageID { get; set; }
29 | public int Interval { get; }
30 | public PeriodicMessage(int Interval, byte[] Data) : base(Data)
31 | {
32 | this.Interval = Interval;
33 | }
34 | public PeriodicMessage(int Interval, byte[] Data, TxFlag TxFlags) : base(Data, TxFlags)
35 | {
36 | this.Interval = Interval;
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Src/DataClasses/SConfig.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Runtime.InteropServices;
24 |
25 | namespace SAE.J2534
26 | {
27 | [StructLayout(LayoutKind.Explicit)]
28 | public struct SConfig
29 | {
30 | [FieldOffset(0), MarshalAs(UnmanagedType.U4)]
31 | public Parameter Parameter;
32 | [FieldOffset(4), MarshalAs(UnmanagedType.U4)]
33 | public int Value;
34 |
35 | public SConfig(Parameter Parameter, int Value)
36 | {
37 | this.Parameter = Parameter;
38 | this.Value = Value;
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapIntPtr.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapIntPtr : Common.UnmanagedDisposable
29 | {
30 | public IntPtr Ptr { get; }
31 | public HeapIntPtr()
32 | {
33 | Ptr = Marshal.AllocHGlobal(4);
34 | }
35 | public static explicit operator IntPtr(HeapIntPtr HeapIntPtr)
36 | {
37 | return Marshal.ReadIntPtr(HeapIntPtr.Ptr);
38 | }
39 | protected override void DisposeUnmanaged()
40 | {
41 | Marshal.FreeHGlobal(Ptr);
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/Src/DataClasses/J2534Exception.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace SAE.J2534
26 | {
27 | public class J2534Exception : Exception
28 | {
29 | public ResultCode Result { get; }
30 | public string GenericDescription { get; }
31 | public string SpecificDescription { get; }
32 | public override string Message { get; }
33 | public J2534Exception(ResultCode Result, string Message = "")
34 | {
35 | this.Result = Result;
36 | GenericDescription = this.Result.GetDescription();
37 | SpecificDescription = Message;
38 |
39 | this.Message = String.IsNullOrWhiteSpace(Message) ? GenericDescription : Message;
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/Src/DataClasses/SParam.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Runtime.InteropServices;
24 | namespace SAE.J2534
25 | {
26 | [StructLayout(LayoutKind.Explicit)]
27 | public struct SParam
28 | {
29 | [FieldOffset(0), MarshalAs(UnmanagedType.U4)]
30 | public DeviceInfo Parameter;
31 | [FieldOffset(4), MarshalAs(UnmanagedType.U4)]
32 | public int Value;
33 | [FieldOffset(8), MarshalAs(UnmanagedType.U4)]
34 | public int Supported;
35 |
36 | public SParam(DeviceInfo Parameter, int Value, int Supported)
37 | {
38 | this.Parameter = Parameter;
39 | this.Value = Value;
40 | this.Supported = Supported;
41 | }
42 | public int Length => 12;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/J2534-Sharp.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.30804.86
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "J2534-Sharp", "src\J2534-Sharp.csproj", "{D99E0DE7-2F06-41E3-B33E-687E1B425A7F}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5BEF19E0-D800-4ABD-A815-3A599C36E285}"
9 | ProjectSection(SolutionItems) = preProject
10 | J2534-Sharp.nuspec = J2534-Sharp.nuspec
11 | LICENSE.md = LICENSE.md
12 | README.md = README.md
13 | EndProjectSection
14 | EndProject
15 | Global
16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
17 | Debug|Any CPU = Debug|Any CPU
18 | Debug|x86 = Debug|x86
19 | Release|Any CPU = Release|Any CPU
20 | Release|x86 = Release|x86
21 | EndGlobalSection
22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
23 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Debug|Any CPU.Build.0 = Debug|Any CPU
25 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Debug|x86.ActiveCfg = Debug|Any CPU
26 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Debug|x86.Build.0 = Debug|Any CPU
27 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Release|Any CPU.ActiveCfg = Release|Any CPU
28 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Release|Any CPU.Build.0 = Release|Any CPU
29 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Release|x86.ActiveCfg = Release|Any CPU
30 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}.Release|x86.Build.0 = Release|Any CPU
31 | EndGlobalSection
32 | GlobalSection(SolutionProperties) = preSolution
33 | HideSolutionNode = FALSE
34 | EndGlobalSection
35 | GlobalSection(ExtensibilityGlobals) = postSolution
36 | SolutionGuid = {19363A5D-8DBB-4B03-B2EF-9B4E8FCC86D2}
37 | EndGlobalSection
38 | GlobalSection(ExtensibilityGlobals) = postSolution
39 | SolutionGuid = {19363A5D-8DBB-4B03-B2EF-9B4E8FCC86D2}
40 | EndGlobalSection
41 | EndGlobal
42 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapString.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapString : Common.UnmanagedDisposable
29 | {
30 | public IntPtr Ptr { get; }
31 | public HeapString(string Str)
32 | {
33 | Ptr = Marshal.StringToHGlobalAnsi(Str);
34 | }
35 | public HeapString(int Length)
36 | {
37 | Ptr = Marshal.AllocHGlobal(Length);
38 | }
39 | public override string ToString()
40 | {
41 | return Marshal.PtrToStringAnsi(Ptr);
42 | }
43 | public static explicit operator IntPtr(HeapString HeapString)
44 | {
45 | return HeapString.Ptr;
46 | }
47 | protected override void DisposeUnmanaged()
48 | {
49 | Marshal.FreeHGlobal(Ptr);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapInt.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapInt : Common.UnmanagedDisposable
29 | {
30 | public IntPtr Ptr { get; }
31 | public HeapInt()
32 | {
33 | Ptr = Marshal.AllocHGlobal(4);
34 | }
35 | public HeapInt(int i) : this()
36 | {
37 | Marshal.WriteInt32(Ptr, i);
38 | }
39 | public int Value
40 | {
41 | get { return Marshal.ReadInt32(Ptr); }
42 | set { Marshal.WriteInt32(Ptr, value); }
43 | }
44 | public static explicit operator IntPtr(HeapInt HeapIntPtr)
45 | {
46 | return HeapIntPtr.Ptr;
47 | }
48 | protected override void DisposeUnmanaged()
49 | {
50 | Marshal.FreeHGlobal(Ptr);
51 | }
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Src/DataClasses/Message.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 |
24 | namespace SAE.J2534
25 | {
26 | public class Message
27 | {
28 | public int FlagsAsInt { get; }
29 | public uint Timestamp { get; }
30 | //public int ExtraData { get; } //Not implemented.
31 | public byte[] Data { get; }
32 | public Message()
33 | {
34 | }
35 | public Message(byte[] Data, TxFlag TxFlags = TxFlag.NONE)
36 | {
37 | FlagsAsInt = (int)TxFlags;
38 | this.Data = Data;
39 | }
40 | public Message(byte[] Data, RxFlag RxFlags, uint Timestamp)
41 | {
42 | this.Data = Data;
43 | FlagsAsInt = (int)RxFlags;
44 | this.Timestamp = Timestamp;
45 | }
46 | public RxFlag RxStatus
47 | {
48 | get { return (RxFlag)FlagsAsInt; }
49 | }
50 | public TxFlag TxFlags
51 | {
52 | get { return (TxFlag)FlagsAsInt; }
53 | }
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/Src/Common/BoolInterlock.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Threading;
24 |
25 | namespace Common
26 | {
27 | public class BoolInterlock
28 | {
29 | private int state = States.Unlocked;
30 |
31 | public bool IsUnlocked
32 | {
33 | get { return state == States.Unlocked; }
34 | }
35 |
36 | public bool IsLocked
37 | {
38 | get { return state == States.Locked; }
39 | }
40 |
41 | public bool Enter()
42 | {
43 | //Set state to Locked, and return the original state
44 | return Interlocked.Exchange(ref state, States.Locked) == States.Unlocked;
45 | }
46 | public void Exit()
47 | {
48 | state = States.Unlocked;
49 | }
50 | //Can't be an Enum due to being passed by ref in the Exchange() method
51 | private static class States
52 | {
53 | public const int Unlocked = 0;
54 | public const int Locked = 1;
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/Src/Definitions/SAE_API.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace SAE.J2534
26 | {
27 | [Flags]
28 | internal enum SAE_API
29 | {
30 | //2.02 calls
31 | NONE = 0x00000000,
32 | CONNECT = 0x00000001,
33 | DISCONNECT = 0x00000002,
34 | READMSGS = 0x00000004,
35 | WRITEMSGS = 0x00000008,
36 | STARTPERIODICMSG = 0x00000010,
37 | STOPPERIODICMSG = 0x00000020,
38 | STARTMSGFILTER = 0x00000040,
39 | STOPMSGFILTER = 0x00000080,
40 | SETPROGRAMMINGVOLTAGE = 0x00000100,
41 | READVERSION = 0x00000200,
42 | GETLASTERROR = 0x00000400,
43 | IOCTL = 0x00000800,
44 | //4.04 calls
45 | OPEN = 0x00001000,
46 | CLOSE = 0x00002000,
47 | //5.00 calls
48 | SCANFORDEVICES = 0x00004000,
49 | GETNEXTDEVICE = 0x00008000,
50 | LOGICALCONNECT = 0x00010000,
51 | LOGICALDISCONNECT = 0x00020000,
52 | SELECT = 0x00040000,
53 | QUEUEMESSAGES = 0x00080000,
54 | //Signature matches
55 | V202_SIGNATURE = 0x0FFF,
56 | V404_SIGNATURE = 0x3FFF,
57 | V500_SIGNATURE = 0xFFFFF
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/Src/API_GetDeviceList.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Collections.Generic;
24 |
25 | namespace SAE.J2534
26 | {
27 | public partial class API
28 | {
29 | ///
30 | /// Gets a list of discoverable devices
31 | /// NOTE: Only supported by v5.00API or Drewtech
32 | ///
33 | ///
34 | public List GetDeviceList()
35 | {
36 | List result = new List();
37 | //Need to make some special sauce to get from registry here
38 | if (APISignature.SAE_API == SAE_API.V500_SIGNATURE)
39 | {
40 | throw new System.NotImplementedException("J2534 v5 support is not complete!");
41 | }
42 | else if (APISignature.DREWTECH_API.HasFlag(DrewTech_API.GETNEXTCARDAQ))
43 | {
44 | GetNextCarDAQ_RESET();
45 | for (GetNextCarDAQResults DrewtechDevice = GetNextCarDAQ();
46 | DrewtechDevice != null;
47 | DrewtechDevice = GetNextCarDAQ())
48 | {
49 | result.Add(DrewtechDevice.Name);
50 | }
51 |
52 | }
53 | return result;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Copyright(c) 2023, Brian Humlicek
2 | https://github.com/BrianHumlicek
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19 | SOFTWARE.
20 |
21 |
22 | Copyright (c) 2010, Michael Kelly
23 | michael.e.kelly@gmail.com
24 | http://michael-kelly.com/
25 |
26 | All rights reserved.
27 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
28 | Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
29 | Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
30 | Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
31 |
32 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
36 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43 |
--------------------------------------------------------------------------------
/Src/DataClasses/API_Signature.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Text;
24 |
25 | namespace SAE.J2534
26 | {
27 | internal class API_Signature
28 | {
29 | public API_Signature()
30 | {
31 | SAE_API = SAE_API.NONE;
32 | DREWTECH_API = DrewTech_API.NONE;
33 | }
34 | //This indicates what SAE standard API functions have been loaded
35 | public SAE_API SAE_API { get; set; }
36 | //This indicates if any drewtech specific API functions have been loaded
37 | public DrewTech_API DREWTECH_API { get; set; }
38 | public override string ToString()
39 | {
40 | StringBuilder API_String = new StringBuilder();
41 | if (DREWTECH_API != DrewTech_API.NONE)
42 | API_String.Append("DREWTECH ");
43 | else if (SAE_API != SAE_API.NONE)
44 | API_String.Append("SAE ");
45 | else
46 | API_String.Append("NO J2534 API DETECTED");
47 |
48 | switch (SAE_API)
49 | {
50 | case SAE_API.V202_SIGNATURE:
51 | API_String.Append("J2534 v2.02");
52 | break;
53 | case SAE_API.V404_SIGNATURE:
54 | API_String.Append("J2534 v4.04");
55 | break;
56 | case SAE_API.V500_SIGNATURE:
57 | API_String.Append("J2534 v5.00");
58 | break;
59 | default:
60 | API_String.Append("UNKNOWN API");
61 | break;
62 | }
63 | return API_String.ToString();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Src/Common/ManagedDisposable.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace Common
26 | {
27 | public abstract class ManagedDisposable : IDisposable
28 | {
29 | private BoolInterlock DisposalInterlock { get; } = new BoolInterlock();
30 |
31 | public delegate void OnDisposingPrototype();
32 | ///
33 | /// Event that fires immediately before object disposal occurs. Intended for long lived dependant object cleanup.
34 | ///
35 | public event OnDisposingPrototype OnDisposing;
36 |
37 | ///
38 | /// Returns true if Dispose() has been called
39 | ///
40 | public bool IsDisposed
41 | {
42 | get { return DisposalInterlock.IsLocked; }
43 | }
44 |
45 | ///
46 | /// Checks if Dispose() has been called, and throws an ObjectDisposedxException() if it has
47 | ///
48 | protected void CheckDisposed()
49 | {
50 | if (IsDisposed) throw new ObjectDisposedException(GetType().ToString());
51 | }
52 |
53 | ///
54 | /// Disposal implementation for managed objects should go in this method.
55 | ///
56 | protected abstract void DisposeManaged();
57 |
58 | protected void Dispose(bool Disposing)
59 | {
60 | if (DisposalInterlock.Enter())
61 | {
62 | CallDisposeMethods(Disposing);
63 | }
64 | }
65 |
66 | protected virtual void CallDisposeMethods(bool Disposing)
67 | {
68 | if (Disposing)
69 | {
70 | OnDisposing?.Invoke();
71 | DisposeManaged();
72 | }
73 | }
74 |
75 | public void Dispose()
76 | {
77 | Dispose(true);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Src/Definitions/Filter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | public enum Filter
51 | {
52 | PASS_FILTER = 0x01,
53 | BLOCK_FILTER = 0x02,
54 | FLOW_CONTROL_FILTER = 0x03
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapSByteArray.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal class HeapSByteArray : Common.UnmanagedDisposable
29 | {
30 | public IntPtr Ptr { get; }
31 | public HeapSByteArray(byte Byte)
32 | {
33 | Ptr = Marshal.AllocHGlobal(9);
34 | Length = 1;
35 | Marshal.WriteIntPtr(Ptr, 4, IntPtr.Add(Ptr, 8));
36 | Marshal.WriteByte(IntPtr.Add(Ptr, 8), Byte);
37 | }
38 | public HeapSByteArray(byte[] SByteArray)
39 | {
40 | Ptr = Marshal.AllocHGlobal(SByteArray.Length + 8);
41 | Length = SByteArray.Length;
42 | Marshal.WriteIntPtr(Ptr, 4, IntPtr.Add(Ptr, 8));
43 | Marshal.Copy(SByteArray, 0, IntPtr.Add(Ptr, 8), SByteArray.Length);
44 | }
45 | public int Length
46 | {
47 | get { return Marshal.ReadInt32(Ptr); }
48 | private set { Marshal.WriteInt32(Ptr, value); }
49 | }
50 |
51 | public byte this[int Index]
52 | {
53 | get
54 | {
55 | if (Index >= Length || Index < 0) throw new IndexOutOfRangeException("Index is greater than array bound");
56 | return Marshal.ReadByte(IntPtr.Add(Ptr, Index + 8));
57 | }
58 | }
59 | public byte[] ToSByteArray()
60 | {
61 | byte[] result = new byte[Length];
62 | Marshal.Copy(IntPtr.Add(Ptr, 8), result, 0, result.Length);
63 | return result;
64 |
65 | }
66 | public static explicit operator IntPtr(HeapSByteArray HeapSByteArray)
67 | {
68 | return HeapSByteArray.Ptr;
69 | }
70 | protected override void DisposeUnmanaged()
71 | {
72 | Marshal.FreeHGlobal(Ptr);
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/Src/Definitions/Pin.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | public enum Pin
51 | {
52 | AUX = 0,
53 | PIN_6 = 6,
54 | PIN_9 = 9,
55 | PIN_11 = 11,
56 | PIN_12 = 12,
57 | PIN_13 = 13,
58 | PIN_14 = 14,
59 | PIN_15 = 15
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/Src/API_v202Shim.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | public partial class API
29 | {
30 | private string shim_DeviceName = String.Empty;
31 | private int shim_DeviceID = 0;
32 | private bool shim_IsOpen = false;
33 | private ResultCode Open_shim(IntPtr pDeviceName, IntPtr pDeviceID)
34 | {
35 | string DeviceName = pDeviceName == IntPtr.Zero ? String.Empty : Marshal.PtrToStringAnsi(pDeviceName);
36 | if (!shim_IsOpen)
37 | {
38 | shim_DeviceName = DeviceName;
39 | shim_IsOpen = true;
40 | return ResultCode.STATUS_NOERROR;
41 | }
42 | if (shim_IsOpen && (DeviceName == this.shim_DeviceName)) return ResultCode.DEVICE_IN_USE;
43 |
44 | return ResultCode.INVALID_DEVICE_ID;
45 | }
46 |
47 | private ResultCode Close_shim(int DeviceID)
48 | {
49 | if (!shim_IsOpen || DeviceID != shim_DeviceID) return ResultCode.INVALID_DEVICE_ID;
50 | return ResultCode.STATUS_NOERROR;
51 | }
52 |
53 | private ResultCode Connect_shim(int DeviceID, int ProtocolID, int ConnectFlags, int Baud, IntPtr ChannelID)
54 | {
55 | if (DeviceID != shim_DeviceID) return ResultCode.INVALID_DEVICE_ID;
56 | return PTConnectv202(ProtocolID, ConnectFlags, ChannelID);
57 | }
58 |
59 | private ResultCode SetVoltage_shim(int DeviceID, int Pin, int Voltage)
60 | {
61 | if (DeviceID != shim_DeviceID) return ResultCode.INVALID_DEVICE_ID;
62 | return PTSetProgrammingVoltagev202(Pin, Voltage);
63 | }
64 |
65 | private ResultCode ReadVersion_shim(int DeviceID, IntPtr pFirmwareVer, IntPtr pDllVer, IntPtr pAPIVer)
66 | {
67 | if (DeviceID != shim_DeviceID) return ResultCode.INVALID_DEVICE_ID;
68 | return PTReadVersionv202(pFirmwareVer, pDllVer, pAPIVer);
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/Src/Definitions/TxFlag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 |
49 | namespace SAE.J2534
50 | {
51 | [Flags]
52 | public enum TxFlag
53 | {
54 | NONE = 0x00000000,
55 | SCI_TX_VOLTAGE = 0x00800000,
56 | SCI_MODE = 0x00400000,
57 | WAIT_P3_MIN_ONLY = 0x00000200,
58 | CAN_29BIT_ID = 0x00000100,
59 | ISO15765_ADDR_TYPE = 0x00000080,
60 | ISO15765_FRAME_PAD = 0x00000040
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Src/Definitions/RxFlag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 |
49 | namespace SAE.J2534
50 | {
51 | [Flags]
52 | public enum RxFlag
53 | {
54 | NONE = 0x00000000,
55 | TX_MSG_TYPE = 0x00000001,
56 | START_OF_MESSAGE = 0x00000002,
57 | RX_BREAK = 0x00000004,
58 | TX_INDICATION = 0x00000008,
59 | ISO15765_PADDING_ERROR = 0x00000010,
60 | ISO15765_EXT_ADDR = 0x00000080,
61 | CAN_29BIT_ID = 0x00000100
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/Src/Common/UnmanagedDisposable.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace Common
26 | {
27 | public abstract class UnmanagedDisposable : ManagedDisposable
28 | {
29 | ///
30 | /// Disposal implementation for managed objects should go in this method.
31 | ///
32 | protected override void DisposeManaged() { } //Optional implementation for the superclass
33 |
34 | ///
35 | /// Disposal implementation for unmanaged objects should go in this method.
36 | ///
37 | protected abstract void DisposeUnmanaged(); //Super class MUST implement this
38 |
39 | protected sealed override void CallDisposeMethods(bool Disposing)
40 | {
41 | base.CallDisposeMethods(Disposing); //Must dispose of managed objects first
42 | DisposeUnmanaged();
43 | if (Disposing)
44 | {
45 | GC.SuppressFinalize(this);
46 | }
47 | }
48 |
49 | ~UnmanagedDisposable()
50 | {
51 | try
52 | {
53 | Dispose(false);
54 | }
55 | catch (Exception exception)
56 | {
57 | //This is bad. At least attempt to get a log message out if this happens.
58 | try
59 | {
60 | System.Text.StringBuilder builder = new System.Text.StringBuilder();
61 | builder.AppendLine($"{DateTime.Now} - Exception in type '{GetType()}'");
62 | builder.Append(exception.StackTrace);
63 | builder.Append(exception.Message);
64 | var inner_exception = exception.InnerException;
65 | while (inner_exception != null)
66 | {
67 | builder.Append(inner_exception.Message);
68 | inner_exception = inner_exception.InnerException;
69 | }
70 | System.IO.File.AppendAllText(@"FinalizerException.txt", builder.ToString());
71 | }
72 | catch { } //Swallow any exceptions inside a finalizer
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Src/Definitions/ConnectFlag.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 |
49 | namespace SAE.J2534
50 | {
51 | [Flags]
52 | public enum ConnectFlag
53 | {
54 | NONE = 0x0000,
55 | CAN_29BIT_ID = 0x0100,
56 | ISO9141_NO_CHECKSUM = 0x0200,
57 | CAN_ID_BOTH = 0x0800,
58 | ISO9141_K_LINE_ONLY = 0x1000,
59 | DT_ISO9141_LISTEN_L_LINE = 0x08000000,
60 | SNIFF_MODE = 0x10000000, //Drewtech only
61 | ISO9141_FORD_HEADER = 0x20000000, //Drewtech only
62 | ISO9141_NO_CHECKSUM_DT = 0x40000000 //Drewtech only
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/Src/Definitions/DeviceParameter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | public enum DeviceParameter
51 | {
52 | NON_VOLATILE_STORE_1 = 0x0000C001,
53 | NON_VOLATILE_STORE_2 = 0x0000C002,
54 | NON_VOLATILE_STORE_3 = 0x0000C003,
55 | NON_VOLATILE_STORE_4 = 0x0000C004,
56 | NON_VOLATILE_STORE_5 = 0x0000C005,
57 | NON_VOLATILE_STORE_6 = 0x0000C006,
58 | NON_VOLATILE_STORE_7 = 0x0000C007,
59 | NON_VOLATILE_STORE_8 = 0x0000C008,
60 | NON_VOLATILE_STORE_9 = 0x0000C009,
61 | NON_VOLATILE_STORE_10 = 0x0000C00A
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #################
2 | ## Eclipse
3 | #################
4 |
5 | *.pydevproject
6 | .project
7 | .metadata
8 | bin/
9 | tmp/
10 | *.tmp
11 | *.bak
12 | *.swp
13 | *~.nib
14 | local.properties
15 | .classpath
16 | .settings/
17 | .loadpath
18 |
19 | # External tool builders
20 | .externalToolBuilders/
21 |
22 | # Locally stored "Eclipse launch configurations"
23 | *.launch
24 |
25 | # CDT-specific
26 | .cproject
27 |
28 | # PDT-specific
29 | .buildpath
30 |
31 |
32 | #################
33 | ## Visual Studio
34 | #################
35 |
36 | ## Ignore Visual Studio temporary files, build results, and
37 | ## files generated by popular Visual Studio add-ons.
38 |
39 | # User-specific files
40 | *.suo
41 | *.user
42 | *.sln.docstates
43 | .vs/
44 |
45 | # Build results
46 |
47 | [Dd]ebug/
48 | [Rr]elease/
49 | x64/
50 | build/
51 | [Bb]in/
52 | [Oo]bj/
53 |
54 | # MSTest test Results
55 | [Tt]est[Rr]esult*/
56 | [Bb]uild[Ll]og.*
57 |
58 | *_i.c
59 | *_p.c
60 | *.ilk
61 | *.meta
62 | *.obj
63 | *.pch
64 | *.pdb
65 | *.pgc
66 | *.pgd
67 | *.rsp
68 | *.sbr
69 | *.tlb
70 | *.tli
71 | *.tlh
72 | *.tmp
73 | *.tmp_proj
74 | *.log
75 | *.vspscc
76 | *.vssscc
77 | .builds
78 | *.pidb
79 | *.log
80 | *.scc
81 |
82 | # Visual C++ cache files
83 | ipch/
84 | *.aps
85 | *.ncb
86 | *.opensdf
87 | *.sdf
88 | *.cachefile
89 |
90 | # Visual Studio profiler
91 | *.psess
92 | *.vsp
93 | *.vspx
94 |
95 | # Guidance Automation Toolkit
96 | *.gpState
97 |
98 | # ReSharper is a .NET coding add-in
99 | _ReSharper*/
100 | *.[Rr]e[Ss]harper
101 |
102 | # TeamCity is a build add-in
103 | _TeamCity*
104 |
105 | # DotCover is a Code Coverage Tool
106 | *.dotCover
107 |
108 | # NCrunch
109 | *.ncrunch*
110 | .*crunch*.local.xml
111 |
112 | # Installshield output folder
113 | [Ee]xpress/
114 |
115 | # DocProject is a documentation generator add-in
116 | DocProject/buildhelp/
117 | DocProject/Help/*.HxT
118 | DocProject/Help/*.HxC
119 | DocProject/Help/*.hhc
120 | DocProject/Help/*.hhk
121 | DocProject/Help/*.hhp
122 | DocProject/Help/Html2
123 | DocProject/Help/html
124 |
125 | # Click-Once directory
126 | publish/
127 |
128 | # Publish Web Output
129 | *.Publish.xml
130 | *.pubxml
131 | *.publishproj
132 |
133 | # NuGet Packages Directory
134 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line
135 | #packages/
136 |
137 | # Windows Azure Build Output
138 | csx
139 | *.build.csdef
140 |
141 | # Windows Store app package directory
142 | AppPackages/
143 |
144 | # Others
145 | sql/
146 | *.Cache
147 | ClientBin/
148 | [Ss]tyle[Cc]op.*
149 | ~$*
150 | *~
151 | *.dbmdl
152 | *.[Pp]ublish.xml
153 | *.pfx
154 | *.publishsettings
155 |
156 | # RIA/Silverlight projects
157 | Generated_Code/
158 |
159 | # Backup & report files from converting an old project file to a newer
160 | # Visual Studio version. Backup files are not needed, because we have git ;-)
161 | _UpgradeReport_Files/
162 | Backup*/
163 | UpgradeLog*.XML
164 | UpgradeLog*.htm
165 |
166 | # SQL Server files
167 | App_Data/*.mdf
168 | App_Data/*.ldf
169 |
170 | #############
171 | ## Windows detritus
172 | #############
173 |
174 | # Windows image file caches
175 | Thumbs.db
176 | ehthumbs.db
177 |
178 | # Folder config file
179 | Desktop.ini
180 |
181 | # Recycle Bin used on file shares
182 | $RECYCLE.BIN/
183 |
184 | # Mac crap
185 | .DS_Store
186 |
187 |
188 | #############
189 | ## Python
190 | #############
191 |
192 | *.py[cod]
193 |
194 | # Packages
195 | *.egg
196 | *.egg-info
197 | dist/
198 | build/
199 | eggs/
200 | parts/
201 | var/
202 | sdist/
203 | develop-eggs/
204 | .installed.cfg
205 |
206 | # Installer logs
207 | pip-log.txt
208 |
209 | # Unit test / coverage reports
210 | .coverage
211 | .tox
212 |
213 | #Translations
214 | *.mo
215 |
216 | #Mr Developer
217 | .mr.developer.cfg
218 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapStructArray.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Runtime.InteropServices;
25 |
26 | namespace SAE.J2534
27 | {
28 | internal abstract class HeapStructArray : Common.UnmanagedDisposable
29 | {
30 | private readonly int elementSize;
31 | private readonly IntPtr firstElementPtr;
32 | public IntPtr Ptr { get; }
33 | private HeapStructArray(int Length)
34 | {
35 | elementSize = Marshal.SizeOf(typeof(T));
36 | //Create a blob big enough for all elements and two longs (NumOfItems and pItems)
37 | Ptr = Marshal.AllocHGlobal(Length * elementSize + 8);
38 | firstElementPtr = IntPtr.Add(Ptr, 8);
39 | this.Length = Length;
40 | //Write pItems. To save complexity, the array immediately follows SConfigArray.
41 | Marshal.WriteIntPtr(Ptr, 4, firstElementPtr);
42 | }
43 | public HeapStructArray(T Element) : this(1)
44 | {
45 | setIndex(0, Element);
46 | }
47 | public HeapStructArray(T[] Elements) : this(Elements.Length)
48 | {
49 | //Write the array to the blob
50 | for (int i = 0; i < Elements.Length; i++)
51 | setIndex(i, Elements[i]);
52 | }
53 | public int Length
54 | {
55 | get { return Marshal.ReadInt32(Ptr); }
56 | private set { Marshal.WriteInt32(Ptr, value); }
57 | }
58 | public T this[int Index]
59 | {
60 | get
61 | {
62 | if (Index >= Length || Index < 0) throw new IndexOutOfRangeException("Index out of bounds HeapStructArrayPtr!");
63 | return getIndex(Index);
64 | }
65 | set
66 | {
67 | if (Index >= Length || Index < 0) throw new IndexOutOfRangeException("Index out of bounds HeapStructArrayPtr!");
68 | setIndex(Index, value);
69 | }
70 | }
71 | private T getIndex(int Index)
72 | {
73 | return Marshal.PtrToStructure(IntPtr.Add(firstElementPtr, Index * elementSize));
74 | }
75 | private void setIndex(int Index, T Element)
76 | {
77 | Marshal.StructureToPtr(Element, IntPtr.Add(firstElementPtr, Index * elementSize), false);
78 | }
79 | public T[] ToArray()
80 | {
81 | T[] result = new T[Length];
82 | for (int i = 0; i < result.Length; i++)
83 | result[i] = getIndex(i);
84 | return result;
85 | }
86 | public static explicit operator IntPtr(HeapStructArray HeapStructArray)
87 | {
88 | return HeapStructArray.Ptr;
89 | }
90 | protected override void DisposeUnmanaged()
91 | {
92 | Marshal.FreeHGlobal(Ptr);
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/Src/DataClasses/MessageFilter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System.Linq;
24 |
25 | namespace SAE.J2534
26 | {
27 | public class MessageFilter
28 | {
29 | public Filter FilterType;
30 | public byte[] Mask;
31 | public byte[] Pattern;
32 | public byte[] FlowControl;
33 | public TxFlag TxFlags;
34 | public int FilterId;
35 |
36 | public MessageFilter()
37 | {
38 | TxFlags = TxFlag.NONE;
39 | }
40 |
41 | public MessageFilter(UserFilterType FilterType, byte[] Match)
42 | {
43 | TxFlags = TxFlag.NONE;
44 |
45 | switch (FilterType)
46 | {
47 | case UserFilterType.PASSALL:
48 | PassAll();
49 | break;
50 | case UserFilterType.PASS:
51 | Pass(Match);
52 | break;
53 | case UserFilterType.BLOCK:
54 | Block(Match);
55 | break;
56 | case UserFilterType.STANDARDISO15765:
57 | StandardISO15765(Match);
58 | break;
59 | case UserFilterType.NONE:
60 | break;
61 | }
62 | }
63 |
64 | private void Reset(int Length)
65 | {
66 | Mask = new byte[Length];
67 | Pattern = new byte[Length];
68 | FlowControl = new byte[Length];
69 | }
70 |
71 | public void PassAll()
72 | {
73 | Reset(1);
74 | Mask[0] = 0x00;
75 | Pattern[0] = 0x00;
76 | FilterType = Filter.PASS_FILTER;
77 | }
78 |
79 | public void Pass(byte[] Match)
80 | {
81 | ExactMatch(Match);
82 | FilterType = Filter.PASS_FILTER;
83 | }
84 |
85 | public void Block(byte[] Match)
86 | {
87 | ExactMatch(Match);
88 | FilterType = Filter.BLOCK_FILTER;
89 | }
90 |
91 | private void ExactMatch(byte[] Match)
92 | {
93 | Reset(Match.Length);
94 | Mask = Enumerable.Repeat((byte)0xFF, Match.Length).ToArray();
95 | Pattern = Match;
96 | }
97 | public void StandardISO15765(byte[] SourceAddress)
98 | {
99 | //Should throw exception??
100 | if (SourceAddress.Length != 4)
101 | return;
102 | Reset(4);
103 | Mask[0] = 0xFF;
104 | Mask[1] = 0xFF;
105 | Mask[2] = 0xFF;
106 | Mask[3] = 0xFF;
107 |
108 | Pattern = SourceAddress.ToArray();
109 | Pattern[3] += 0x08;
110 |
111 | FlowControl = SourceAddress;
112 |
113 | TxFlags = TxFlag.ISO15765_FRAME_PAD;
114 | FilterType = Filter.FLOW_CONTROL_FILTER;
115 | }
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/Src/Definitions/ProtocolInfo.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | public enum ProtocolInfo
51 | {
52 | MAX_RX_BUFFER_SIZE = 0x00000001,
53 | MAX_PASS_FILTER = 0x00000002,
54 | MAX_BLOCK_FILTER = 0x00000003,
55 | MAX_FILTER_MSG_LENGTH = 0x00000004,
56 | MAX_PERIODIC_MSGS = 0x00000005,
57 | MAX_PERIODIC_MSG_LENGTH = 0x00000006,
58 | DESIRED_DATA_RATE = 0x00000007,
59 | MAX_REPEAT_MESSAGING = 0x00000008,
60 | MAX_REPEAT_MESSAGING_LENGTH = 0x00000009,
61 | NETWORK_LINE_SUPPORTED = 0x0000000A,
62 | MAX_FUNCT_MSG_LOOKUP = 0x0000000B,
63 | PARITY_SUPPORTED = 0x0000000C,
64 | DATA_BITS_SUPPORTED = 0x0000000D,
65 | FIVE_BAUD_MOD_SUPPORTED = 0x0000000E,
66 | L_LINE_SUPPORTED = 0x0000000F,
67 | CAN_11_29_IDS_SUPPORTED = 0x00000010,
68 | CAN_MIXED_FORMAT_SUPPORTED = 0x00000011,
69 | MAX_FLOW_CONTROL_FILTER = 0x00000012,
70 | MAX_ISO15765_WFT_MAX = 0x00000013,
71 | MAX_AD_ACTIVE_CHANNELS = 0x00000014,
72 | MAX_AD_SAMPLE_RATE = 0x00000015,
73 | MAX_AD_SAMPLES_PER_READING = 0x00000016,
74 | AD_SAMPLE_RESOLUTION = 0x00000017,
75 | AD_INPUT_RANGE_LOW = 0x00000018,
76 | AD_INPUT_RANGE_HIGH = 0x00000019,
77 | RESOURCE_GROUP = 0x0000001A,
78 | TIMESTAMP_RESOLUTION = 0x0000001B
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/Src/Definitions/IOCTL.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | enum IOCTL
51 | {
52 | GET_CONFIG = 0x01,
53 | SET_CONFIG = 0x02,
54 | READ_VBATT = 0x03,
55 | FIVE_BAUD_INIT = 0x04,
56 | FAST_INIT = 0x05,
57 | CLEAR_TX_BUFFER = 0x07,
58 | CLEAR_RX_BUFFER = 0x08,
59 | CLEAR_PERIODIC_MSGS = 0x09,
60 | CLEAR_MSG_FILTERS = 0x0A,
61 | CLEAR_FUNCT_MSG_LOOKUP_TABLE = 0x0B,
62 | ADD_TO_FUNCT_MSG_LOOKUP_TABLE = 0x0C,
63 | DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE = 0x0D,
64 | READ_PROG_VOLTAGE = 0x0E,
65 | READ_CH1_VOLTAGE = 0x10000,
66 | READ_CH2_VOLTAGE = 0x10001,
67 | READ_CH3_VOLTAGE = 0x10002,
68 | READ_CH4_VOLTAGE = 0x10003,
69 | READ_CH5_VOLTAGE = 0x10004,
70 | READ_CH6_VOLTAGE = 0x10005,
71 | READ_ANALOG_CH1 = 0x10010,
72 | READ_ANALOG_CH2 = 0x10011,
73 | READ_ANALOG_CH3 = 0x10012,
74 | READ_ANALOG_CH4 = 0x10013,
75 | READ_ANALOG_CH5 = 0x10014,
76 | READ_ANALOG_CH6 = 0x10015,
77 | READ_TIMESTAMP = 0x10100,
78 | DT_IOCTL_VVSTATS = 0x20000000,
79 |
80 | //J2534-2
81 | SW_CAN_HS = 0x00008000,
82 | SW_CAN_NS = 0x00008001,
83 | SET_POLL_RESPONSE = 0x00008002,
84 | BECOME_MASTER = 0x00008003,
85 | START_REPEAT_MESSAGE = 0x00008004,
86 | QUERY_REPEAT_MESSAGE = 0x00008005,
87 | STOP_REPEAT_MESSAGE = 0x00008006,
88 | GET_DEVICE_CONFIG = 0x00008007,
89 | SET_DEVICE_CONFIG = 0x00008008,
90 | PROTECT_J1939_ADDR = 0x00008009,
91 | REQUEST_CONNECTION = 0x0000800A,
92 | TEARDOWN_CONNECTION = 0x0000800B,
93 | GET_DEVICE_INFO = 0x0000800C,
94 | GET_PROTOCOL_INFO = 0x0000800D,
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/Src/Definitions/Baud.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | using System.ComponentModel;
49 |
50 | namespace SAE.J2534
51 | {
52 | public enum Baud
53 | {
54 | [Description("10.4kbps")]
55 | ISO9141 = 10400,
56 | [Description("10.4kbps")]
57 | ISO9141_10400 = 10400,
58 | [Description("10kbps")]
59 | ISO9141_10000 = 10000,
60 |
61 | [Description("10.4kbps")]
62 | ISO14230 = 10400,
63 | [Description("10.4kbps")]
64 | ISO14230_10400 = 10400,
65 | [Description("10kbps")]
66 | ISO14230_10000 = 10000,
67 |
68 | [Description("41.6kbps")]
69 | J1850PWM = 41600,
70 | [Description("41.6kbps")]
71 | J1850PWM_41600 = 41600,
72 | [Description("83.2kbps")]
73 | J1850PWM_83200 = 83200,
74 |
75 | [Description("10.4kbps")]
76 | J1850VPW = 10400,
77 | [Description("10.4kbps")]
78 | J1850VPW_10400 = 10400,
79 | [Description("41.6kbps")]
80 | J1850VPW_41600 = 41600,
81 |
82 | [Description("500kbps")]
83 | CAN = 500000,
84 | [Description("125kbps")]
85 | CAN_125000 = 125000,
86 | [Description("250kbps")]
87 | CAN_250000 = 250000,
88 | [Description("500kbps")]
89 | CAN_500000 = 500000,
90 |
91 | [Description("GM LAN 33.333kbps")]
92 | GMLAN_33333 = 33333,
93 |
94 | [Description("500kbps")]
95 | ISO15765 = 500000,
96 | [Description("125kbps")]
97 | ISO15765_125000 = 125000,
98 | [Description("250kbps")]
99 | ISO15765_250000 = 250000,
100 | [Description("500kbps")]
101 | ISO15765_500000 = 500000,
102 |
103 | [Description("7812bps")]
104 | SCI_7812 = 7812,
105 | [Description("62.5kbps")]
106 | SCI_62500 = 62500
107 | }
108 | public static class BaudExtensions
109 | {
110 | public static string GetDescription(this Baud baud)
111 | {
112 | return Common.EnumHelper.GetMemberDescription(baud);
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/Src/Device.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 |
25 | namespace SAE.J2534
26 | {
27 | public partial class Device :Common.ManagedDisposable
28 | {
29 | private int deviceId;
30 | private object sync;
31 | internal API API { get; }
32 | public string FirmwareVersion { get; }
33 | public string DriverVersion { get; }
34 | public string APIVersion { get; }
35 | public string DeviceName { get; }
36 |
37 | internal Device(API API, string DeviceName, int DeviceID, object Sync)
38 | {
39 | this.API = API;
40 | this.DeviceName = DeviceName;
41 | deviceId = DeviceID;
42 | sync = Sync;
43 |
44 | using (var hFirmwareVersion = new HeapString(80))
45 | using (var hDllVersion = new HeapString(80))
46 | using (var hApiVersion = new HeapString(80))
47 | {
48 | lock (Sync)
49 | {
50 | API.CheckResult(API.PTReadVersion(DeviceID, (IntPtr)hFirmwareVersion, (IntPtr)hDllVersion, (IntPtr)hApiVersion));
51 | }
52 | FirmwareVersion = hFirmwareVersion.ToString();
53 | DriverVersion = hDllVersion.ToString();
54 | APIVersion = hApiVersion.ToString();
55 | }
56 | }
57 | ///
58 | /// Turns on the programming voltage for the device
59 | ///
60 | /// Pin number
61 | /// voltage (mV)
62 | public void SetProgrammingVoltage(Pin PinNumber, int Voltage)
63 | {
64 | lock (sync)
65 | {
66 | API.CheckResult(API.PTSetProgrammingVoltage(deviceId, (int)PinNumber, Voltage));
67 | }
68 | }
69 | ///
70 | /// Measures the vehicle supply voltage
71 | ///
72 | /// Voltage (mV)
73 | public int MeasureBatteryVoltage()
74 | {
75 | using (HeapInt hVoltage = new HeapInt())
76 | {
77 | lock (sync)
78 | {
79 | API.CheckResult(API.PTIoctl(deviceId, (int)IOCTL.READ_VBATT, IntPtr.Zero, (IntPtr)hVoltage));
80 | }
81 | return hVoltage.Value;
82 | }
83 | }
84 | ///
85 | /// Measures the delivered programming voltage
86 | ///
87 | /// Voltage (mV)
88 | public int MeasureProgrammingVoltage()
89 | {
90 | using (HeapInt hVoltage = new HeapInt())
91 | {
92 | lock (sync)
93 | {
94 | API.CheckResult(API.PTIoctl(deviceId, (int)IOCTL.READ_PROG_VOLTAGE, IntPtr.Zero, (IntPtr)hVoltage));
95 | }
96 | return hVoltage.Value;
97 | }
98 | }
99 | ///
100 | /// Opens a channel on the device using the specified parameters
101 | ///
102 | /// Connection protocol
103 | /// Connection baud-rate
104 | /// Connection flags
105 | /// A connected J2534Channel object
106 | public Channel GetChannel(Protocol ProtocolID, Baud Baud, ConnectFlag ConnectFlags, bool ChannelLevelSync = false)
107 | {
108 | using (HeapInt hChannelID = new HeapInt())
109 | {
110 | lock (sync)
111 | {
112 | API.CheckResult(API.PTConnect(deviceId, (int)ProtocolID, (int)ConnectFlags, (int)Baud, (IntPtr)hChannelID));
113 | }
114 | var NewChannel = new Channel(this, ProtocolID, Baud, ConnectFlags, hChannelID.Value, ChannelLevelSync ? new object() : sync);
115 | OnDisposing += NewChannel.Dispose;
116 | return NewChannel;
117 | }
118 | }
119 |
120 | protected override void DisposeManaged()
121 | {
122 | API.PTClose(deviceId);
123 | }
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### J2534-Sharp ###
2 |
3 | J2534-Sharp handles all the details of operating with unmanaged SAE J2534 spec library and lets you deal with the important stuff.
4 |
5 | Available on NuGet! [NuGet Gallery: J2534-Sharp]
6 |
7 | ## Features ##
8 | - No 'Unsafe' code. All unmanaged memory references are done using the marshaller
9 | - Thread safe design. Locking is done on API calls to allow concurrent access.
10 | - Simplified API. Most API calls have had redundant data removed and offer method signatures for common use cases
11 | - Support for v2.02 and v4.04 J2534 standards. v2.02 libraries are detected and 'shimmed' to a v4.04 interface seamlessly
12 | - Support for v5.00. v5 J2534 support has been started, but I need more info to complete it.
13 | - Support for DrewTech API. Support has been included for undocumented DrewTech API calls
14 |
15 | ## TODO's ##
16 | - Test the FivebaudInit and Fastinit methods.
17 | - Test with an actual v2.02 driver.
18 | - Finish the v5.00 implementation (can anyone send me the spec please??!!)
19 |
20 | This project is very active and still somewhat fluid. Breaking changes may occur and I wont apologize for them.
21 |
22 | ## Feedback ##
23 | I want to hear from you if you have ideas or thoughts about this library. Anything from features to critiques are welcome. Also, I would love to know what kinds of things its being used for!
24 |
25 | ## Usage Paradigm ##
26 | ## Traditional usage ##
27 | The traditional usage will use explicit filter definition and using disposables within using's'.
28 | ```csharp
29 | using System;
30 | using System.Linq;
31 | using SAE.J2534;
32 |
33 | namespace J5234Examples
34 | {
35 | class Program
36 | {
37 | static void Main(string[] args)
38 | {
39 | MessageFilter FlowControlFilter = new MessageFilter()
40 | {
41 | FilterType = Filter.FLOW_CONTROL_FILTER,
42 | Mask = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF },
43 | Pattern = new byte[] { 0x00, 0x00, 0x07, 0xE8 },
44 | FlowControl = new byte[] { 0x00, 0x00, 0x07, 0xE0 }
45 | };
46 |
47 | string DllFileName = APIFactory.GetAPIinfo().First().Filename;
48 |
49 | using (API API = APIFactory.GetAPI(DllFileName))
50 | using (Device Device = API.GetDevice())
51 | using (Channel Channel = Device.GetChannel(Protocol.ISO15765, Baud.ISO15765, ConnectFlag.NONE))
52 | {
53 | Channel.StartMsgFilter(FlowControlFilter);
54 | Console.WriteLine($"Voltage is {Channel.MeasureBatteryVoltage() / 1000}");
55 | Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x01, 0x00 });
56 | GetMessageResults Response = Channel.GetMessage();
57 | }
58 | }
59 | }
60 | }
61 | ```
62 |
63 | ## Simplified usage ##
64 | The simplified usage take advantage of built in 'templates' for creating the filters
65 | ```csharp
66 | using System;
67 | using System.Linq;
68 | using SAE.J2534;
69 |
70 | namespace J5234Examples
71 | {
72 | class Program
73 | {
74 | static void Main(string[] args)
75 | {
76 | string DllFileName = APIFactory.GetAPIinfo().First().Filename;
77 |
78 | using (API API = APIFactory.GetAPI(DllFileName))
79 | using (Device Device = API.GetDevice())
80 | using (Channel Channel = Device.GetChannel(Protocol.ISO15765, Baud.ISO15765, ConnectFlag.NONE))
81 | {
82 | Channel.StartMsgFilter(new MessageFilter(UserFilterType.STANDARDISO15765, new byte[] { 0x00, 0x00, 0x07, 0xE0}));
83 | Console.WriteLine($"Voltage is {Channel.MeasureBatteryVoltage() / 1000}");
84 | Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x01, 0x00 });
85 | GetMessageResults Response = Channel.GetMessage();
86 | }
87 | }
88 | }
89 | }
90 | ```
91 |
92 | ## Alternate usage of the APIFactory ##
93 | Alternately, the API factory can be instantiated as an instance, and when disposed, will dispose all children with it. This negates the need for explicit using's'
94 | except for the initial one for the APIFactory. NOTE: The APIFactory instance is only used to facilitate the disposal, and the instance does not need to be passed
95 | around.
96 | ```csharp
97 | using System;
98 | using System.Linq;
99 | using SAE.J2534;
100 |
101 | namespace J5234Examples
102 | {
103 | class Program
104 | {
105 | static void Main(string[] args)
106 | {
107 | using (var factory = new APIFactory())
108 | {
109 | Run();
110 | }
111 | }
112 | static void Run()
113 | {
114 | string DllFileName = APIFactory.GetAPIinfo().First().Filename;
115 |
116 | Channel Channel = APIFactory.GetAPI(DllFileName).GetDevice().GetChannel(Protocol.ISO15765, Baud.ISO15765, ConnectFlag.NONE);
117 |
118 | Channel.StartMsgFilter(new MessageFilter(UserFilterType.STANDARDISO15765, new byte[] { 0x00, 0x00, 0x07, 0xE0 }));
119 | Console.WriteLine($"Voltage is {Channel.MeasureBatteryVoltage() / 1000}");
120 | Channel.SendMessage(new byte[] { 0x00, 0x00, 0x07, 0xE0, 0x01, 0x00 });
121 | GetMessageResults Response = Channel.GetMessage();
122 | }
123 | }
124 | }
125 | ```
126 | [NuGet Gallery: J2534-Sharp]: http://www.nuget.org/packages/J2534-Sharp
--------------------------------------------------------------------------------
/Src/DataClasses/HeapMessage.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Runtime.InteropServices;
26 |
27 | namespace SAE.J2534
28 | {
29 | internal class HeapMessage : Common.UnmanagedDisposable
30 | {
31 | public IntPtr Ptr { get; } = Marshal.AllocHGlobal(CONST.J2534MESSAGESIZE);
32 |
33 | public HeapMessage(Protocol ProtocolID)
34 | {
35 | this.ProtocolID = ProtocolID;
36 | }
37 | public HeapMessage(Protocol ProtocolID, Message Message) : this(ProtocolID, Message.TxFlags, Message.Data)
38 | {
39 | }
40 | public HeapMessage(Protocol ProtocolID, TxFlag TxFlags, IEnumerable Data) : this(ProtocolID)
41 | {
42 | this.TxFlags = TxFlags;
43 | this.Data = Data;
44 | }
45 |
46 | public Message ToMessage()
47 | {
48 | return new Message((byte[])Data, RxStatus, Timestamp);
49 | }
50 |
51 | public Protocol ProtocolID
52 | {
53 | get { return (Protocol)Marshal.ReadInt32(Ptr); }
54 | set { Marshal.WriteInt32(Ptr, (int)value); }
55 | }
56 | public RxFlag RxStatus
57 | {
58 | get { return (RxFlag)Marshal.ReadInt32(Ptr, 4); }
59 | set { Marshal.WriteInt32(Ptr, 4, (int)value); }
60 | }
61 | public TxFlag TxFlags
62 | {
63 | get { return (TxFlag)Marshal.ReadInt32(Ptr, 8); }
64 | set { Marshal.WriteInt32(Ptr, 8, (int)value); }
65 | }
66 | public uint Timestamp
67 | {
68 | get { return (uint)Marshal.ReadInt32(Ptr, 12); }
69 | set { Marshal.WriteInt32(Ptr, 12, (int)value); }
70 | }
71 | public uint ExtraDataIndex
72 | {
73 | get { return (uint)Marshal.ReadInt32(Ptr, 20); }
74 | set { Marshal.WriteInt32(Ptr, 20, (int)value); }
75 | }
76 | public int Length
77 | {
78 | get { return Marshal.ReadInt32(Ptr, 16); }
79 | private set
80 | {
81 | if (value > CONST.J2534MESSAGESIZE) throw new ArgumentException("Message Data.Length is greater than fixed maximum");
82 | Marshal.WriteInt32(Ptr, 16, value);
83 | }
84 | }
85 | public IEnumerable Data
86 | {
87 | get
88 | {
89 | byte[] data = new byte[Marshal.ReadInt32(Ptr, 16)];
90 | Marshal.Copy(IntPtr.Add(Ptr, 24), data, 0, data.Length);
91 | return data;
92 | }
93 | set
94 | {
95 | IntPtr DataPtr = IntPtr.Add(Ptr, 24); //Offset to data array
96 | if (value is byte[]) //Byte[] is fastest
97 | {
98 | var ValueAsArray = (byte[])value;
99 | Length = ValueAsArray.Length;
100 | Marshal.Copy(ValueAsArray, 0, DataPtr, ValueAsArray.Length);
101 | }
102 | else if (value is IList) //Collection with indexer is second best
103 | {
104 | var ValueAsList = (IList)value;
105 | int length = ValueAsList.Count;
106 | Length = length;
107 | for (int indexer = 0; indexer < length; indexer++)
108 | {
109 | Marshal.WriteByte(DataPtr, indexer, ValueAsList[indexer]);
110 | }
111 | }
112 | else if (value is IEnumerable) //Enumerator is third
113 | {
114 | int index_count = 0;
115 | foreach (byte b in value)
116 | {
117 | Marshal.WriteByte(DataPtr, index_count, b);
118 | index_count++;
119 | }
120 | Length = index_count; //Set length
121 | }
122 | }
123 | }
124 | public static explicit operator IntPtr(HeapMessage HeapMessage)
125 | {
126 | return HeapMessage.Ptr;
127 | }
128 | protected override void DisposeUnmanaged()
129 | {
130 | Marshal.FreeHGlobal(Ptr);
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/Src/Definitions/Protocol.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System.ComponentModel;
48 |
49 | namespace SAE.J2534
50 | {
51 | public enum Protocol
52 | {
53 | [Description("SAE J1850 VPW")]
54 | J1850VPW = 0x01,
55 | [Description("SAE J1850 PWM")]
56 | J1850PWM = 0x02,
57 | [Description("ISO 9141")]
58 | ISO9141 = 0x03,
59 | [Description("ISO 14229")]
60 | ISO14230 = 0x04,
61 | [Description("CAN")]
62 | CAN = 0x05,
63 | [Description("ISO 15765")]
64 | ISO15765 = 0x06,
65 | [Description("SCI-A Engine")]
66 | SCI_A_ENGINE = 0x07,
67 | [Description("SCI-A Transmission")]
68 | SCI_A_TRANS = 0x08,
69 | [Description("SCI-B Engine")]
70 | SCI_B_ENGINE = 0x09,
71 | [Description("SCI-B Transmission")]
72 | SCI_B_TRANS = 0x0A,
73 |
74 | //J2534-2 Protocol definitions
75 | J1850VPW_PS = 0x00008000,
76 | J1850PWM_PS = 0x00008001,
77 | ISO9141_PS = 0x00008002,
78 | ISO14230_PS = 0x00008003,
79 | CAN_PS = 0x00008004,
80 | ISO15765_PS = 0x00008005,
81 | J2610_PS = 0x00008006,
82 | SW_ISO15765_PS = 0x00008007,
83 | SW_CAN_PS = 0x00008008,
84 | GM_UART_PS = 0x00008009,
85 | UART_ECHO_BYTE_PS = 0x0000800A,
86 | HONDA_DIAGH_PS = 0x0000800B,
87 | J1939_PS = 0x0000800C,
88 | J1708_PS = 0x0000800D,
89 | TP2_0_PS = 0x0000800E,
90 | FT_CAN_PS = 0x0000800F,
91 | FT_ISO15765_PS = 0x00008010,
92 | FD_CAN_PS = 0x00008011,
93 | FD_ISO15765_PS = 0x00008012,
94 | CAN_CH1 = 0x00009000,
95 | J1850VPW_CH1 = 0x00009080,
96 | J1850PWM_CH1 = 0x00009100,
97 | ISO9141_CH1 = 0x00009180,
98 | ISO14230_CH1 = 0x00009200,
99 | ISO15765_CH1 = 0x00009280,
100 | SW_CAN_CAN_CH1 = 0x00009300,
101 | SW_CAN_ISO15765_CH1 = 0x00009380,
102 | J2610_CH1 = 0x00009400,
103 | FT_CAN_CH1 = 0x00009480,
104 | FT_ISO15765_CH1 = 0x00009500,
105 | GM_UART_CH1 = 0x00009580,
106 | ECHO_BYTE_CH1 = 0x00009600,
107 | HONDA_DIAGH_CH1 = 0x00009680,
108 | J1939_CH1 = 0x00009700,
109 | J1708_CH1 = 0x00009780,
110 | TP2_0_CH1 = 0x00009800,
111 | FD_CAN_CH1 = 0x00009880,
112 | FD_ISO15765_CH1 = 0x00009900,
113 | ANALOG_IN_1 = 0x0000C000,
114 | }
115 | public static class ProtocolExtensions
116 | {
117 | public static string GetDescription(this Protocol protocol)
118 | {
119 | return Common.EnumHelper.GetMemberDescription(protocol);
120 | }
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/Src/J2534-Sharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(SolutionDir)\obj\
5 |
6 |
7 | Debug
8 | AnyCPU
9 | 9.0.30729
10 | 2.0
11 | {D99E0DE7-2F06-41E3-B33E-687E1B425A7F}
12 | Library
13 | Properties
14 | SAE.J2534
15 | J2534-Sharp
16 | v4.8
17 | 512
18 |
19 |
20 | 3.5
21 |
22 |
23 |
24 |
25 | true
26 | full
27 | false
28 | $(SolutionDir)\bin\Debug\
29 | DEBUG;TRACE
30 | prompt
31 | 4
32 | false
33 | AnyCPU
34 | false
35 | 7.1
36 |
37 |
38 | pdbonly
39 | true
40 | $(SolutionDir)\bin\Release\
41 | TRACE
42 | prompt
43 | 4
44 | AnyCPU
45 | false
46 | false
47 | ..\bin\Release\J2534-Sharp.XML
48 | 7.1
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
120 |
--------------------------------------------------------------------------------
/Src/APIFactory.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Collections.Generic;
25 | using System.IO;
26 | using System.Linq;
27 | using System.Text;
28 | using Microsoft.Win32;
29 |
30 | namespace SAE.J2534
31 | {
32 | public class APIFactory : Common.ManagedDisposable
33 | {
34 | private static Dictionary Cache = new Dictionary();
35 | ///
36 | /// Loads an API, verifies its signature and returns the managed wrapper
37 | ///
38 | /// DLL File to load
39 | /// JManaged 2534API
40 | public static API GetAPI(string Filename)
41 | {
42 | lock (Cache)
43 | {
44 | if (!Cache.ContainsKey(Filename))
45 | {
46 | if (!File.Exists(Filename)) throw new DllNotFoundException($"DLL Not Found! {Filename}");
47 |
48 | var API = new API(Filename);
49 | if (API.APISignature.SAE_API != SAE_API.V202_SIGNATURE &&
50 | API.APISignature.SAE_API != SAE_API.V404_SIGNATURE &&
51 | API.APISignature.SAE_API != SAE_API.V500_SIGNATURE)
52 | {
53 | API.Dispose();
54 | throw new MissingMemberException($"No compatible export signature was found in DLL {Filename}");
55 | }
56 |
57 | API.OnDisposing += () => Cache.Remove(Filename);
58 | Cache.Add(Filename, API);
59 | }
60 | return Cache[Filename];
61 | }
62 | }
63 |
64 | ///
65 | /// Queries the registry for registered J2534 API's
66 | ///
67 | /// APIInfo enumerable
68 | public static IEnumerable GetAPIinfo()
69 | {
70 | Dictionary DetailOptions = new Dictionary();
71 | DetailOptions.Add("CAN", "CAN Bus");
72 | DetailOptions.Add("ISO15765", "ISO15765");
73 | DetailOptions.Add("J1850PWM", "J1850PWM");
74 | DetailOptions.Add("J1850VPW", "J1850VPW");
75 | DetailOptions.Add("ISO9141", "ISO9141");
76 | DetailOptions.Add("ISO14230", "ISO14230");
77 | DetailOptions.Add("SCI_A_ENGINE", "SCI-A Engine");
78 | DetailOptions.Add("SCI_A_TRANS", "SCI-A Transmission");
79 | DetailOptions.Add("SCI_B_ENGINE", "SCI-B Engine");
80 | DetailOptions.Add("SCI_B_TRANS", "SCI-B Transmission");
81 |
82 | const string PASSTHRU_REGISTRY_PATH = @"Software\PassThruSupport.04.04";
83 | const string PASSTHRU_REGISTRY_PATH_6432 = @"Software\Wow6432Node\PassThruSupport.04.04";
84 |
85 | RegistryKey RootKey = Registry.LocalMachine.OpenSubKey(PASSTHRU_REGISTRY_PATH, false);
86 | if (RootKey == null)
87 | {
88 | RootKey = Registry.LocalMachine.OpenSubKey(PASSTHRU_REGISTRY_PATH_6432, false);
89 | }
90 |
91 | if (RootKey == null)
92 | yield break;
93 |
94 | string[] RegistryEntries = RootKey.GetSubKeyNames();
95 | foreach (string Entry in RegistryEntries)
96 | {
97 | RegistryKey deviceKey = RootKey.OpenSubKey(Entry);
98 | if (deviceKey == null) continue;
99 |
100 | StringBuilder DetailsBuilder = new StringBuilder();
101 |
102 | var Vendor = (string)deviceKey.GetValue("Vendor", "");
103 | if (!String.IsNullOrWhiteSpace(Vendor))
104 | DetailsBuilder.AppendLine($"Vendor: {Vendor}");
105 | var ConfigApplication = (string)deviceKey.GetValue("ConfigApplication", "");
106 | if (!String.IsNullOrWhiteSpace(ConfigApplication))
107 | DetailsBuilder.AppendLine($"Configuration Application: {ConfigApplication}");
108 |
109 | foreach (var Option in DetailOptions)
110 | {
111 | if (((int)deviceKey.GetValue(Option.Key, 0)) != 0)
112 | {
113 | DetailsBuilder.AppendLine(Option.Value);
114 | }
115 | }
116 |
117 | yield return new APIInfo((string)deviceKey.GetValue("Name", ""),
118 | (string)deviceKey.GetValue("FunctionLibrary", ""),
119 | DetailsBuilder.ToString());
120 | }
121 | }
122 | public static void StaticDispose()
123 | {
124 | foreach (var API in Cache.Values.ToArray())
125 | {
126 | API.Dispose();
127 | }
128 | }
129 |
130 | protected override void DisposeManaged()
131 | {
132 | StaticDispose();
133 | }
134 | }
135 | }
136 |
--------------------------------------------------------------------------------
/Src/Definitions/Parameter.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 |
48 | namespace SAE.J2534
49 | {
50 | public enum Parameter
51 | {
52 | DATA_RATE = 0x01,
53 | LOOP_BACK = 0x03,
54 | NODE_ADDRESS = 0x04,
55 | NETWORK_LINE = 0x05,
56 | P1_MIN = 0x06,
57 | P1_MAX = 0x07,
58 | P2_MIN = 0x08,
59 | P2_MAX = 0x09,
60 | P3_MIN = 0x0A,
61 | P3_MAX = 0x0B,
62 | P4_MIN = 0x0C,
63 | P4_MAX = 0x0D,
64 | W0 = 0x19,
65 | W1 = 0x0E,
66 | W2 = 0x0F,
67 | W3 = 0x10,
68 | W4 = 0x11,
69 | W5 = 0x12,
70 | TIDLE = 0x13,
71 | TINIL = 0x14,
72 | TWUP = 0x15,
73 | PARITY = 0x16,
74 | BIT_SAMPLE_POINT = 0x17,
75 | SYNC_JUMP_WIDTH = 0x18,
76 | T1_MAX = 0x1A,
77 | T2_MAX = 0x1B,
78 | T3_MAX = 0x24,
79 | T4_MAX = 0x1C,
80 | T5_MAX = 0x1D,
81 | ISO15765_BS = 0x1E,
82 | ISO15765_STMIN = 0x1F,
83 | DATA_BITS = 0x20,
84 | FIVE_BAUD_MOD = 0x21,
85 | BS_TX = 0x22,
86 | STMIN_TX = 0x23,
87 | ISO15765_WFT_MAX = 0x25,
88 |
89 | //J2534-2
90 | CAN_MIXED_FORMAT = 0x00008000,
91 | J1962_PINS = 0x00008001,
92 | SW_CAN_HS_DATA_RATE = 0x00008010,
93 | SW_CAN_SPEEDCHANGE_ENABLE = 0x00008011,
94 | SW_CAN_RES_SWITCH = 0x00008012,
95 | ACTIVE_CHANNELS = 0x00008020,
96 | SAMPLE_RATE = 0x00008021,
97 | SAMPLES_PER_READING = 0x00008022,
98 | READINGS_PER_MSG = 0x00008023,
99 | AVERAGING_METHOD = 0x00008024,
100 | SAMPLE_RESOLUTION = 0x00008025,
101 | INPUT_RANGE_LOW = 0x00008026,
102 | INPUT_RANGE_HIGH = 0x00008027,
103 | UEB_T0_MIN = 0x00008028,
104 | UEB_T1_MAX = 0x00008029,
105 | UEB_T2_MAX = 0x0000802A,
106 | UEB_T3_MAX = 0x0000802B,
107 | UEB_T4_MIN = 0x0000802C,
108 | UEB_T5_MAX = 0x0000802D,
109 | UEB_T6_MAX = 0x0000802E,
110 | UEB_T7_MIN = 0x0000802F,
111 | UEB_T7_MAX = 0x00008030,
112 | UEB_T9_MIN = 0x00008031,
113 | J1939_PINS = 0x0000803D,
114 | J1708_PINS = 0x0000803E,
115 | J1939_T1 = 0x0000803F,
116 | J1939_T2 = 0x00008040,
117 | J1939_T3 = 0x00008041,
118 | J1939_T4 = 0x00008042,
119 | J1939_BRDCST_MIN_DELAY = 0x00008043,
120 | TP2_0_T_BR_INT = 0x00008044,
121 | TP2_0_T_E = 0x00008045,
122 | TP2_0_MNTC = 0x00008046,
123 | TP2_0_T_CTA = 0x00008047,
124 | TP2_0_MNCT = 0x00008048,
125 | TP2_0_MNTB = 0x00008049,
126 | TP2_0_MNT = 0x0000804A,
127 | TP2_0_T_WAIT = 0x0000804B,
128 | TP2_0_T1 = 0x0000804C,
129 | TP2_0_T3 = 0x0000804D,
130 | TP2_0_IDENTIFER = 0x0000804E,
131 | TP2_0_RXIDPASSIVE = 0x0000804F,
132 | FD_CAN_DATA_PHASE_RATE = 0x0000805C,
133 | FD_ISO15765_TX_DATA_LENGTH = 0x0000805D,
134 | HS_CAN_TERMINATION = 0x0000805E,
135 | N_CR_MAX = 0x0000805F,
136 | ISO15765_PAD_VALUE = 0x00008060,
137 |
138 | ISO15765_SIMULTANEOUS = 0x10000000, //Drewtech
139 | DT_ISO15765_PAD_BYTE = 0x10000001, //Drewtech
140 | ADC_READINGS_PER_SECOND = 0x10000, //Drewtech
141 | ADC_READINGS_PER_SAMPLE = 0x20000 //Drewtech
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/Src/Definitions/DeviceInfo.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | namespace SAE.J2534
48 | {
49 | public enum DeviceInfo
50 | {
51 | SERIAL_NUMBER = 0x00000001,
52 | J1850PWM_SUPPORTED = 0x00000002,
53 | J1850VPW_SUPPORTED = 0x00000003,
54 | ISO9141_SUPPORTED = 0x00000004,
55 | ISO14230_SUPPORTED = 0x00000005,
56 | CAN_SUPPORTED = 0x00000006,
57 | ISO15765_SUPPORTED = 0x00000007,
58 | SCI_A_ENGINE_SUPPORTED = 0x00000008,
59 | SCI_A_TRANS_SUPPORTED = 0x00000009,
60 | SCI_B_ENGINE_SUPPORTED = 0x0000000A,
61 | SCI_B_TRANS_SUPPORTED = 0x0000000B,
62 | SW_ISO15765_SUPPORTED = 0x0000000C,
63 | SW_CAN_SUPPORTED = 0x0000000D,
64 | GM_UART_SUPPORTED = 0x0000000E,
65 | UART_ECHO_BYTE_SUPPORTED = 0x0000000F,
66 | HONDA_DIAGH_SUPPORTED = 0x00000010,
67 | J1939_SUPPORTED = 0x00000011,
68 | J1708_SUPPORTED = 0x00000012,
69 | TP2_0_SUPPORTED = 0x00000013,
70 | J2610_SUPPORTED = 0x00000014,
71 | ANALOG_IN_SUPPORTED = 0x00000015,
72 | MAX_NON_VOLATILE_STORAGE = 0x00000016,
73 | SHORT_TO_GND_J1962 = 0x00000017,
74 | PGM_VOLTAGE_J1962 = 0x00000018,
75 | J1850PWM_PS_J1962 = 0x00000019,
76 | J1850VPW_PS_J1962 = 0x0000001A,
77 | ISO9141_PS_K_LINE_J1962 = 0x0000001B,
78 | ISO9141_PS_L_LINE_J1962 = 0x0000001C,
79 | ISO14230_PS_K_LINE_J1962 = 0x0000001D,
80 | ISO14230_PS_L_LINE_J1962 = 0x0000001E,
81 | CAN_PS_J1962 = 0x0000001F,
82 | ISO15765_PS_J1962 = 0x00000020,
83 | SW_CAN_PS_J1962 = 0x00000021,
84 | SW_ISO15765_PS_J1962 = 0x00000022,
85 | GM_UART_PS_J1962 = 0x00000023,
86 | UART_ECHO_BYTE_PS_J1962 = 0x00000024,
87 | HONDA_DIAGH_PS_J1962 = 0x00000025,
88 | J1939_PS_J1962 = 0x00000026,
89 | J1708_PS_J1962 = 0x00000027,
90 | TP2_0_PS_J1962 = 0x00000028,
91 | J2610_PS_J1962 = 0x00000029,
92 | J1939_PS_J1939 = 0x0000002A,
93 | J1708_PS_J1939 = 0x0000002B,
94 | ISO9141_PS_K_LINE_J1939 = 0x0000002C,
95 | ISO9141_PS_L_LINE_J1939 = 0x0000002D,
96 | ISO14230_PS_K_LINE_J1939 = 0x0000002E,
97 | ISO14230_PS_L_LINE_J1939 = 0x0000002F,
98 | J1708_PS_J1708 = 0x00000030,
99 | FT_CAN_SUPPORTED = 0x00000031,
100 | FT_ISO15765_SUPPORTED = 0x00000032,
101 | FT_CAN_PS_J1962 = 0x00000033,
102 | FT_ISO15765_PS_J1962 = 0x00000034,
103 | J1850PWM_SIMULTANEOUS = 0x00000035,
104 | J1850VPW_SIMULTANEOUS = 0x00000036,
105 | ISO9141_SIMULTANEOUS = 0x00000037,
106 | ISO14230_SIMULTANEOUS = 0x00000038,
107 | CAN_SIMULTANEOUS = 0x00000039,
108 | ISO15765_SIMULTANEOUS = 0x0000003A,
109 | SCI_A_ENGINE_SIMULTANEOUS = 0x0000003B,
110 | SCI_A_TRANS_SIMULTANEOUS = 0x0000003C,
111 | SCI_B_ENGINE_SIMULTANEOUS = 0x0000003D,
112 | SCI_B_TRANS_SIMULTANEOUS = 0x0000003E,
113 | SW_ISO15765_SIMULTANEOUS = 0x0000003F,
114 | SW_CAN_SIMULTANEOUS = 0x00000040,
115 | GM_UART_SIMULTANEOUS = 0x00000041,
116 | UART_ECHO_BYTE_SIMULTANEOUS = 0x00000042,
117 | HONDA_DIAGH_SIMULTANEOUS = 0x00000043,
118 | J1939_SIMULTANEOUS = 0x00000044,
119 | J1708_SIMULTANEOUS = 0x00000045,
120 | TP2_0_SIMULTANEOUS = 0x00000046,
121 | J2610_SIMULTANEOUS = 0x00000047,
122 | ANALOG_IN_SIMULTANEOUS = 0x00000048,
123 | PART_NUMBER = 0x00000049,
124 | FT_CAN_SIMULTANEOUS = 0x0000004A,
125 | FT_ISO15765_SIMULTANEOUS = 0x0000004B,
126 | FD_CAN_SUPPORTED = 0x0000004C,
127 | FD_ISO15765_SUPPORTED = 0x0000004D,
128 | FD_CAN_SIMULTANEOUS = 0x0000004E,
129 | FD_ISO15765_SIMULTANEOUS = 0x0000004F,
130 | FD_CAN_PS_J1962 = 0x00000050,
131 | FD_ISO15765_PS_J1962 = 0x00000051
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/Src/API.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 | using System.Runtime.InteropServices;
49 |
50 | namespace SAE.J2534
51 | {
52 | public partial class API : Common.UnmanagedDisposable
53 | {
54 | private object sync = new object();
55 | private IntPtr pLibrary;
56 | internal API_Signature APISignature { get; }
57 | internal API(string FileName)
58 | {
59 | APISignature = new API_Signature();
60 |
61 | pLibrary = Kernal32.LoadLibrary(FileName);
62 |
63 | APISignature = AssignDelegates();
64 | }
65 | ///
66 | /// Opens a J2534 device using this API
67 | ///
68 | /// The name of the device or blank to open the first available
69 | /// Device object
70 | public Device GetDevice(string DeviceName = "")
71 | {
72 | using (var hDeviceID = new HeapInt())
73 | using (var hDeviceName = new HeapString(DeviceName))
74 | {
75 | lock (sync)
76 | {
77 | CheckResult(PTOpen(String.IsNullOrWhiteSpace(DeviceName) ? IntPtr.Zero : (IntPtr)hDeviceName, (IntPtr)hDeviceID));
78 | }
79 | var device = new Device(this, hDeviceName.ToString(), hDeviceID.Value, sync);
80 | OnDisposing += device.Dispose;
81 | return device;
82 | }
83 | }
84 | ///
85 | /// Resets the GetNextCarDAQ enumerator
86 | /// NOTE: Drewtech ONLY
87 | ///
88 | public void GetNextCarDAQ_RESET()
89 | {
90 | lock (sync)
91 | {
92 | CheckResult(PTGetNextCarDAQ(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero));
93 | }
94 | }
95 | ///
96 | /// Enumerates through connected Drewtech devices
97 | /// NOTE: Drewtech ONLY
98 | ///
99 | /// GetNextCarDAQResults
100 | public GetNextCarDAQResults GetNextCarDAQ()
101 | {
102 | using (var hNamePtr = new HeapIntPtr())
103 | using (var hAddrPtr = new HeapIntPtr())
104 | using (var hVerPtr = new HeapIntPtr())
105 | {
106 | lock (sync)
107 | {
108 | CheckResult(PTGetNextCarDAQ((IntPtr)hNamePtr, (IntPtr)hVerPtr, (IntPtr)hAddrPtr));
109 | }
110 | if (hNamePtr.Ptr == IntPtr.Zero) return null;
111 |
112 | byte[] b = new byte[3];
113 | Marshal.Copy((IntPtr)hVerPtr, b, 0, 3);
114 |
115 | return new GetNextCarDAQResults(Name: Marshal.PtrToStringAnsi((IntPtr)hNamePtr),
116 | Version: $"{b[2]}.{b[1]}.{b[0]}",
117 | Address: Marshal.PtrToStringAnsi((IntPtr)hAddrPtr));
118 | }
119 | }
120 | internal void CheckResult(ResultCode Result)
121 | {
122 | if (Result.IsNotOK()) throw new J2534Exception(Result, GetLastError());
123 | }
124 |
125 | internal string GetLastError() //Should never be called outside of API_LOCK
126 | {
127 | ResultCode Result;
128 | using(var hErrorDescription = new HeapString(80))
129 | {
130 | lock (sync)
131 | {
132 | Result = PTGetLastError((IntPtr)hErrorDescription);
133 | if (Result == ResultCode.STATUS_NOERROR)
134 | return hErrorDescription.ToString();
135 | else
136 | return null;
137 | }
138 | }
139 | }
140 | protected override void DisposeUnmanaged()
141 | {
142 | Kernal32.FreeLibrary(pLibrary);
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/Src/API_Prototypes.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 | using System.Runtime.InteropServices;
49 |
50 | namespace SAE.J2534
51 | {
52 | public partial class API
53 | {
54 | //Shared prototypes
55 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
56 | internal delegate ResultCode PassThruConnect(int DeviceID, int ProtocolID, int ConnectFlags, int Baud, IntPtr ChannelID);
57 |
58 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59 | internal delegate ResultCode PassThruDisconnect(int channelId);
60 |
61 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
62 | internal delegate ResultCode PassThruReadMsgs(int ChannelID, IntPtr pUMsgArray, IntPtr NumMsgs, int Timeout);
63 |
64 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
65 | internal delegate ResultCode PassThruWriteMsgs(int ChannelID, IntPtr pUMsgArray, IntPtr NumMsgs, int Timeout);
66 |
67 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
68 | internal delegate ResultCode PassThruStartPeriodicMsg(int ChannelID, IntPtr Msg, IntPtr MsgID, int Interval);
69 |
70 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
71 | internal delegate ResultCode PassThruStopPeriodicMsg(int ChannelID, int MsgID);
72 |
73 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
74 | internal delegate ResultCode PassThruStartMsgFilter
75 | (
76 | int ChannelID,
77 | int FilterType,
78 | IntPtr pMaskMsg,
79 | IntPtr PatternMsg,
80 | IntPtr pFlowControlMsg,
81 | IntPtr FilterID
82 | );
83 |
84 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
85 | internal delegate ResultCode PassThruStopMsgFilter(int ChannelID, int FilterID);
86 |
87 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
88 | internal delegate ResultCode PassThruSetProgrammingVoltage(int DeviceID, int Pin, int Voltage);
89 |
90 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91 | internal delegate ResultCode PassThruReadVersion(int DeviceID, IntPtr pFirmwareVer, IntPtr pDllVer, IntPtr pAPIVer);
92 |
93 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
94 | internal delegate ResultCode PassThruGetLastError(IntPtr pErr);
95 |
96 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
97 | internal delegate ResultCode PassThruIoctl(int HandleID, int IOCtlID, IntPtr Input, IntPtr Output);
98 |
99 | //v2.02 ONLY
100 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
101 | internal delegate ResultCode PassThruConnectv202(int ProtocolID, int ConnectFlags, IntPtr ChannelID);
102 |
103 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
104 | internal delegate ResultCode PassThruSetProgrammingVoltagev202(int Pin, int Voltage);
105 |
106 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
107 | internal delegate ResultCode PassThruReadVersionv202(IntPtr pFirmwareVer, IntPtr pDllVer, IntPtr pAPIVer);
108 | //v4.04
109 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
110 | internal delegate ResultCode PassThruOpen(IntPtr pDeviceName, IntPtr DeviceID);
111 |
112 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
113 | internal delegate ResultCode PassThruClose(int DeviceID);
114 | //v5.00 and undocumented drewtech calls
115 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
116 | internal delegate ResultCode PassThruScanForDevices(ref int DeviceCount);
117 |
118 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
119 | internal delegate ResultCode PassThruGetNextDevice(IntPtr pSDevice);
120 |
121 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
122 | internal delegate ResultCode PassThruLogicalConnect(int PhysicalChannelID, int ProtocolID, int ConnectFlags, IntPtr ChannelDescriptor, ref int pChannelID);
123 |
124 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
125 | internal delegate ResultCode PassThruLogicalDisconnect(int pChannelID);
126 |
127 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
128 | internal delegate ResultCode PassThruSelect(IntPtr pSChannelSet, int SelectType, int Timeout);
129 |
130 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
131 | internal delegate ResultCode PassThruQueueMsgs(int ChannelID, IntPtr pMsgArray, ref int NumMsgs);
132 | //Drewtech ONLY
133 | [UnmanagedFunctionPointer(CallingConvention.StdCall)]
134 | internal delegate ResultCode PassThruGetNextCarDAQ(IntPtr pName, IntPtr pVer, IntPtr pAddress);
135 | }
136 | }
137 |
--------------------------------------------------------------------------------
/Src/Definitions/ResultCode.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 | using System.ComponentModel;
49 |
50 | namespace SAE.J2534
51 | {
52 | public enum ResultCode
53 | {
54 | [Description("Function completed successfully.")]
55 | STATUS_NOERROR = 0x00,
56 | [Description("Function option is not supported.")]
57 | NOT_SUPPORTED = 0x01,
58 | [Description("Channel Identifier or handle was not recognized.")]
59 | INVALID_CHANNEL_ID = 0x02,
60 | [Description("Protocol identifier was not recognized.")]
61 | INVALID_PROTOCOL_ID = 0x03,
62 | [Description("NULL pointer presented as a function parameter address.")]
63 | NULL_PARAMETER = 0x04,
64 | [Description("IOCTL GET_CONFIG/SET_CONFIG parameter value is not recognized.")]
65 | INVALID_IOCTL_VALUE = 0x05,
66 | [Description("Flags bit field(s) contain(s) an invalid value.")]
67 | INVALID_FLAGS = 0x06,
68 | [Description("Unspecified error, use PassThruGetLastError for obtaining error text string.")]
69 | FAILED = 0x07,
70 | [Description("The PassThru device is not connected to the PC.")]
71 | DEVICE_NOT_CONNECTED = 0x08,
72 | [Description("The PassThru device was unable to read the specified number of messages from the vehicle network within the specified time.")]
73 | TIMEOUT = 0x09,
74 | [Description("Message contains a min/max Length, ExtraData support or J1850PWM specific source address conflict violation.")]
75 | INVALID_MSG = 0x0A,
76 | [Description("The time interval value is outside the allowed range.")]
77 | INVALID_TIME_INTERVAL = 0x0B,
78 | [Description("The limit (ten) of filter/periodic messages has been exceed. for the protocol associated with the communications channel.")]
79 | EXCEEDED_LIMIT = 0x0C,
80 | [Description("The message identifier or handle was not recognized.")]
81 | INVALID_MSG_ID = 0x0D,
82 | [Description("The specified PassThru device is already in use.")]
83 | DEVICE_IN_USE = 0x0E,
84 | [Description("IOCTL identifier is not recognized.")]
85 | INVALID_IOCTL_ID = 0x0F,
86 | [Description("The PassThru device could not read any messages from the vehicle network.")]
87 | BUFFER_EMPTY = 0x10,
88 | [Description("The PassThru device could not queue any more transmit messages destined for the vehicle network.")]
89 | BUFFER_FULL = 0x11,
90 | [Description("The PassThru device experienced a buffer overflow and receive messages were lost.")]
91 | BUFFER_OVERFLOW = 0x12,
92 | [Description("An unknown pin number specified for the J1962 connector, or the resource is already in use.")]
93 | PIN_INVALID = 0x13,
94 | [Description("An existing communications channel is currently using the specified network protocol.")]
95 | CHANNEL_IN_USE = 0x14,
96 | [Description("The specified protocol type within the message structure is different from the protocol associated with the communications channel when it was opened.")]
97 | MSG_PROTOCOL_ID = 0x15,
98 | [Description("Filter identifier is not recognized.")]
99 | INVALID_FILTER_ID = 0x16,
100 | [Description("No ISO15765 flow control filter matches the header of the outgoing message.")]
101 | NO_FLOW_CONTROL = 0x17,
102 | [Description("An existing filter already matches this header or node identifier.")]
103 | NOT_UNIQUE = 0x18,
104 | [Description("Unable to honor requested baud-rate within required tolerances.")]
105 | INVALID_BAUDRATE = 0x19,
106 | [Description("PassThru device identifier was not recognized.")]
107 | INVALID_DEVICE_ID = 0x1A,
108 | [Description("Invalid IOCTL Parameter ID (either in the reserved range or not appropriate for the current channel)")]
109 | ERR_INVALID_IOCTL_PARAM_ID = 0x1E,
110 | [Description("Programming voltage is currently being applied to another pin")]
111 | ERR_VOLTAGE_IN_USE = 0x1F,
112 | [Description("Pin number specified is currently in use(another protocol is using the pin)")]
113 | ERR_PIN_IN_USE = 0x20,
114 | [Description("The API call was not mapped to a function in the PassThru DLL.")]
115 | FUNCTION_NOT_ASSIGNED = 0x7EADBEEF //non-standard flag used by the wrapper to indicate no function assigned
116 | }
117 | public static class ResultCodeExtensions
118 | {
119 | public static bool IsOK(this ResultCode code)
120 | {
121 | return code == ResultCode.STATUS_NOERROR;
122 | }
123 | public static bool IsNotOK(this ResultCode code)
124 | {
125 | return code != ResultCode.STATUS_NOERROR;
126 | }
127 | public static string GetDescription(this ResultCode code)
128 | {
129 | return Common.EnumHelper.GetMemberDescription(code);
130 | }
131 | }
132 | }
133 |
--------------------------------------------------------------------------------
/Src/DataClasses/HeapMessageArray.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Runtime.InteropServices;
26 | using System.Runtime.CompilerServices;
27 |
28 | namespace SAE.J2534
29 | {
30 | public class HeapMessageArray : Common.UnmanagedDisposable
31 | {
32 | private int protocolID;
33 | private int array_max_length;
34 | public IntPtr MessagePtr { get; }
35 | public IntPtr LengthPtr { get; }
36 |
37 | public IntPtr Ptr { get { return MessagePtr; } }
38 |
39 | public HeapMessageArray(Protocol ProtocolID, int Length)
40 | {
41 | if (Length < 1) throw new ArgumentException("Length must be at least 1 (HEAPMessageArray");
42 | array_max_length = Length;
43 | LengthPtr = Marshal.AllocHGlobal(CONST.J2534MESSAGESIZE * Length + 4);
44 | MessagePtr = IntPtr.Add(LengthPtr, 4);
45 | protocolID = (int)ProtocolID;
46 | }
47 | public int Length
48 | {
49 | get
50 | {
51 | return Marshal.ReadInt32(LengthPtr);
52 | }
53 | set
54 | {
55 | if (value > array_max_length) throw new IndexOutOfRangeException("Length is greater than array bound (HEAPMessageArray)");
56 | Marshal.WriteInt32(LengthPtr, value);
57 | }
58 | }
59 | public Message this[int index]
60 | {
61 | get
62 | {
63 | if (index >= array_max_length || index < 0) throw new IndexOutOfRangeException("Index out of range in J2534HeapMessageArray get[]");
64 | return getIndex(index);
65 | }
66 | set
67 | {
68 | if (index >= array_max_length || index < 0) throw new IndexOutOfRangeException("Index out of range in J2534HeapMessageArray set[]");
69 | setIndex(index, value);
70 | }
71 | }
72 | private Message getIndex(int index)
73 | {
74 | IntPtr pMessage = IntPtr.Add(MessagePtr, index * CONST.J2534MESSAGESIZE);
75 | return new Message(marshalHeapDataToArray(pMessage),
76 | (RxFlag)Marshal.ReadInt32(pMessage, 4),
77 | (uint)Marshal.ReadInt32(pMessage, 12));
78 | }
79 | private void setIndex(int index, Message Message)
80 | {
81 | IntPtr pMessage = IntPtr.Add(MessagePtr, index * CONST.J2534MESSAGESIZE);
82 | Marshal.WriteInt32(pMessage, protocolID);
83 | Marshal.WriteInt32(pMessage, 8, Message.FlagsAsInt);
84 | marshalIEnumerableToHeapData(pMessage, Message.Data);
85 | }
86 | private byte[] marshalHeapDataToArray(IntPtr pData)
87 | {
88 | int Length = Marshal.ReadInt32(pData, 16);
89 | byte[] data = new byte[Length];
90 | Marshal.Copy(IntPtr.Add(pData, 24), data, 0, Length);
91 | return data;
92 | }
93 | private void marshalIEnumerableToHeapData(IntPtr pMessage, IEnumerable Data)
94 | {
95 | if (Data is byte[]) //Byte[] is fastest
96 | {
97 | var DataAsArray = (byte[])Data;
98 | Marshal.WriteInt32(pMessage, 16, DataAsArray.Length);
99 | Marshal.Copy(DataAsArray, 0, IntPtr.Add(pMessage, 24), DataAsArray.Length);
100 | }
101 | else if (Data is ArraySegment)
102 | {
103 | var DataAsArraySegment = (ArraySegment)Data;
104 | Marshal.WriteInt32(pMessage, 16, DataAsArraySegment.Count);
105 | Marshal.Copy(DataAsArraySegment.Array, DataAsArraySegment.Offset, IntPtr.Add(pMessage, 24), DataAsArraySegment.Count);
106 | }
107 | else if (Data is IList) //Collection with indexer is second best
108 | {
109 | var DataAsList = (IList)Data;
110 | int length = DataAsList.Count;
111 | IntPtr Ptr = IntPtr.Add(pMessage, 24); //Offset to data array
112 | Marshal.WriteInt32(pMessage, 16, length);
113 | for (int indexer = 0; indexer < length; indexer++)
114 | {
115 | Marshal.WriteByte(Ptr, indexer, DataAsList[indexer]);
116 | }
117 | }
118 | else if (Data is IEnumerable) //Enumerator is third
119 | {
120 | IntPtr Ptr = IntPtr.Add(pMessage, 24); //Offset to data array
121 | int index_count = 0;
122 | foreach (byte b in Data)
123 | {
124 | Marshal.WriteByte(Ptr, index_count, b);
125 | index_count++;
126 | }
127 | Marshal.WriteInt32(pMessage, 16, index_count); //Set length
128 | }
129 | }
130 | public void FromMessage(Message Message)
131 | {
132 | Length = 1;
133 | setIndex(0, Message);
134 | }
135 | public Message ToMessage()
136 | {
137 | return getIndex(0);
138 | }
139 | public Message[] ToMessageArray()
140 | {
141 | int length = Length;
142 | Message[] result = new Message[length];
143 | for (int i = 0; i < length; i++)
144 | result[i] = getIndex(i);
145 | return result;
146 | }
147 | public void FromMessageArray(Message [] Messages)
148 | {
149 | Length = Messages.Length;
150 | for (int i = 0; i < Messages.Length; i++)
151 | {
152 | setIndex(i, Messages[i]);
153 | }
154 | }
155 | public void FromDataBytes(IEnumerable Data, TxFlag TxFlags = TxFlag.NONE)
156 | {
157 | Length = 1;
158 | Marshal.WriteInt32(MessagePtr, protocolID);
159 | Marshal.WriteInt32(MessagePtr, 8, (int)TxFlags);
160 | marshalIEnumerableToHeapData(MessagePtr, Data);
161 | }
162 | public void FromDataBytesArray(IEnumerable[] Data, TxFlag TxFlags = TxFlag.NONE)
163 | {
164 | Length = Data.Length;
165 | for (int i = 0; i < Data.Length; i++)
166 | {
167 | IntPtr pMessage = IntPtr.Add(MessagePtr, i * CONST.J2534MESSAGESIZE);
168 | Marshal.WriteInt32(pMessage, protocolID);
169 | Marshal.WriteInt32(pMessage, 8, (int)TxFlags);
170 | marshalIEnumerableToHeapData(pMessage, Data[i]);
171 | }
172 | }
173 | public static explicit operator IntPtr(HeapMessageArray HeapMessageArray)
174 | {
175 | return HeapMessageArray.Ptr;
176 | }
177 | protected override void DisposeUnmanaged()
178 | {
179 | Marshal.FreeHGlobal(LengthPtr);
180 | }
181 | }
182 | }
183 |
--------------------------------------------------------------------------------
/Src/API_Delegates.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | /*
23 | * Copyright (c) 2010, Michael Kelly
24 | * michael.e.kelly@gmail.com
25 | * http://michael-kelly.com/
26 | *
27 | * All rights reserved.
28 | * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
29 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
30 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
31 | * Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
32 | *
33 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
34 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
35 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
36 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
37 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 | *
45 | */
46 | #endregion License
47 | using System;
48 | using System.Runtime.InteropServices;
49 |
50 | namespace SAE.J2534
51 | {
52 | public partial class API
53 | {
54 | internal PassThruConnect PTConnect = delegate (int DeviceID, int ProtocolID, int ConnectFlags, int Baud, IntPtr ChannelID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
55 | internal PassThruDisconnect PTDisconnect = delegate (int channelId) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
56 | internal PassThruReadMsgs PTReadMsgs = delegate (int ChannelID, IntPtr pMsgArray, IntPtr NumMsgs, int Timeout) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
57 | internal PassThruWriteMsgs PTWriteMsgs = delegate (int ChannelID, IntPtr pMsgArray, IntPtr NumMsgs, int Timeout) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
58 | internal PassThruStartPeriodicMsg PTStartPeriodicMsg = delegate (int ChannelID, IntPtr pMsg, IntPtr MsgID, int Interval) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
59 | internal PassThruStopPeriodicMsg PTStopPeriodicMsg = delegate (int ChannelID, int MsgID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
60 | internal PassThruStartMsgFilter PTStartMsgFilter = delegate (
61 | int ChannelID,
62 | int FilterType,
63 | IntPtr pMaskMsg,
64 | IntPtr pPatternMsg,
65 | IntPtr pFlowControlMsg,
66 | IntPtr FilterID
67 | ) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
68 | internal PassThruStopMsgFilter PTStopMsgFilter = delegate (int ChannelID, int FilterID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
69 | internal PassThruSetProgrammingVoltage PTSetProgrammingVoltage = delegate (int DeviceID, int Pin, int Voltage) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
70 | internal PassThruReadVersion PTReadVersion = delegate (int DeviceID, IntPtr pFirmwareVer, IntPtr pDllVer, IntPtr pAPIVer) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
71 | internal PassThruGetLastError PTGetLastError = delegate (IntPtr pErr) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
72 | internal PassThruIoctl PTIoctl = delegate (int HandleID, int IoctlID, IntPtr Input, IntPtr Output) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
73 | //v2.02
74 | internal PassThruConnectv202 PTConnectv202 = delegate (int ProtocolID, int ConnectFlags, IntPtr ChannelID) { return ResultCode.FUNCTION_NOT_ASSIGNED; } ;
75 | internal PassThruSetProgrammingVoltagev202 PTSetProgrammingVoltagev202 = delegate (int Pin, int Voltage) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
76 | internal PassThruReadVersionv202 PTReadVersionv202 = delegate (IntPtr pFirmwareVer, IntPtr pDllVer, IntPtr pAPIVer) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
77 | //v4.04
78 | internal PassThruOpen PTOpen = delegate (IntPtr pDeviceName, IntPtr DeviceID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
79 | internal PassThruClose PTClose = delegate (int DeviceID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
80 | //v5.00 and undocumented Drewtech calls
81 | internal PassThruScanForDevices PTScanForDevices = delegate (ref int DeviceCount) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
82 | internal PassThruGetNextDevice PTGetNextDevice = delegate (IntPtr pSDevice) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
83 | internal PassThruLogicalConnect PTLogicalConnect = delegate (int PhysicalChannelID, int ProtocolID, int ConnectFlags, IntPtr ChannelDescriptor, ref int pChannelID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
84 | internal PassThruLogicalDisconnect PTLogicalDisconnect = delegate (int pChannelID) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
85 | internal PassThruSelect PTSelect = delegate (IntPtr pSChannelSet, int SelectType, int Timeout) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
86 | internal PassThruQueueMsgs PTQueueMsgs = delegate (int ChannelID, IntPtr pMsgArray, ref int NumMsgs) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
87 | //Drewtech ONLY
88 | internal PassThruGetNextCarDAQ PTGetNextCarDAQ = delegate (IntPtr pName, IntPtr pVer, IntPtr pAddress) { return ResultCode.FUNCTION_NOT_ASSIGNED; };
89 |
90 | private API_Signature AssignDelegates()
91 | {
92 | if (pLibrary == IntPtr.Zero)
93 | return APISignature;
94 |
95 | IntPtr pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruOpen");
96 | if (pFunction != IntPtr.Zero)
97 | {
98 | PTOpen = Marshal.GetDelegateForFunctionPointer(pFunction);
99 | APISignature.SAE_API |= SAE_API.OPEN;
100 | }
101 | else
102 | PTOpen = Open_shim;
103 |
104 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruClose");
105 | if (pFunction != IntPtr.Zero)
106 | {
107 | PTClose = Marshal.GetDelegateForFunctionPointer(pFunction);
108 | APISignature.SAE_API |= SAE_API.CLOSE;
109 | }
110 | else
111 | PTClose = Close_shim;
112 |
113 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruConnect");
114 | if (pFunction != IntPtr.Zero)
115 | {
116 | //If the API is v4.04 (because it has 'PassThruOpen')
117 | if (APISignature.SAE_API.HasFlag(SAE_API.OPEN))
118 | //Make 'Connect' work directly with the library function
119 | PTConnect = Marshal.GetDelegateForFunctionPointer(pFunction);
120 | else
121 | {
122 | //Otherwise, use the v202 prototype and wrap it with the v404 call
123 | PTConnectv202 = Marshal.GetDelegateForFunctionPointer(pFunction);
124 | PTConnect = Connect_shim;
125 | }
126 | APISignature.SAE_API |= SAE_API.CONNECT;
127 | }
128 |
129 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruDisconnect");
130 | if (pFunction != IntPtr.Zero)
131 | {
132 | PTDisconnect = Marshal.GetDelegateForFunctionPointer(pFunction);
133 | APISignature.SAE_API |= SAE_API.DISCONNECT;
134 | }
135 |
136 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruReadMsgs");
137 | if (pFunction != IntPtr.Zero)
138 | {
139 | PTReadMsgs = Marshal.GetDelegateForFunctionPointer(pFunction);
140 | APISignature.SAE_API |= SAE_API.READMSGS;
141 | }
142 |
143 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruWriteMsgs");
144 | if (pFunction != IntPtr.Zero)
145 | {
146 | PTWriteMsgs = Marshal.GetDelegateForFunctionPointer(pFunction);
147 | APISignature.SAE_API |= SAE_API.WRITEMSGS;
148 | }
149 |
150 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruStartPeriodicMsg");
151 | if (pFunction != IntPtr.Zero)
152 | {
153 | PTStartPeriodicMsg = Marshal.GetDelegateForFunctionPointer(pFunction);
154 | APISignature.SAE_API |= SAE_API.STARTPERIODICMSG;
155 | }
156 |
157 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruStopPeriodicMsg");
158 | if (pFunction != IntPtr.Zero)
159 | {
160 | PTStopPeriodicMsg = Marshal.GetDelegateForFunctionPointer(pFunction);
161 | APISignature.SAE_API |= SAE_API.STOPPERIODICMSG;
162 | }
163 |
164 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruStartMsgFilter");
165 | if (pFunction != IntPtr.Zero)
166 | {
167 | PTStartMsgFilter = Marshal.GetDelegateForFunctionPointer(pFunction);
168 | APISignature.SAE_API |= SAE_API.STARTMSGFILTER;
169 | }
170 |
171 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruStopMsgFilter");
172 | if (pFunction != IntPtr.Zero)
173 | {
174 | PTStopMsgFilter = Marshal.GetDelegateForFunctionPointer(pFunction);
175 | APISignature.SAE_API |= SAE_API.STOPMSGFILTER;
176 | }
177 |
178 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruSetProgrammingVoltage");
179 | if (pFunction != IntPtr.Zero)
180 | {
181 | //If the API is v4.04 (because it has 'PassThruOpen')
182 | if (APISignature.SAE_API.HasFlag(SAE_API.OPEN))
183 | //Make 'Connect' work directly with the library function
184 | PTSetProgrammingVoltage = Marshal.GetDelegateForFunctionPointer(pFunction);
185 | else
186 | {
187 | //Otherwise, use the v202 prototype and wrap it with the v404 call
188 | PTSetProgrammingVoltagev202 = Marshal.GetDelegateForFunctionPointer(pFunction);
189 | PTSetProgrammingVoltage = SetVoltage_shim;
190 | }
191 | APISignature.SAE_API |= SAE_API.SETPROGRAMMINGVOLTAGE;
192 | }
193 |
194 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruReadVersion");
195 | if (pFunction != IntPtr.Zero)
196 | {
197 | //If the API is v4.04 (because it has 'PassThruOpen')
198 | if (APISignature.SAE_API.HasFlag(SAE_API.OPEN))
199 | //Make 'Connect' work directly with the library function
200 | PTReadVersion = Marshal.GetDelegateForFunctionPointer(pFunction);
201 | else
202 | {
203 | //Otherwise, use the v202 prototype and wrap it with the v404 call
204 | PTReadVersionv202 = Marshal.GetDelegateForFunctionPointer(pFunction);
205 | PTReadVersion = ReadVersion_shim;
206 | }
207 | APISignature.SAE_API |= SAE_API.READVERSION;
208 | }
209 |
210 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruGetLastError");
211 | if (pFunction != IntPtr.Zero)
212 | {
213 | PTGetLastError = Marshal.GetDelegateForFunctionPointer(pFunction);
214 | APISignature.SAE_API |= SAE_API.GETLASTERROR;
215 | }
216 |
217 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruIoctl");
218 | if (pFunction != IntPtr.Zero)
219 | {
220 | PTIoctl = Marshal.GetDelegateForFunctionPointer(pFunction);
221 | APISignature.SAE_API |= SAE_API.IOCTL;
222 | }
223 |
224 | //v5.00
225 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruScanForDevices");
226 | if (pFunction != IntPtr.Zero)
227 | {
228 | PTScanForDevices = Marshal.GetDelegateForFunctionPointer(pFunction);
229 | APISignature.SAE_API |= SAE_API.SCANFORDEVICES;
230 | }
231 |
232 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruGetNextDevice");
233 | if (pFunction != IntPtr.Zero)
234 | {
235 | PTGetNextDevice = Marshal.GetDelegateForFunctionPointer(pFunction);
236 | APISignature.SAE_API |= SAE_API.GETNEXTDEVICE;
237 | }
238 |
239 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruLogicalConnect");
240 | if (pFunction != IntPtr.Zero)
241 | {
242 | PTLogicalConnect = Marshal.GetDelegateForFunctionPointer(pFunction);
243 | APISignature.SAE_API |= SAE_API.LOGICALCONNECT;
244 | }
245 |
246 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruLogicalDisconnect");
247 | if (pFunction != IntPtr.Zero)
248 | {
249 | PTLogicalDisconnect = Marshal.GetDelegateForFunctionPointer(pFunction);
250 | APISignature.SAE_API |= SAE_API.LOGICALDISCONNECT;
251 | }
252 |
253 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruSelect");
254 | if (pFunction != IntPtr.Zero)
255 | {
256 | PTSelect = Marshal.GetDelegateForFunctionPointer(pFunction);
257 | APISignature.SAE_API |= SAE_API.SELECT;
258 | }
259 |
260 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruQueueMsgs");
261 | if (pFunction != IntPtr.Zero)
262 | {
263 | PTQueueMsgs = Marshal.GetDelegateForFunctionPointer(pFunction);
264 | APISignature.SAE_API |= SAE_API.QUEUEMESSAGES;
265 | }
266 |
267 | pFunction = Kernal32.GetProcAddress(pLibrary, "PassThruGetNextCarDAQ");
268 | if (pFunction != IntPtr.Zero)
269 | {
270 | PTGetNextCarDAQ = Marshal.GetDelegateForFunctionPointer(pFunction);
271 | APISignature.DREWTECH_API |= DrewTech_API.GETNEXTCARDAQ;
272 | }
273 |
274 | return APISignature;
275 | }
276 | }
277 | }
278 |
--------------------------------------------------------------------------------
/Src/Channel.cs:
--------------------------------------------------------------------------------
1 | #region License
2 | /*Copyright(c) 2023, Brian Humlicek
3 | * https://github.com/BrianHumlicek
4 | *
5 | *Permission is hereby granted, free of charge, to any person obtaining a copy
6 | *of this software and associated documentation files (the "Software"), to deal
7 | *in the Software without restriction, including without limitation the rights
8 | *to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
9 | *copies of the Software, and to permit persons to whom the Software is
10 | *furnished to do so, subject to the following conditions:
11 | *The above copyright notice and this permission notice shall be included in all
12 | *copies or substantial portions of the Software.
13 | *
14 | *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | *IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | *FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | *AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | *LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | *OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | *SOFTWARE.
21 | */
22 | #endregion License
23 | using System;
24 | using System.Collections.Generic;
25 | using System.Linq;
26 |
27 | namespace SAE.J2534
28 | {
29 | public class Channel : Common.ManagedDisposable
30 | {
31 | private object sync { get; }
32 | private int channelId;
33 | private HeapMessageArray hJ2534MessageArray { get; }
34 | private List periodicMsgList { get; } = new List();
35 | private List filterList { get; } = new List();
36 | internal API API { get; }
37 | internal Device Device { get; }
38 | public Protocol ProtocolID { get; }
39 | public ConnectFlag ConnectFlags { get; }
40 | public IList PeriodicMsgList { get { return periodicMsgList.AsReadOnly(); } }
41 | public IList FilterList { get { return filterList.AsReadOnly(); } }
42 | public int DefaultTxTimeout { get; set; }
43 | public int DefaultRxTimeout { get; set; }
44 | public TxFlag DefaultTxFlag { get; set; }
45 |
46 | internal Channel(Device Device, Protocol ProtocolID, Baud Baud, ConnectFlag ConnectFlags, int ChannelID, object Sync)
47 | {
48 | sync = Sync;
49 | channelId = ChannelID;
50 | hJ2534MessageArray = new HeapMessageArray(ProtocolID, CONST.HEAPMESSAGEBUFFERSIZE);
51 | API = Device.API;
52 | this.Device = Device;
53 | this.ProtocolID = ProtocolID;
54 | this.ConnectFlags = ConnectFlags;
55 | DefaultTxTimeout = 100;
56 | DefaultRxTimeout = 300;
57 | DefaultTxFlag = TxFlag.NONE;
58 | }
59 | ///
60 | /// Gets a single message using the DefaultRxTimeout
61 | ///
62 | ///
63 | public GetMessageResults GetMessage()
64 | {
65 | return GetMessages(1, DefaultRxTimeout);
66 | }
67 |
68 | ///
69 | /// Reads 'NumMsgs' messages from the input buffer using the DefaultRxTimeout
70 | ///
71 | /// The number of messages to return. Due to timeout, the number of messages returned may be less than the number requested. Number must be less than or equal to J2534.CONST.HEAPMESSAGEBUFFERSIZE (default is 200)
72 | public GetMessageResults GetMessages(int NumMsgs)
73 | {
74 | return GetMessages(NumMsgs, DefaultRxTimeout);
75 | }
76 | ///
77 | /// Reads 'NumMsgs' messages from the input buffer.
78 | ///
79 | /// The number of messages to return. Due to timeout, the number of messages returned may be less than the number requested. Number must be less than or equal to J2534.CONST.HEAPMESSAGEBUFFERSIZE (default is 200)
80 | /// Timeout (in milliseconds) for read completion. A value of zero reads buffered messages and returns immediately. A non-zero value blocks (does not return) until the specified number of messages have been read, or until the timeout expires.
81 | public GetMessageResults GetMessages(int NumMsgs, int Timeout)
82 | {
83 | lock (sync)
84 | {
85 | hJ2534MessageArray.Length = NumMsgs;
86 | ResultCode Result = API.PTReadMsgs(channelId, (IntPtr)hJ2534MessageArray, hJ2534MessageArray.LengthPtr, Timeout);
87 | if(Result != ResultCode.TIMEOUT &&
88 | Result != ResultCode.BUFFER_EMPTY)
89 | {
90 | API.CheckResult(Result);
91 | }
92 | return new GetMessageResults(hJ2534MessageArray.ToMessageArray(), Result);
93 | }
94 | }
95 | ///
96 | /// Sends a single message 'Message' created from raw bytes
97 | ///
98 | /// Raw message bytes to send
99 | public void SendMessage(IEnumerable Message)
100 | {
101 | lock (sync)
102 | {
103 | hJ2534MessageArray.FromDataBytes(Message, DefaultTxFlag);
104 | SendMessages(hJ2534MessageArray);
105 | }
106 | }
107 | ///
108 | /// Sends an array of messages created from raw bytes
109 | ///
110 | /// Array of raw message bytes
111 | public void SendMessages(IEnumerable[] Messages)
112 | {
113 | lock (sync)
114 | {
115 | hJ2534MessageArray.FromDataBytesArray(Messages, DefaultTxFlag);
116 | SendMessages(hJ2534MessageArray);
117 | }
118 | }
119 | ///
120 | /// Sends a single J2534Message
121 | ///
122 | /// J2534Message
123 | public void SendMessage(Message Message)
124 | {
125 | lock (sync)
126 | {
127 | hJ2534MessageArray.FromMessage(Message);
128 | SendMessages(hJ2534MessageArray);
129 | }
130 | }
131 | ///
132 | /// Sends an array of J2534Messages
133 | ///
134 | /// J2534Message Array
135 | public void SendMessages(Message[] Messages)
136 | {
137 | lock (sync)
138 | {
139 | hJ2534MessageArray.FromMessageArray(Messages);
140 | SendMessages(hJ2534MessageArray);
141 | }
142 | }
143 | ///
144 | /// Sends the contents of a HeapMessageArray
145 | ///
146 | /// HeapMessageArray to send
147 | public void SendMessages(HeapMessageArray hJ2534MessageArray_Local)
148 | {
149 | lock (sync)
150 | API.CheckResult(API.PTWriteMsgs(channelId,
151 | (IntPtr)this.hJ2534MessageArray,
152 | hJ2534MessageArray_Local.LengthPtr,
153 | DefaultTxTimeout));
154 | }
155 | ///
156 | /// Starts automated periodic transmission of a message using the channel protocol
157 | ///
158 | /// Periodic message object
159 | /// Message index
160 | public int StartPeriodicMessage(PeriodicMessage PeriodicMessage)
161 | {
162 | return StartPeriodicMessage(PeriodicMessage, ProtocolID);
163 | }
164 | ///
165 | /// Starts automated periodic transmission of a message
166 | ///
167 | /// Periodic message object
168 | /// Periodic message protocol
169 | /// Message Id
170 | public int StartPeriodicMessage(PeriodicMessage PeriodicMessage, Protocol PeriodicMessageProtocolID)
171 | {
172 | using (HeapInt hMessageID = new HeapInt())
173 | using(HeapMessage hPeriodicMessage = new HeapMessage(PeriodicMessageProtocolID, PeriodicMessage))
174 | {
175 | lock (sync)
176 | {
177 | API.CheckResult(API.PTStartPeriodicMsg(channelId,
178 | (IntPtr)hPeriodicMessage,
179 | (IntPtr)hMessageID,
180 | PeriodicMessage.Interval));
181 | PeriodicMessage.MessageID = hMessageID.Value;
182 | periodicMsgList.Add(PeriodicMessage);
183 | }
184 | return PeriodicMessage.MessageID;
185 | }
186 | }
187 |
188 | ///
189 | /// Stops automated transmission of a periodic message.
190 | ///
191 | /// Message index
192 | public void StopPeriodicMsg(int MessageId)
193 | {
194 | lock (sync)
195 | {
196 | API.CheckResult(API.PTStopPeriodicMsg(channelId, MessageId));
197 | periodicMsgList.RemoveAll(m => m.MessageID == MessageId);
198 | }
199 | }
200 | ///
201 | /// Starts a message filter for the channel protocol
202 | ///
203 | /// Message filter object
204 | /// Filter Id
205 | public int StartMsgFilter(MessageFilter Filter)
206 | {
207 | return StartMsgFilter(Filter, ProtocolID);
208 | }
209 | ///
210 | /// Starts a message filter
211 | ///
212 | /// Message filter object
213 | /// Message filter protocol
214 | /// Filter Id
215 | public int StartMsgFilter(MessageFilter Filter, Protocol FilterProtocolID)
216 | {
217 | using (HeapInt hFilterID = new HeapInt())
218 | using (HeapMessage hMask = new HeapMessage(FilterProtocolID, Filter.TxFlags, Filter.Mask))
219 | using (HeapMessage hPattern = new HeapMessage(FilterProtocolID, Filter.TxFlags, Filter.Pattern))
220 | using (HeapMessage hFlowControl = new HeapMessage(FilterProtocolID, Filter.TxFlags, Filter.FlowControl))
221 | {
222 | lock (sync)
223 | {
224 | API.CheckResult(API.PTStartMsgFilter(channelId,
225 | (int)Filter.FilterType,
226 | (IntPtr)hMask,
227 | (IntPtr)hPattern,
228 | Filter.FilterType == J2534.Filter.FLOW_CONTROL_FILTER ? (IntPtr)hFlowControl : IntPtr.Zero,
229 | (IntPtr)hFilterID));
230 | Filter.FilterId = hFilterID.Value;
231 | filterList.Add(Filter);
232 | }
233 | return Filter.FilterId;
234 | }
235 | }
236 | ///
237 | /// Stops a message filter
238 | ///
239 | /// Filter Id
240 | public void StopMsgFilter(int FilterId)
241 | {
242 | lock (sync)
243 | {
244 | API.CheckResult(API.PTStopMsgFilter(channelId, FilterId));
245 | filterList.RemoveAll(f => f.FilterId == FilterId);
246 | }
247 | }
248 | ///
249 | /// Stops all message filters
250 | /// Alternative to ClearMsgFilters()
251 | ///
252 | public void StopAllMsgFilters()
253 | {
254 | lock (sync)
255 | {
256 | var filterIdList = filterList.Select(f => f.FilterId).ToList();
257 | foreach (int filterId in filterIdList)
258 | {
259 | StopMsgFilter(filterId);
260 | }
261 | }
262 | }
263 | ///
264 | /// Gets a configuration parameter for the channel
265 | ///
266 | /// Parameter to return
267 | /// Parameter value
268 | public int GetConfig(Parameter Parameter)
269 | {
270 | using (HeapSConfigArray hSConfigArray = new HeapSConfigArray(new SConfig(Parameter, 0)))
271 | {
272 | lock (sync)
273 | {
274 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.GET_CONFIG, (IntPtr)hSConfigArray, IntPtr.Zero));
275 | }
276 | return hSConfigArray[0].Value;
277 | }
278 | }
279 | ///
280 | /// Sets a configuration parameter for the channel
281 | ///
282 | /// Parameter to set
283 | /// Parameter value
284 | public void SetConfig(Parameter Parameter, int Value)
285 | {
286 | using (HeapSConfigArray hSConfigList = new HeapSConfigArray(new SConfig(Parameter, Value)))
287 | {
288 | lock (sync)
289 | {
290 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.SET_CONFIG, (IntPtr)hSConfigList, IntPtr.Zero));
291 | }
292 | }
293 | }
294 | ///
295 | /// Gets a list of configuration parameters for the channel
296 | ///
297 | /// List of parameters to get
298 | /// Parameter list
299 | public SConfig[] GetConfig(SConfig[] SConfig)
300 | {
301 | using (HeapSConfigArray hSConfigArray = new HeapSConfigArray(SConfig))
302 | {
303 | lock (sync)
304 | {
305 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.GET_CONFIG, (IntPtr)hSConfigArray, IntPtr.Zero));
306 | }
307 | return hSConfigArray.ToArray();
308 | }
309 | }
310 | ///
311 | /// Sets a list of configuration parameters for the channel
312 | ///
313 | /// List of parameters to set
314 | public void SetConfig(SConfig[] SConfig)
315 | {
316 | using (HeapSConfigArray hSConfigList = new HeapSConfigArray(SConfig))
317 | {
318 | lock (sync)
319 | {
320 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.SET_CONFIG, (IntPtr)hSConfigList, IntPtr.Zero));
321 | }
322 | }
323 | }
324 | ///
325 | /// Empties the transmit buffer for this channel
326 | ///
327 | public void ClearTxBuffer()
328 | {
329 | lock (sync)
330 | {
331 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.CLEAR_TX_BUFFER, IntPtr.Zero, IntPtr.Zero));
332 | }
333 | }
334 | ///
335 | /// Empties the receive buffer for this channel
336 | ///
337 | public void ClearRxBuffer()
338 | {
339 | lock (sync)
340 | {
341 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.CLEAR_RX_BUFFER, IntPtr.Zero, IntPtr.Zero));
342 | }
343 | }
344 | ///
345 | /// Stops and clears any periodic messages that have been configured for this channel
346 | ///
347 | public void ClearPeriodicMsgs()
348 | {
349 | lock (sync)
350 | {
351 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.CLEAR_PERIODIC_MSGS, IntPtr.Zero, IntPtr.Zero));
352 | }
353 | }
354 | ///
355 | /// Stops and clears any message filters that have been configured for this channel
356 | ///
357 | public void ClearMsgFilters()
358 | {
359 | lock (sync)
360 | {
361 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.CLEAR_MSG_FILTERS, IntPtr.Zero, IntPtr.Zero));
362 | filterList.Clear();
363 | }
364 | }
365 | ///
366 | /// Stops and clears all functional message address filters configured for this channel
367 | ///
368 | public void ClearFunctMsgLookupTable()
369 | {
370 | lock (sync)
371 | {
372 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.CLEAR_FUNCT_MSG_LOOKUP_TABLE, IntPtr.Zero, IntPtr.Zero));
373 | }
374 | }
375 | ///
376 | /// Starts a functional message address filter for this channel
377 | ///
378 | /// Address to pass
379 | public void AddToFunctMsgLookupTable(byte Addr)
380 | {
381 | using (HeapSByteArray hSByteArray = new HeapSByteArray(Addr))
382 | {
383 | lock (sync)
384 | {
385 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.ADD_TO_FUNCT_MSG_LOOKUP_TABLE, (IntPtr)hSByteArray, IntPtr.Zero));
386 | }
387 | }
388 | }
389 | ///
390 | /// Starts a list of functional message address filters for this channel
391 | ///
392 | /// Address list to pass
393 | public void AddToFunctMsgLookupTable(List AddressList)
394 | {
395 | using (HeapSByteArray hSByteArray = new HeapSByteArray(AddressList.ToArray()))
396 | {
397 | lock (sync)
398 | {
399 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.ADD_TO_FUNCT_MSG_LOOKUP_TABLE, (IntPtr)hSByteArray, IntPtr.Zero));
400 | }
401 | }
402 | }
403 | ///
404 | /// Stops and clears a single functional address message filter for this channel
405 | ///
406 | /// Address to remove
407 | public void DeleteFromFunctMsgLookupTable(byte Addr)
408 | {
409 | using (HeapSByteArray hSByteArray = new HeapSByteArray(Addr))
410 | {
411 | lock (sync)
412 | {
413 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE, (IntPtr)hSByteArray, IntPtr.Zero));
414 | }
415 | }
416 | }
417 | ///
418 | /// Stops and clears a list of functional address filters for this channel
419 | ///
420 | /// Address list to stop
421 | public void DeleteFromFunctMsgLookupTable(IEnumerable AddressList)
422 | {
423 | using (HeapSByteArray hSByteArray = new HeapSByteArray(AddressList.ToArray()))
424 | {
425 | lock (sync)
426 | {
427 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.DELETE_FROM_FUNCT_MSG_LOOKUP_TABLE, (IntPtr)hSByteArray, IntPtr.Zero));
428 | }
429 | }
430 | }
431 | ///
432 | /// Performs a 5 baud handshake for ISO9141 initialization
433 | ///
434 | /// Address to handshake with
435 | /// byte[2]
436 | public byte[] FiveBaudInit(byte TargetAddress)
437 | {
438 | using (HeapSByteArray hInput = new HeapSByteArray(new byte[] { TargetAddress }))
439 | using (HeapSByteArray hOutput = new HeapSByteArray(new byte[2]))
440 | {
441 | lock (sync)
442 | {
443 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.FIVE_BAUD_INIT, (IntPtr)hInput, (IntPtr)hOutput));
444 | }
445 | return hOutput.ToSByteArray();
446 | }
447 | }
448 | ///
449 | /// Performs a fast initialization sequence
450 | ///
451 | ///
452 | ///
453 | public Message FastInit(Message TxMessage)
454 | {
455 | using (HeapMessage hInput = new HeapMessage(ProtocolID, TxMessage.TxFlags, TxMessage.Data))
456 | using (HeapMessage hOutput = new HeapMessage(ProtocolID))
457 | {
458 | lock (sync)
459 | {
460 | API.CheckResult(API.PTIoctl(channelId, (int)IOCTL.FAST_INIT, (IntPtr)hInput, (IntPtr)hOutput));
461 | }
462 | return hOutput.ToMessage();
463 | }
464 | }
465 | ///
466 | /// Turns on the programming voltage for the device
467 | ///
468 | /// Pin number
469 | /// voltage (mV)
470 | public void SetProgrammingVoltage(Pin PinNumber, int Voltage)
471 | {
472 | Device.SetProgrammingVoltage(PinNumber, Voltage);
473 | }
474 | ///
475 | /// Measures the delivered programming voltage
476 | ///
477 | /// Voltage (mV)
478 | public int MeasureProgrammingVoltage()
479 | {
480 | return Device.MeasureProgrammingVoltage();
481 | }
482 | ///
483 | /// Measures the vehicle supply voltage
484 | ///
485 | /// Voltage (mV)
486 | public int MeasureBatteryVoltage()
487 | {
488 | return Device.MeasureBatteryVoltage();
489 | }
490 |
491 | protected override void DisposeManaged()
492 | {
493 | API.PTDisconnect(channelId);
494 | hJ2534MessageArray?.Dispose();
495 | }
496 | }
497 | }
498 |
--------------------------------------------------------------------------------