read
Add-On Required: This feature requires the MATLAB Support Package for Raspberry Pi Hardware add-on.
Description
reads a timetable of CAN messages equal to message
= read(ch
,numMessages
)numMessages
received on the
CAN channel ch
.
Examples
Read CAN Messages
Create a Raspberry Pi® object.
raspiObj = raspi("192.168.1.101","pi","raspberry");
Create a canChannel
object.
ch = canChannel(raspiObj,"can0");
Read messages as a timetable.
read(ch)
ans = 1×7 timetable Time ID Extended Name Data Length Signals Error ____________________ ___ ________ __________ ___________________ ______ ____________ _____ 08-Apr-2021 11:36:32 291 false {0×0 char} {[0 1 2 3 4 5 6 7]} 8 {0×0 struct} false
Read Specified Number of CAN Messages
Create a Raspberry Pi object.
raspiObj = raspi("192.168.1.101","pi","raspberry");
Create a canChannel
object.
ch = canChannel(raspiObj,"can0")
Specify the length of message to read.
read(ch,5)
ans = 5×7 timetable Time ID Extended Name Data Length Signals Error ____________________ ____ ________ __________ ___________________ ______ ____________ _____ 08-Apr-2021 11:37:42 291 false {0×0 char} {[0 1 2 3 4 5 6 7]} 8 {0×0 struct} false 08-Apr-2021 11:37:42 1110 true {0×0 char} {[7 6 5 4 3 2 1 0]} 8 {0×0 struct} false 08-Apr-2021 11:37:42 291 false {0×0 char} {[0 1 2 3 4 5 6 7]} 8 {0×0 struct} false 08-Apr-2021 11:37:42 1110 true {0×0 char} {[7 6 5 4 3 2 1 0]} 8 {0×0 struct} false 08-Apr-2021 11:37:42 291 false {0×0 char} {[0 1 2 3 4 5 6 7]} 8 {0×0 struct} false
Read CAN Messages with Database
Create a Raspberry Pi object.
raspiObj = raspi("192.168.1.101","pi","raspberry");
Create a canChannel
object.
ch = canChannel(raspiObj,"can0")
ch = Channel with properties: Interface: 'can0' ProtocolMode: 'CAN' BusSpeed: 500000 SilentMode: 0 Database: [] Show all properties
Attach a database.
ch.Database = canDatabase('test.dbc')
ch = Channel with properties: Interface: 'can0' ProtocolMode: 'CAN' BusSpeed: 500000 SilentMode: 0 Database: [1×1 can.Database] Show all properties
Read the can channel object.
read(ch,5)
ans = 5×8 timetable Time ID Extended Name Data Length Signals Error Remote ____________________ ____ ________ _______________________ ___________________ ______ ____________ _____ ______ 08-Apr-2021 11:39:24 291 false {'StandardTestMessage'} {[0 1 2 3 4 5 6 7]} 8 {1×1 struct} false false 08-Apr-2021 11:39:24 1110 true {'ExtendedTestMessage'} {[7 6 5 4 3 2 1 0]} 8 {1×1 struct} false false 08-Apr-2021 11:39:24 291 false {'StandardTestMessage'} {[0 1 2 3 4 5 6 7]} 8 {1×1 struct} false false 08-Apr-2021 11:39:24 1110 true {'ExtendedTestMessage'} {[7 6 5 4 3 2 1 0]} 8 {1×1 struct} false false 08-Apr-2021 11:39:24 291 false {'StandardTestMessage'} {[0 1 2 3 4 5 6 7]} 8 {1×1 struct} false false
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced in R2021b
See Also
disableCAN
| write
| enableCAN
| canChannel