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 of- 0.
- SigB— Another multiplexed signal with a multiplex value of- 1.
- 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- MuxSigis the multiplexor signal, whose value determines which of the two multiplexed signals are active in the message.- SigAand- SigBare the multiplexed signals that are active in the message if their multiplex values match- MuxSig. In the example shown,- SigAis active because its current multiplex value of- 0matches the value of- MuxSig(which is- 0).
- If you want to make - SigBactive, change the value of the- MuxSigto- 1.- m.Signals.MuxSig = 1 - To display the signals, type: - m.Signals - ans = SigB: 0 SigA: 0 MuxSig: 1- SigBis now active because its multiplex value of- 1matches the current value of- MuxSig(which is- 1).
- Change the value of - MuxSigto- 2.- m.Signals.MuxSig = 2 - Here, neither of the multiplexed signals are active because the current value of - MuxSigdoes not match the multiplex value of either- SigAor- SigB.- 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. Nested multiplexing is not supported.