Wait instruction while transmitting the messages
Posted: Mon 1. Feb 2021, 17:35
Hello there,
I have just started using PCAN Developer 4 and was going through its examples. Is there any way to wait for some time while transmitting the number of messages to the connected client, as "Wait" instruction in PCAN Explorer 6?
I used this method to write the CAN messages but could not find a way to wait some time after transmitting each message. The transmitting process takes place at such a speed that my client could not respond. That is why I need to wait after transmitting each message. I also tried incrementing the Timestamp value, but still, it's not working. Any help would be highly appreciated.
Best regards,
Krishna
I have just started using PCAN Developer 4 and was going through its examples. Is there any way to wait for some time while transmitting the number of messages to the connected client, as "Wait" instruction in PCAN Explorer 6?
Code: Select all
// Sends 5 standard messages over a client with handle 1.
//
StatusErrors status;
CommonObjectInfo[] toSend = new CommonObjectInfo[5];
UInt32 bytesWritten = 0;
for (int i = 0; i < 5; i++)
{
toSend[i] = new DataFrame();
DataFrame frame = toSend[i] as DataFrame;
frame.Timestamp = 0; // Message will be sent as soon as possible.
frame.Tag = 0; // Not used in this example.
frame.ClientHandle = 1; // Client with handle 1
frame.NetHandle = 2; // Net with handle 2
frame.MessageType = MessageTypes.Standard; // Standard 11-bit message
frame.ID = (uint)(0x100 + i); // CAN ID 0x100 to 0x104
frame.DLC = 8; // 8 data bytes
for (int j = 0; j < 8; j++)
frame.Data[j] = (byte)((i * 16) + j);
}
status = CanApi4.Write(PcanDevice.Usb, toSend, ref bytesWritten);
if (status != StatusErrors.Ok)
{
CanApi4.GetStatusText(status, out string errorText);
Console.WriteLine(String.Format("CanApi4.Write failed. Error: 0x{0,8:X} ({1})\n",
status, errorText));
}
Best regards,
Krishna