Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <signal.h>
  4. #include <unistd.h>
  5. #include <asm/types.h>
  6. #include <sys/mman.h>
  7.  
  8. #define PCAN_DEVICE PCAN_USBBUS1
  9.  
  10. #include "PCANBasic.h"
  11.  
  12. static void signal_handler(int s)
  13. {
  14. printf("Interrupted by SIG%u!\n", s);
  15. }
  16.  
  17. int main(int argc, char* argv[])
  18. {
  19. TPCANMsg Message;
  20. TPCANStatus Status;
  21. unsigned int pcan_device = PCAN_DEVICE;
  22.  
  23. #ifndef NO_RT
  24. mlockall(MCL_CURRENT | MCL_FUTURE);
  25. #endif
  26. signal(SIGINT, signal_handler);
  27.  
  28. Status = CAN_Initialize(pcan_device, PCAN_BAUD_500K, 0, 0, 0);
  29. printf("CAN_Initialize(%xh): Status=0x%x\n", pcan_device, (int)Status);
  30. if (Status)
  31. goto lbl_exit;
  32.  
  33. while (1) {
  34. while ((Status=CAN_Read(pcan_device, &Message, NULL)) == PCAN_ERROR_QRCVEMPTY)
  35. if (usleep(100))
  36. break;
  37.  
  38. if (Status != PCAN_ERROR_OK) {
  39. printf("CAN_Read(%xh) failure 0x%x\n", pcan_device, (int)Status);
  40. break;
  41. }
  42.  
  43. printf(" - R ID:%4x LEN:%1x DATA:%02x %02x %02x %02x %02x %02x %02x %02x\n",
  44. (int)Message.ID, (int)Message.LEN,
  45. (int)Message.DATA[0], (int)Message.DATA[1],
  46. (int)Message.DATA[2], (int)Message.DATA[3],
  47. (int)Message.DATA[4], (int)Message.DATA[5],
  48. (int)Message.DATA[6], (int)Message.DATA[7]);
  49.  
  50. #ifdef XENOMAI
  51. rt_print_flush_buffers();
  52. #endif
  53. }
  54.  
  55. CAN_Uninitialize(pcan_device);
  56.  
  57. lbl_exit:
  58.  
  59. return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement