public void Close() { if (this.FThread != null) { this.PerformBlocking(() => { this.FIsClosing = true; if (!NativeFunctions.candle_dev_close(this.FDeviceHandle)) { NativeFunctions.throwError(this.FDeviceHandle); } }); // Close queues this.FActionQueue.CompleteAdding(); this.FActionQueue.Dispose(); this.FActionQueue = null; this.FExceptionQueue.CompleteAdding(); this.FExceptionQueue.Dispose(); this.FExceptionQueue = null; this.FThread.Join(); this.FThread = null; } }
public void Send(Frame frame) { var nativeFrame = new NativeFunctions.candle_frame_t(); nativeFrame.can_id = frame.Identifier; if (frame.Extended) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED; } if (frame.RTR) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_RTR; } if (frame.Error) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_ERR; } nativeFrame.data = new byte[8]; nativeFrame.can_dlc = (byte)frame.Data.Length; Buffer.BlockCopy(frame.Data, 0, nativeFrame.data, 0, frame.Data.Length); this.FDevice.Perform(() => { if (!NativeFunctions.candle_frame_send(this.FDevice.Handle, this.FChannelIndex, ref nativeFrame)) { NativeFunctions.throwError(this.FDevice.Handle); } }); }
public void SendOnChannel(Frame frame, byte channelIndex, bool blocking = false) { var nativeFrame = new NativeFunctions.candle_frame_t(); nativeFrame.can_id = frame.Identifier; if (frame.Extended) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_EXTENDED; } if (frame.RTR) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_RTR; } if (frame.Error) { nativeFrame.can_id |= (UInt32)NativeFunctions.candle_id_flags.CANDLE_ID_ERR; } nativeFrame.data = new byte[8]; nativeFrame.can_dlc = (byte)frame.Data.Length; Buffer.BlockCopy(frame.Data, 0, nativeFrame.data, 0, frame.Data.Length); var lengthOnBus = frame.LengthOnBus; this.PerformInRightThread(() => { if (!NativeFunctions.candle_frame_send(this.FDeviceHandle, channelIndex, ref nativeFrame)) { NativeFunctions.throwError(this.FDeviceHandle); } this.Channels[channelIndex].IncrementTx(lengthOnBus); }, blocking); }
public void Stop() { this.FDevice.PerformBlocking(() => { if (!NativeFunctions.candle_channel_stop(this.FDevice.Handle, this.FChannelIndex)) { NativeFunctions.throwError(this.FDevice.Handle); } }); }
public void SetBitrate(int value) { this.FDevice.PerformBlocking(() => { if (!NativeFunctions.candle_channel_set_bitrate(this.FDevice.Handle, this.FChannelIndex, (UInt32)value)) { NativeFunctions.throwError(this.FDevice.Handle); } }); }
public void SetTiming(NativeFunctions.candle_bittiming_t value) { this.FDevice.PerformBlocking(() => { if (!NativeFunctions.candle_channel_set_timing(this.FDevice.Handle, this.FChannelIndex, ref value)) { NativeFunctions.throwError(this.FDevice.Handle); } }); }
public void Start(int bitrate) { this.SetBitrate(bitrate); this.FDevice.PerformBlocking(() => { if (!NativeFunctions.candle_channel_start(this.FDevice.Handle, this.FChannelIndex, 0)) { NativeFunctions.throwError(this.FDevice.Handle); } }); }
virtual public void Start(int bitrate) { this.SetBitrate(bitrate); this.FDevice.PerformBlocking(() => { if (!NativeFunctions.candle_channel_start(this.FDevice.Handle, this.FChannelIndex, 0)) { NativeFunctions.throwError(this.FDevice.Handle); } }); this.FCounterLastTime = DateTime.Now; this.FCounterRxBits = 0; this.FCounterTxBits = 0; }
public virtual void Open() { this.Close(); if (!NativeFunctions.candle_dev_open(this.FDeviceHandle)) { NativeFunctions.throwError(this.FDeviceHandle); } // Create queues this.FActionQueue = new BlockingCollection <Action>(); this.FExceptionQueue = new BlockingCollection <Exception>(); // Flush Rx on device { NativeFunctions.candle_frame_t nativeFrame; while (NativeFunctions.candle_frame_read(this.FDeviceHandle , out nativeFrame , 0)) { } } // Setup device thread this.FIsClosing = false; this.FThread = new Thread(this.ThreadedUpdate); this.FThread.Name = String.Format("Candle {0}", this.FInstanceIndex); // List Channels this.FChannels.Clear(); byte channelCount; if (!NativeFunctions.candle_channel_count(this.FDeviceHandle, out channelCount)) { NativeFunctions.throwError(this.FDeviceHandle); } for (byte i = 0; i < channelCount; i++) { this.FChannels.Add(i, new Channel(this, i)); } // Start device thread this.FThread.Start(); }
public void Open() { this.Close(); if (!NativeFunctions.candle_dev_open(this.FDeviceHandle)) { NativeFunctions.throwError(this.FDeviceHandle); } // Create queues this.FActionQueue = new BlockingCollection <Action>(); this.FExceptionQueue = new BlockingCollection <Exception>(); // Start device thread this.FIsClosing = false; this.FThread = new Thread(this.ThreadedUpdate); this.FThread.Name = "Candle"; this.FThread.Start(); // List Channels this.FChannels.Clear(); byte channelCount; if (!NativeFunctions.candle_channel_count(this.FDeviceHandle, out channelCount)) { NativeFunctions.throwError(this.FDeviceHandle); } for (byte i = 0; i < channelCount; i++) { this.FChannels.Add(i, new Channel(this, i)); } this.FCounterLastTime = DateTime.Now; this.FCounterRxBits = 0; this.FCounterTxBits = 0; }