Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <string.h>
- #include <signal.h>
- #include <asm/types.h>
- #ifndef NO_RT
- #include <sys/mman.h>
- #endif
- #define PCAN_DEVICE PCAN_USBBUS1
- #include <PCANBasic.h>
- static void signal_handler(int s)
- {
- printf("Interrupted by SIG%u!\n", s);
- }
- int main(int argc, char* argv[])
- {
- TPCANMsg Message;
- TPCANStatus Status;
- unsigned long ulIndex = 0;
- unsigned int pcan_device = PCAN_DEVICE;
- #ifndef NO_RT
- mlockall(MCL_CURRENT | MCL_FUTURE);
- #endif
- signal(SIGINT, signal_handler);
- Status = CAN_Initialize(pcan_device, PCAN_BAUD_500K, 0, 0, 0);
- printf("CAN_Initialize(%xh): Status=0x%x\n", pcan_device, (int )Status);
- if (Status)
- goto lbl_exit;
- Message.ID = 0x02;
- Message.LEN = 8;
- Message.MSGTYPE = PCAN_MESSAGE_STANDARD;
- //memset(Message.DATA, '\0', sizeof(Message.DATA));
- for(int i=0; i<8; i++)
- {
- Message.DATA[i]=i*i;
- }
- while(1) {
- while ((Status = CAN_Write(pcan_device, &Message)) == PCAN_ERROR_OK) {
- for (int i = 0; i < 8; i++)
- if (++Message.DATA[i])
- break;
- ulIndex++;
- if ((ulIndex % 1000) == 0)
- printf(" - T Message %i\n", (int)ulIndex);
- }
- if (Status != PCAN_ERROR_QXMTFULL) {
- printf("CAN_Write(%xh): Error 0x%x\n", pcan_device,
- (int)Status);
- break;
- }
- // Tx queue is full: must wait a bit instad of forever
- // looping. Handle ^C here too.
- if (usleep(100))
- break;
- }
- CAN_Uninitialize(pcan_device);
- lbl_exit:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement