跳转到内容

示例

消息传输:

J1939_MSG objMsg;
objMsg.id = 0x1cfefefe;
objMsg.dlc = 215;
for(int i =0; i < objMsg.dlc; i++)
{
objMsg.byteAt(i, i*2);
}
SendMsg(objMsg);
```**数据库消息传输:**
// 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));
**设置 J1939 特定参数:**
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);
**访问 J1939 特定参数:**
J1939_MSG objMsg; unsigned int nPGN = objMsg.id.getPGN(); char nPduSpecific = objMsg.id.getSourceAddress(); unsigned char dataPage = id.getDataPage(); objMsg.id.getPriority();
**访问信号值:**// 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();
**更新数据库消息信号值:**
数据库消息结构可以被有意义的解释。数据库消息结构将具有数据库中定义的信号成员。通过使用数据库消息结构的成员和信号名称,可以直接分配信号原始值。
DBMsg 是一个具有信号 Sig1、Sig2 和 Sig3 的数据库消息。每个信号的长度为 2 个字节。要分配信号的原始值,请使用消息名称结构,并将信号名称作为成员使用。
```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);
```> **注意**:在函数编辑器的编辑区域上单击鼠标右键。选择“Insert Message”或“Insert Signal”选项以插入消息结构或信号结构。在“Message and Signal List”中选择“Yes, I want to declare selected message structure variable”选项,以使用其结构定义初始化消息。
---
**权威来源**: BUSMASTER DITA help source `J1939_Node_Simulation_Examples.dita`, compiled into `BUSMASTER.CHM` with the application.