Beispiel #1
0
 /// <summary>
 /// Opens a J2534 device using this API
 /// </summary>
 /// <param name="DeviceName">The name of the device or blank to open the first available</param>
 /// <returns>Device object</returns>
 public Device GetDevice(string DeviceName = "")
 {
     using (var hDeviceID = new HeapInt())
         using (var hDeviceName = new HeapString(DeviceName))
         {
             lock (sync)
             {
                 CheckResult(PTOpen(String.IsNullOrWhiteSpace(DeviceName) ? IntPtr.Zero : (IntPtr)hDeviceName, (IntPtr)hDeviceID));
             }
             var device = new Device(this, hDeviceName.ToString(), hDeviceID.Value, sync);
             OnDisposing += device.Dispose;
             return(device);
         }
 }
Beispiel #2
0
        internal Device(API API, string DeviceName, int DeviceID, object Sync)
        {
            this.API        = API;
            this.DeviceName = DeviceName;
            deviceId        = DeviceID;
            sync            = Sync;

            using (var hFirmwareVersion = new HeapString(80))
                using (var hDllVersion = new HeapString(80))
                    using (var hApiVersion = new HeapString(80))
                    {
                        lock (Sync)
                        {
                            API.CheckResult(API.PTReadVersion(DeviceID, (IntPtr)hFirmwareVersion, (IntPtr)hDllVersion, (IntPtr)hApiVersion));
                        }
                        FirmwareVersion = hFirmwareVersion.ToString();
                        DriverVersion   = hDllVersion.ToString();
                        APIVersion      = hApiVersion.ToString();
                    }
        }
Beispiel #3
0
        internal string GetLastError()  //Should never be called outside of API_LOCK
        {
            ResultCode Result;

            using (var hErrorDescription = new HeapString(80))
            {
                lock (sync)
                {
                    Result = PTGetLastError((IntPtr)hErrorDescription);
                    if (Result == ResultCode.STATUS_NOERROR)
                    {
                        return(hErrorDescription.ToString());
                    }
                    else
                    {
                        return($"GetLastError failed with result: {Result.ToString()}");
                    }
                }
            }
        }