Guest User

Untitled

a guest
Dec 13th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. void sendCommand() {
  2. int fd;
  3.  
  4. if ((fd = serialOpen ("/dev/ttyS0", 115200)) < 0) {
  5. //fprintf (stderr, "Unable to open serial device: %sn", strerror (errno));
  6. cout<<"Unable to open serial device"<<endl;
  7. return;
  8. }
  9.  
  10. unsigned char motor_on[6] = {0x3E, 0x4D, 0x01, 0x4E,0x01, 0x01}; //MOTOR ON
  11. unsigned char motor_off[6] = {0x3E, 0x6D, 0x01, 0x6E,0x01, 0x01}; //MOTOR OFF
  12. unsigned char board_info[6] = {0x3E, 0x56, 0x01, 0x57, 0x01, 0x01}; //BOARD_INFO
  13.  
  14. serialFlush(fd);
  15.  
  16. // Send command to grab board info
  17. write(fd, board_info, 6);
  18. sleep(2);
  19.  
  20. // Read board response and print it
  21. char c;
  22. int counter = 0;
  23. while (read(fd, &c, 1) == 1) {
  24. //putchar(c); // print out char
  25. printf("%d",c);
  26. counter++;
  27. }
  28. cout<<"ncounter="<<counter<<endl;
  29. sleep(5);
  30.  
  31.  
  32. }
  33.  
  34. int main() {
  35. sendCommand();
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment