Class CanChannelModule
Represents a module for a Vector CAN channel with VXL API. Warning: You cannot use the interfaces Loehnert.Lisrt.Communication.Can.ICanCommunication and ICanCommunication2 at the same time on one instance.
Implements
Inherited Members
Namespace: Loehnert.Lisrt.Can.Vector
Assembly: Loehnert.Lisrt.Can.Vector.dll
Syntax
public class CanChannelModule : LisrtModule, ILisrtModule, IInitializable, INotifyPropertyChangedEx, INotifyPropertyChanged, ICanCommunication, ICanCommunication2, IHasServiceView
Constructors
CanChannelModule(String)
Initializes a new instance of the CanChannelModule class.
Declaration
public CanChannelModule(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | CAN channel name. |
Properties
BaudRate
Gets or sets the baud rate.
Declaration
[Configuration(0U, Unit = "Baud", Description = "15k to 1M Baud")]
public uint BaudRate { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 |
ChannelIndex
Gets or sets the device depending channel index.
Declaration
[Configuration((byte)0)]
public byte ChannelIndex { get; set; }
Property Value
Type | Description |
---|---|
System.Byte |
ChannelName
Gets the channel name. Available after Initialize() or SetChannel(ChannelInfo). To get the unique channel identification use DeviceSerial and ChannelIndex.
Declaration
public string ChannelName { get; }
Property Value
Type | Description |
---|---|
String |
DataReceivedAutoResetEvent
Gets the auto reset event for received data.
Declaration
protected AutoResetEvent DataReceivedAutoResetEvent { get; }
Property Value
Type | Description |
---|---|
AutoResetEvent |
DataTransmittedAutoResetEvent
Gets the auto reset event for successfully transmitted data.
Declaration
protected AutoResetEvent DataTransmittedAutoResetEvent { get; }
Property Value
Type | Description |
---|---|
AutoResetEvent |
DeviceSerial
Gets or sets the device serial.
Declaration
[Configuration(0U)]
public uint DeviceSerial { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 |
Icon
Gets a icon which is representative for the module.
Declaration
public override Uri Icon { get; }
Property Value
Type | Description |
---|---|
Uri |
Overrides
InitializationState
Gets a value indicating whether the module is initialized.
Declaration
public InitializationState InitializationState { get; }
Property Value
Type | Description |
---|---|
InitializationState |
ReceivedBuffer
Gets the latest received data. Cleared on ClearBuffer(), Receive(), Send(CanData) and Query(CanData).
Declaration
protected IList<CanData> ReceivedBuffer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IList<CanData> |
ReceiveTimeoutInMS
Gets or sets the receive timeout in milliseconds. Default is 200ms.
Declaration
public int ReceiveTimeoutInMS { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Methods
ClearBuffer()
Clears the received data buffer.
Declaration
protected void ClearBuffer()
Exit()
De initializes the module.
Declaration
public void Exit()
GetPossibleCanChannels()
Gets all possible CAN channels.
Declaration
public IEnumerable<ChannelInfo> GetPossibleCanChannels()
Returns
Type | Description |
---|---|
IEnumerable<ChannelInfo> | All CAN channels. |
Initialize()
Initializes the module.
Declaration
public void Initialize()
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when channel is not found. |
System.ArgumentException | Thrown when BaudRate is not between 15k to 1M baud. |
Query(CanData)
Sends and receives data.
Declaration
public IEnumerable<CanData> Query(CanData data)
Parameters
Type | Name | Description |
---|---|---|
CanData | data | Data to send. |
Returns
Type | Description |
---|---|
IEnumerable<CanData> | Received data. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when DataReceived has any event handler. |
System.TimeoutException | Thrown when no data received in the expected time range. |
System.ArgumentNullException | Thrown when |
System.InvalidOperationException | Thrown when InitializationState is not Initialized. |
System.TimeoutException | Thrown when no bus device acknowledged the transmission in the expected time range or not data is received in the expected time range. |
Receive()
Receives the data from the buffer. The buffer is cleared on ClearBuffer(), Receive(), Send(CanData) and Query(CanData).
Declaration
public IEnumerable<CanData> Receive()
Returns
Type | Description |
---|---|
IEnumerable<CanData> | Received data. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when InitializationState is not Initialized. |
System.InvalidOperationException | Thrown when DataReceived has any event handler. |
Send(CanData)
Sends CanData to a device.
Declaration
public void Send(CanData data)
Parameters
Type | Name | Description |
---|---|---|
CanData | data | Data to send. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
System.InvalidOperationException | Thrown when InitializationState is not Initialized. |
System.TimeoutException | Thrown when no bus device acknowledged the transmission in the expected time range. |
SetChannel(ChannelInfo)
Sets the channel with the channelInfo
.
Declaration
public void SetChannel(ChannelInfo channelInfo)
Parameters
Type | Name | Description |
---|---|---|
ChannelInfo | channelInfo | Channel info to set. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | Thrown when InitializationState is Initialized. |
ShowServiceView()
Shows the service window.
Declaration
public void ShowServiceView()
Events
DataReceived
Occurs when data are received.
Declaration
public event EventHandler DataReceived
Event Type
Type | Description |
---|---|
System.EventHandler |
Explicit Interface Implementations
ICanCommunication2.DataReceived
Occurs when data are received.
Declaration
event EventHandler<CanDataReceivedEventArgs> ICanCommunication2.DataReceived
Returns
Type | Description |
---|---|
System.EventHandler<CanDataReceivedEventArgs> |
Remarks
If any event handler is add, Receive() will always throw a System.InvalidOperationException.