Main Content

canChannel

Construct CAN channel connected to specified device

Description

canch = canChannel(vendor,device,chanindex) returns a CAN channel connected to a device from a specified vendor.

For Kvaser and Vector products, device is a character vector or string that combines the device model and a device index in the same argument, such as 'VN1610 1' or 'VN1610 2' to distinguish one device from another. You can also choose among two MathWorks® virtual devices, each with two virtual channels.

example

canch = canChannel(vendor,device) returns a CAN channel connected to a National Instruments™ or PEAK-System device.

For National Instruments, vendor is the character vector 'NI', and the devicenumber is interface number defined in the NI Measurement & Automation Explorer.

For PEAK-System devices vendor is the character vector 'PEAK-System', and the devicenumber is device number defined for the channel.

example

canch = canChannel(___,'ProtocolMode','CAN FD') returns a channel connected to a device supporting CAN FD. The default ProtocolMode setting is 'CAN', indicating standard CAN support. A channel configured for 'CAN' cannot transmit or receive CAN FD messages.

example

Examples

collapse all

Create CAN channels for several vendors.

canch1 = canChannel('Vector','VN1610 1',1);
canch2 = canChannel('Vector','Virtual 1',2);
canch3 = canChannel('Kvaser','USBcan Pro 1',1);
canch4 = canChannel('NI','CAN1');
canch5 = canChannel('PEAK-System','PCAN_USBBUS1');
canch6 = canChannel('SocketCAN','can0');
canch7 = canChannel('MathWorks','Virtual 1',2)
canch7 = 

  Channel with properties:

   Device Information
            DeviceVendor: 'MathWorks'
                  Device: 'Virtual 1'
      DeviceChannelIndex: 2
      DeviceSerialNumber: 0
            ProtocolMode: 'CAN'

   Status Information
                 Running: 0
       MessagesAvailable: 0
        MessagesReceived: 0
     MessagesTransmitted: 0
    InitializationAccess: 1
        InitialTimestamp: [0×0 datetime]
           FilterHistory: 'Standard ID Filter: Allow All | Extended ID Filter: Allow All'

   Channel Information
               BusStatus: 'N/A'
              SilentMode: 0
         TransceiverName: 'N/A'
        TransceiverState: 'N/A'
       ReceiveErrorCount: 0
      TransmitErrorCount: 0
                BusSpeed: 500000
                     SJW: []
                   TSEG1: []
                   TSEG2: []
            NumOfSamples: []

   Other Information
                Database: []
                UserData: []

Create a CAN FD channel on a MathWorks virtual device.

canch6 = canChannel('MathWorks','Virtual 1',2,'ProtocolMode','CAN FD')
canch6 = 

  Channel with properties:

   Device Information
            DeviceVendor: 'MathWorks'
                  Device: 'Virtual 1'
      DeviceChannelIndex: 2
      DeviceSerialNumber: 0
            ProtocolMode: 'CAN FD'

   Status Information
                 Running: 0
       MessagesAvailable: 0
        MessagesReceived: 0
     MessagesTransmitted: 0
    InitializationAccess: 1
        InitialTimestamp: [0×0 datetime]
           FilterHistory: 'Standard ID Filter: Allow All | Extended ID Filter: Allow All'

   Bit Timing Information
               BusStatus: 'N/A'
              SilentMode: 0
         TransceiverName: 'N/A'
        TransceiverState: 'N/A'
       ReceiveErrorCount: 0
      TransmitErrorCount: 0
     ArbitrationBusSpeed: []
            DataBusSpeed: []

   Other Information
                Database: []
                UserData: []

Input Arguments

collapse all

CAN device vendor, specified as 'MathWorks', 'Kvaser', 'NI', 'PEAK-System', 'SocketCAN', or 'Vector'.

Example: 'MathWorks'

Data Types: char | string

CAN device to connect channel to, specified as a character vector or string. Valid values depend on the specified vendor.

Example: 'Virtual 1'

Data Types: char | string

CAN device channel port or index, specified as a numeric value.

Example: 1

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

CAN device channel, returned as a can.Channel object, with can.Channel Properties.

Tips

  • Use canChannelList to obtain a list of available devices.

  • You cannot have more than one canChannel configured on the same NI-XNET or PEAK-System device channel.

  • You cannot use the same variable to create multiple channels sequentially. Clear any channel in use before using the same variable to construct a new CAN channel.

  • You cannot create arrays of CAN channel objects. Each object you create must exist as its own individual variable.

Version History

Introduced in R2009a