sending CAN message cyclically and incrementing its value

The free CAN Software API (Application Programming Interface) for Windows®
Post Reply
akshay1392
Posts: 2
Joined: Mon 1. Feb 2016, 10:16

sending CAN message cyclically and incrementing its value

Post by akshay1392 » 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.

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
Last edited by M.Gerber on Wed 2. Mar 2016, 15:49, edited 1 time in total.
Reason: Inserted [code] tag for better readability.

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: sending CAN message cyclically and incrementing its valu

Post by PEAK-Support » Fri 4. Mar 2016, 15:09

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)
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply