Page 1 of 1

sending CAN message cyclically and incrementing its value

Posted: Wed 2. Mar 2016, 14:01
by akshay1392
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.

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;
}
Thanks in advance!

Regards,
Akshay

Re: sending CAN message cyclically and incrementing its valu

Posted: Fri 4. Mar 2016, 15:09
by PEAK-Support
Use a loop to run until you think it´s OK / enough, Use a sleep inside the loop of 10 ms. Simply add a counter in the code and increment it every loop until it reached the limit. Then set back to zero.

So you see - it´s easy - but you need to know how to setup in C
(which is a C/C++ problem, you could ask in a C/C++ Forum)