Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sendCommand() {
- int fd;
- if ((fd = serialOpen ("/dev/ttyS0", 115200)) < 0) {
- //fprintf (stderr, "Unable to open serial device: %sn", strerror (errno));
- cout<<"Unable to open serial device"<<endl;
- return;
- }
- unsigned char motor_on[6] = {0x3E, 0x4D, 0x01, 0x4E,0x01, 0x01}; //MOTOR ON
- unsigned char motor_off[6] = {0x3E, 0x6D, 0x01, 0x6E,0x01, 0x01}; //MOTOR OFF
- unsigned char board_info[6] = {0x3E, 0x56, 0x01, 0x57, 0x01, 0x01}; //BOARD_INFO
- serialFlush(fd);
- // Send command to grab board info
- write(fd, board_info, 6);
- sleep(2);
- // Read board response and print it
- char c;
- int counter = 0;
- while (read(fd, &c, 1) == 1) {
- //putchar(c); // print out char
- printf("%d",c);
- counter++;
- }
- cout<<"ncounter="<<counter<<endl;
- sleep(5);
- }
- int main() {
- sendCommand();
- return 0;
- }
Add Comment
Please, Sign In to add comment