Class CanChannelModule
Represents a module for a channel of a VSCOM CAN adapter with VS CAN API. USB and Ethernet adapters are supported.
Implements
Inherited Members
Namespace: Loehnert.Lisrt.Can.VSCom
Assembly: Loehnert.Lisrt.Can.VSCom.dll
Syntax
public class CanChannelModule : LisrtModule, ILisrtModule, IInitializable, INotifyPropertyChangedEx, INotifyPropertyChanged, ICanCommunication, ICanCommunication2, IHasServiceView, IHasDeviceLabel
Remarks
The installation of the VSCOM driver is necessary.
Important
You cannot use the ICanCommunication and the ICanCommunication2 API of an instance at the same time.
Network CAN Adapter
Using a network CAN adapter, you have to configure the Driver Mode, the configuration is done via the web interface of the adapter. The Connection property has to be configured in this format: IP-address:port, the port is 2001 by default.
USB CAN Adapter
The Connection property must be the COM-port name. In order to achieve the maximum performance, the Latency Timer of the FTDI chip should be set to the smallest value. You adapt the Latency Timer via the Windows Device Manager -> Right click on the COM port -> Properties -> Port Settings -> Advanced.
Constructors
CanChannelModule(String)
Initializes a new instance of the CanChannelModule class.
Declaration
public CanChannelModule(string name)
Parameters
Type | Name | Description |
---|---|---|
String | name | Module name. |
Properties
BaudRate
Gets or sets the baud rate.
Declaration
[Configuration(0U, Unit = "Baud", Description = "20000, 50000, 100000, 125000, 250000 500000, 800000 or 1000000 Baud")]
public uint BaudRate { get; set; }
Property Value
Type | Description |
---|---|
System.UInt32 |
CommunicationLogIsEnabled
Gets or sets a value indicating whether the instance logs communication.
Declaration
[Configuration(true)]
public bool CommunicationLogIsEnabled { get; set; }
Property Value
Type | Description |
---|---|
Boolean |
Connection
Gets or sets the connection name of the device. This could be a serial number, COM port or network address with port.
Declaration
[Configuration("", Description = "Serial number, serial port or network address (Example: 192.168.100.51:2001).")]
public string Connection { get; set; }
Property Value
Type | Description |
---|---|
String |
DeviceLabel
Gets or sets the label for the device.
Declaration
[Configuration("")]
public string DeviceLabel { get; set; }
Property Value
Type | Description |
---|---|
String |
InitializationState
Gets the initialization state.
Declaration
public InitializationState InitializationState { get; }
Property Value
Type | Description |
---|---|
InitializationState |
InstanceID
Gets or sets the ID for this instance.
Declaration
public int InstanceID { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
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
Exit()
De initializes the module.
Declaration
public void Exit()
Initialize()
Initializes the module.
Declaration
public void Initialize()
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when Connection is null, empty or white space. |
System.InvalidOperationException | Thrown when the connection to the device is already open. |
System.ArgumentException | Thrown when BaudRate is not 20k, 50k, 100k, 125k, 250k 500k, 800k or 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 are received in the expected time range. See ReceiveTimeoutInMS. |
System.ArgumentNullException | Thrown when parameter |
NotInitializedException | Thrown when InitializationState is not Initialized. |
Receive()
Receives the data from the buffer. The buffer is cleared on Receive(), Send(CanData) and Query(CanData).
Declaration
public IEnumerable<CanData> Receive()
Returns
Type | Description |
---|---|
IEnumerable<CanData> | Received data. |
Exceptions
Type | Condition |
---|---|
NotInitializedException | Thrown when InitializationState is not Initialized. |
System.InvalidOperationException | Thrown when DataReceived has any event handler. |
Send(CanData)
Sends CanData.
Declaration
public void Send(CanData data)
Parameters
Type | Name | Description |
---|---|---|
CanData | data | Data to send. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | Thrown when |
NotInitializedException | Thrown when InitializationState is not 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 added, the Receive() method throws always an System.InvalidOperationException.