跳转到内容

LIN节点仿真示例

主节点请求传输:

要发送主节点请求(或报头),应在节点仿真的Pre Connect事件中配置报头ID。

示例代码:

以下示例展示了如何每隔10ms发送标识符为0x4的主节点请求。

void OnBus_Pre_Connect() { STLIN_MSG sMsg; sMsg.messagetype = 0; // Master Response sMsg.checksumtype = 0; // Classic sMsg.id = 0x4; // Message Identifier sMsg.cluster = 1; // channel 1 // Register the header frame. SendMsg(sMsg); } //Called For Every 10ms. void OnTimer_TimerFor10ms_10() { STLIN_MSG sMsg; sMsg.messagetype = 0; // Master Response sMsg.checksumtype = 0; // Classic sMsg.id = 0x4; // Message Identifier sMsg.cluster = 1; // Send the header frame SendMsg(sMsg); }

响应主节点请求

要响应主节点请求,需要在节点仿真的Pre Connect事件中配置特定标识符的从节点响应。配置完成后,可以在任何其他节点仿真处理程序中更改数据。

示例代码:

例如,要响应标识符为0x4的主节点请求,应按如下所示配置Pre-Connect事件:

void OnBus_Pre_Connect()
{
STLIN_MSG sMsg;
sMsg.messagetype = 1; // Slave Response
sMsg.checksumtype = 0; // Classic
sMsg.dlc = 8;
sMsg.id = 0x4; // Message Identifier
sMsg.data[0] = 10; // Lower 4 Bytes
sMsg.data[1] = 20; // Upper 4 Bytes
sMsg.cluster = 1;
// Register Slave response
SendMsg(sMsg);
}
//changing data in key handlers.
void OnKey_A()
{
STLIN_MSG sMsg;
sMsg.messagetype = 1; // Slave Response
sMsg.checksumtype = 0; // Classic
sMsg.dlc = 8;
sMsg.id = 0x4; // Message Identifier
sMsg.data[0] = 20; // Lower 4 Bytes
sMsg.data[1] = 30; // Upper 4 Bytes
sMsg.cluster = 1;
// Send the message
SendMsg(sMsg);
}

权威来源: BUSMASTER DITA help source LIN_Node_Simulation_Examples.dita, compiled into BUSMASTER.CHM with the application.