Skip to content

Examples

Message Transmission:

J1939_MSG objMsg;
objMsg.id = 0x1cfefefe;
objMsg.dlc = 215;
for(int i =0; i < objMsg.dlc; i++)
{
objMsg.byteAt(i, i*2);
}
SendMsg(objMsg);
```**Database message transmission:**
// Message Declaration DBMsg sMsgStruct; // DBMsg is a database message // Use signal member // Sig1 sMsgStruct.Sig_1 = 10; // for setting signal raw value // Sig2 sMsgStruct.Sig_2 = 20; // Sig3 sMsgStruct.Sig_3 = 30; // Send the message now SendMsg(sMsgStruct));
**Setting J1939 Specific parameters:**
J1939_MSG objMsg; objMsg.id.setPGN(0xfefe); objMsg.id.setSourceAddress(0xfe); objMsg.id.setPriority(7); objMsg.dlc = 215; for(int i =0; i < objMsg.dlc; i++) { objMsg.byteAt(i, i*2); } SendMsg(objMsg);
**Accessing J1939 Specific Parameters:**
J1939_MSG objMsg; unsigned int nPGN = objMsg.id.getPGN(); char nPduSpecific = objMsg.id.getSourceAddress(); unsigned char dataPage = id.getDataPage(); objMsg.id.getPriority();
**Accessing signal values:**// Message Declaration DBMsg sMsgStruct; // Use signal member // Sig1 int sig1Value = sMsgStruct.Sig_1; // Type 'int' to be changed as per signal type // Sig2 int sig2Value = sMsgStruct.Sig_2; // Sig3 int sig3Value = sMsgStruct.Sig_3; (OR) int sig1Rawvalue = sMsgStruct.sig1.rawvalue(); (OR) double sig1PhyValue = sMsgStruct.sig1.physicalvalue();
**Updating database message signal values:**
Database message structures can be meaningfully interpreted. Database message structures will have signal members as defined in the database. Signal raw value can be directly assigned by using member of database message structure with the signal name.
DBMsg is a database message that has signals Sig1, Sig2 and Sig3. Each signal is 2 bytes of length. To assign raw value of a signal use message name structure and use signal name as member.
```text
// Message Declaration
DBMsg sMsgStruct;
// Use signal member
// Sig1
sMsgStruct..Sig_1 = 10;
// Sig2
sMsgStruct.Sig_2 = 20;
// Sig3
sMsgStruct.Sig_3 = 30;
(OR)
sMsgStruct.sig1.rawvalue(10);
(OR)
sMsgStruct.sig1.physicalvalue(12.4);
```> **Note**: Right click on edit area of function editor. Select "Insert Message" or "Insert Signal" option to insert message structure or signal structure. Select the option "Yes, I want to declare selected message structure variable" option in the "Message and Signal List" to initialise message with its struct definition.
---
**Authoritative source**: BUSMASTER DITA help source `J1939_Node_Simulation_Examples.dita`, compiled into `BUSMASTER.CHM` with the application.