某大厂牛马打工人
1.创建工程
首先创建一个以太和CAN的节点
2.设置协议栈的配置
3.capl脚本的编写
includes
{
#include "Core_Objects.cin"
#include "Core_Objects_protocol.cin"
#include "..\Core_Construction_Area\Core_Construction_Area.cin"
#include "..\Core_Lanes_Adjacent\Core_Lanes_Adjacent.cin"
#include "..\Core_Lanes_Host_protocol\Core_Lanes_Host_protocol.cin"
}
variables
{
dword gUdpSocketHandle = 0;
dword gServerUdpPort = 1274; // Service is provided on this port
CHAR gRxBuffer[1472]; // Max. UDP payload without fragmentation
LONG gResult;
CHAR gErrorText[200];
const int gLenPduRaw = 32767;
char gPduRawStr[gLenPduRaw]="";
CHAR textData[20] = "Hello UDP Client";
byte dup_payload[2500];
byte canbuffer[64];
byte Core_Objects_payload[2500];
byte Core_Construction_Area_payload[1000];
byte Core_Lanes_Host_payload[1000];
byte Core_Lanes_Adjacent_payload[1000];
dword startbyte_Core_Objects;
dword startbyte_Core_Construction_Area;
dword startbyte_Core_Lanes_Host;
dword startbyte_Core_Lanes_Adjacent;
dword Core_Objects_length;
dword Core_Construction_Area_length;
dword Core_Lanes_Host_length;
dword Core_Lanes_Adjacent_length;
}
on start
{
// Open UDP socket
gUdpSocketHandle = UdpOpen(ipGetAddressAsNumber("225.5.23.1"),gServerUdpPort);
// Check for valid socket handle
if (gUdpSocketHandle == ~0)
{
write("<%BASE_FILE_NAME%> UdpOpen failed: Result %d", IpGetLastError());
}
else // Socket handle valid
{
// Get received data
UdpSendTo(gUdpSocketHandle,ipGetAddressAsNumber("198.18.36.1"),65521,textData, strlen(textData));
UdpReceiveFrom(gUdpSocketHandle, gRxBuffer, elcount(gRxBuffer));
// Check for error
if ( IpGetLastSocketError(gUdpSocketHandle) != 997 )
{
IpGetLastSocketErrorAsString(gUdpSocketHandle, gErrorText, elcount(gErrorText));
write("<%BASE_FILE_NAME%> UdpReceiveFrom failed, %s (Result %d)", gErrorText, IpGetLastSocketError(gUdpSocketHandle));
}
}
}
// Callback function for reception from UDP client
OnUdpReceiveFrom(dword socket, long resul