Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(void)
- {
- char *portname = "/dev/ttyO4";
- int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
- if (fd < 0)
- {
- printf ("error %d opening %s: %s", errno, portname, strerror (errno));
- return 0;
- }
- set_interface_attribs (fd, BAUD_RATE, 0);
- set_blocking (fd, 1);
- tcflush(fd, TCIOFLUSH);
- char s[] = "XBMCA";
- std::string ans = "";
- int n;
- while (true)
- {
- do {
- n = write (fd, s, sizeof(s));
- if (n < 0)
- {
- std::cout << "ERROR";
- }
- } while (n == 0);
- //write (fd, (void*)s, strlen(s));
- char buf[100];
- do {
- n = read(fd, buf, 99);
- if (n < 0 && errno != EAGAIN)
- {
- std::cout << "ERROR";
- }
- if (n < 0 && errno == EAGAIN)
- {
- continue;
- }
- } while (n == 0);
- //int b = read (fd, (void*)buf, 99);
- buf[n] = '\0';
- std::cout << buf;
- std::cout.flush();
- sleep(1);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement