DCO_81
Member level 1
- Joined
- Mar 10, 2005
- Messages
- 39
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Germany, south
- Activity points
- 1,657
Hi all,
I´ve some trouble with this code. Got this from "serial programming guide for posix operating systems". But this doesn´t work - the buffer is always empty. Where is my mistake? I don´t have a cure.
I´ve some trouble with this code. Got this from "serial programming guide for posix operating systems". But this doesn´t work - the buffer is always empty. Where is my mistake? I don´t have a cure.
Code:
int response()
{
int nbytes;
char *bufptr;
char buffer[255];
write(fd, "AT\r", 3);
sleep(1);
bufptr = buffer;
while ((nbytes = read(fd, bufptr, buffer + sizeof(buffer) - bufptr - 1)) > 0)
{
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] = '\r')
break;
}
*bufptr = '\0';
cout << buffer << endl; // buffer is empty !! - WHY ?!?
if (strncmp(buffer, "OK", 2))
return 0;
return -1;
}