Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

canChannel

Construct CAN channel connected to specified device

Syntax

canch = canChannel(vendor,device,devicechannelindex)
canch = canChannel(vendor,device)
canch = canChannel(___,'ProtocolMode','CAN FD')

Description

example

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

For Vector products, device is a character vector that combines the device type and a device index, such as 'CANCaseXL 1'. For example, if there are two CANcardXL devices, device can be 'CANcardXL 1' or 'CANcardXL 2'.

Use canch = canChannel(vendor,device) for National Instruments® and PEAK-System devices.

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.

Check the CAN Device Constructor in the canHWInfo display for channel construction.

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. Note that a channel configured for 'CAN' cannot transmit or receive CAN FD messages.

Examples

collapse all

Create CAN channels for each of several vendors.

canch1 = canChannel('Vector','CANCaseXL 1',1);
canch2 = canChannel('Vector','Virtual 1',2);
canch3 = canChannel('NI','CAN1');
canch4 = canChannel('PEAK-System','PCAN_USBBUS1');
canch5 = canChannel('MathWorks','Virtual 1',2)
 

canch5 = 

  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', 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 the following properties.

Can Channel Properties:

BusLoadLoad on CAN bus
DatabaseStore CAN database information
MessageReceivedFcnSpecify function to run
MessageReceivedFcnCountSpecify number of messages available before function is triggered
RunningDetermine status of channel
SilentModeSpecify if channel is active or silent
TransceiverNameName of device transceiver
TransceiverStateDisplay state or mode of transceiver
UserDataEnter custom data

CAN Device Properties:

DeviceDisplay channel device type
Device(NI)Display NI CAN channel device type
DeviceChannelIndexDisplay device channel index
DeviceSerialNumberDisplay device serial number
DeviceVendorDisplay device vendor name
InitializationAccessDetermine control of device channel

Bit Timing Properties:

BusSpeedBit rate of bus
NumOfSamplesDisplay number of samples available to channel
SJWSynchronization jump width (SJW) of bit time segment
TSEG1Display amount that channel can lengthen sample time
TSEG2Display amount that channel can shorten sample time

Tips

  • Use canHWInfo 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.

See Also

Functions

Introduced in R2009a

Was this topic helpful?