sending CAN message cyclically and incrementing its value
Posted: Wed 2. Mar 2016, 14:01
Hello,
I want to send a CAN message cyclically at 10ms . Also, I wish to increment the value by using a counter. What changes need to be done to the below code in order to incorporate those changes.
Thanks in advance!
Regards,
Akshay
I want to send a CAN message cyclically at 10ms . Also, I wish to increment the value by using a counter. What changes need to be done to the below code in order to incorporate those changes.
Code: Select all
#include <stdio.h>
#include <windows.h>
#include "PCANBasic.h"
int main( int argc, const char* argv[] )
{
TPCANStatus gStatus;
tagTPCANMsg MessageBuffer;
printf("Init PCI Express \n");
gStatus = CAN_Initialize(PCAN_PCIBUS2, PCAN_BAUD_1M);
if(gStatus!=PCAN_ERROR_OK)
{
printf("Error Init PCI Express \n");
return -1;
}
// Fill a CAN Message Structure with your needed Values Baudrate of 1MB
MessageBuffer.MSGTYPE=PCAN_MESSAGE_STANDARD;
MessageBuffer.ID=0x100;
MessageBuffer.LEN=4;
// Fill Date of the CAN Message
for(int i=0; i<4; i++)
MessageBuffer.DATA[i]=i;
printf("Send Data on PCI Express \n");
Sending the CAN message
gStatus = CAN_Write(PCAN_PCIBUS2,&MessageBuffer);
if(gStatus!=PCAN_ERROR_OK)
{
printf("Error sending CAN Frame");
return -1;
}
Sleep(1000);
// Close the CAN Communication
gStatus = CAN_Uninitialize(PCAN_PCIBUS2);
if(gStatus!=PCAN_ERROR_OK)
{
printf("Error close USB-C1");
return -1;
}
return 0;
}
Regards,
Akshay