Multiplex Signals
Use multiplexing to represent multiple signals in one signal’s location in a CAN message’s data. A multiplexed message can have three types of signals:
Standard signal — This signal is always active. You can create one or more standard signals.
Multiplexor signal — Also called the mode signal, it is always active and its value determines which multiplexed signal is currently active in the message data. You can create only one multiplexor signal per message.
Multiplexed signal — This signal is active when its multiplex value matches the value of the multiplexor signal. You can create one or more multiplexed signals in a message.
Multiplexing works only with a CAN database with message definitions that already contain multiplex signal information. This example shows you how to access the different multiplex signals using a database constructed specifically for this purpose. This database has one message with these signals:
SigA
— A multiplexed signal with a multiplex value of0
.SigB
— Another multiplexed signal with a multiplex value of1
.MuxSig
— A multiplexor signal, whose value determines which of the two multiplexed signals are active in the message.
For example,
Create a CAN database.
d = canDatabase('Mux.dbc')
Note
This is an example database constructed for creating multiplex messages. To try this example, use your own database.
Create a CAN message.
m = canMessage(d,'Msg')
m = can.Message handle Package: can Properties: ID: 250 Extended: 0 Name: 'Msg' Database: [1x1 can.Database] Error: 0 Remote: 0 Timestamp: 0 Data: [0 0 0 0 0 0 0 0] Signals: [1x1 struct] Methods, Events, Superclasses
To display the signals, type:
m.Signals
ans = SigB: 0 SigA: 0 MuxSig: 0
MuxSig
is the multiplexor signal, whose value determines which of the two multiplexed signals are active in the message.SigA
andSigB
are the multiplexed signals that are active in the message if their multiplex values matchMuxSig
. In the example shown,SigA
is active because its current multiplex value of0
matches the value ofMuxSig
(which is0
).If you want to make
SigB
active, change the value of theMuxSig
to1
.m.Signals.MuxSig = 1
To display the signals, type:
m.Signals
ans = SigB: 0 SigA: 0 MuxSig: 1
SigB
is now active because its multiplex value of1
matches the current value ofMuxSig
(which is1
).Change the value of
MuxSig
to2
.m.Signals.MuxSig = 2
Here, neither of the multiplexed signals are active because the current value of
MuxSig
does not match the multiplex value of eitherSigA
orSigB
.m.Signals
ans = SigB: 0 SigA: 0 MuxSig: 2
Always check the value of the multiplexor signal before using a multiplexed signal value.
if (m.Signals.MuxSig == 0) % Feel free to use the value of SigA however is required. end
This ensures that you are not using an invalid value, because the toolbox does not prevent or protect reading or writing inactive multiplexed signals.
Note
You can access both active and inactive multiplexed signals, regardless of the value of the multiplexor signal.
Refer to the canMessage
function
to learn more about creating messages.