/// <summary> /// Measures the vehicle supply voltage /// </summary> /// <returns>Voltage (mV)</returns> public int MeasureBatteryVoltage() { using (HeapInt hVoltage = new HeapInt()) { lock (sync) { API.CheckResult(API.PTIoctl(deviceId, (int)IOCTL.READ_VBATT, IntPtr.Zero, (IntPtr)hVoltage)); } return(hVoltage.Value); } }
/// <summary> /// Measures the delivered programming voltage /// </summary> /// <returns>Voltage (mV)</returns> public int MeasureProgrammingVoltage() { using (HeapInt hVoltage = new HeapInt()) { lock (sync) { API.CheckResult(API.PTIoctl(deviceId, (int)IOCTL.READ_PROG_VOLTAGE, IntPtr.Zero, (IntPtr)hVoltage)); } return(hVoltage.Value); } }
/// <summary> /// Opens a channel on the device using the specified parameters /// </summary> /// <param name="ProtocolID">Connection protocol</param> /// <param name="Baud">Connection baud-rate</param> /// <param name="ConnectFlags">Connection flags</param> /// <returns>A connected J2534Channel object</returns> public Channel GetChannel(Protocol ProtocolID, Baud Baud, ConnectFlag ConnectFlags, bool ChannelLevelSync = false) { using (HeapInt hChannelID = new HeapInt()) { lock (sync) { API.CheckResult(API.PTConnect(deviceId, (int)ProtocolID, (int)ConnectFlags, (int)Baud, (IntPtr)hChannelID)); } var NewChannel = new Channel(this, ProtocolID, Baud, ConnectFlags, hChannelID.Value, ChannelLevelSync ? new object() : sync); OnDisposing += NewChannel.Dispose; return(NewChannel); } }
/// <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); } }
/// <summary> /// Starts automated periodic transmission of a message /// </summary> /// <param name="PeriodicMessage">Periodic message object</param> /// <returns>Message index</returns> public int StartPeriodicMessage(PeriodicMessage PeriodicMessage) { using (HeapInt hMessageID = new HeapInt()) using (HeapMessage hPeriodicMessage = new HeapMessage(ProtocolID, PeriodicMessage)) { lock (sync) { API.CheckResult(API.PTStartPeriodicMsg(channelId, (IntPtr)hPeriodicMessage, (IntPtr)hMessageID, PeriodicMessage.Interval)); PeriodicMessage.MessageID = hMessageID.Value; periodicMsgList.Add(PeriodicMessage); } return(periodicMsgList.IndexOf(PeriodicMessage)); } }
/// <summary> /// Starts a message filter /// </summary> /// <param name="Filter">Message filter object</param> /// <returns>Filter index</returns> public int StartMsgFilter(MessageFilter Filter) { using (HeapInt hFilterID = new HeapInt()) using (HeapMessage hMask = new HeapMessage(ProtocolID, Filter.TxFlags, Filter.Mask)) using (HeapMessage hPattern = new HeapMessage(ProtocolID, Filter.TxFlags, Filter.Pattern)) using (HeapMessage hFlowControl = new HeapMessage(ProtocolID, Filter.TxFlags, Filter.FlowControl)) { lock (sync) { API.CheckResult(API.PTStartMsgFilter(channelId, (int)Filter.FilterType, (IntPtr)hMask, (IntPtr)hPattern, Filter.FilterType == J2534.Filter.FLOW_CONTROL_FILTER ? (IntPtr)hFlowControl : IntPtr.Zero, (IntPtr)hFilterID)); Filter.FilterId = hFilterID.Value; filterList.Add(Filter); } return(filterList.IndexOf(Filter)); } }