sending at commands with c++ on cubietruck -
i have cubieboard3 (cubietruck) , i'm trying send @ commands cb modem, i'm stuck on reading answer modem. c++ code:
#include <stdio.h> #include <string.h> #include <iostream> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <termios.h> using namespace std; int main(void) { int fd; /* file descryptor port */ fd = open("/dev/ttys1", o_rdwr | o_noctty | o_ndelay); if (fd == -1)//if not open port { perror("open_port: unable open /dev/ttys1 - "); } else //if port opened { fcntl(fd, f_setfl, fndelay); //sending data std::cout<<"port opened!"<<endl; std::cout<<"sending 'atz\r' "<<endl; int n = write(fd, "atz\r", 4); if (n < 0) fputs("write() of 4 bytes failed!\n", stderr); else std::cout<<"data send!"<<endl; //reading data char buf [10]; int f = read(fd, buf, sizeof(buf)); if (f < 0) fputs("reading failed!\n", stderr); else std::cout<<f<<endl; } return (fd); }
and returns me :
port opened! sending atz data send! reading failed!
what did wrong?
i changed fcntl(fd, f_setfl, fndelay); fcntl(fd, f_setfl, 0); , started read correctly, started sending kind of trash answer.
Comments
Post a Comment