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
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;
}
options.c_cc[VTIME] = 10; // Meaning 1 second
bufptr[-1]
In this code: nothing, just rewrite the entire loop thingy ;-)Any suggestions what I should write instead of bufptr[-1] ?
cout << hex << (int)buffer;
cout < nbytes << " received" << endl;
cout < "Houston we received data" << endl;
cout << hex << (int) buffer << endl;
cout << buffer << endl;
#define BUFFERSIZE 256
int response()
{
int i;
int nbytes;
unsigned int writePos = 0;
char response[BUFFERSIZE];
write(fd, "AT\x0D\x0A", 4);
sleep(1);
while ((nbytes = read(fd, &response[writePos], BUFFERSIZE - readPos)) > 0)
{
for (i=writePos ; i<writePos+nbytes; i++)
cout << "Byte received: " << hex << (int)response[i] << endl;
writePos += nbytes;
if (writePos >= BUFFERSIZE)
break;
// Probably you receive "\x0D\x0AOK\x0D\x0A"
if ( (writePos > 2) && (response[writePos-1] == 0x0A) )
break;
}
cout << response << endl;
if (strncmp(response, "\x0D\x0AOK\x0D\x0A", 6))
return 0;
return -1;
}
printf(response)
for
while
Serial::Serial (char *device_name)
{
fd = open(device_name, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd < 0)
{
exit(1);
}
fcntl(fd, F_SETFL, 0);
tcgetattr(fd, &old_settings);
bzero(&new_settings, sizeof(new_settings);
new_settings.c_cflag |= ( CLOCAL | CREAD );
new_settings.c_lflag &= ~( ICANON | ECHO | ECHOE | ISIG );
new_settings.c_oflag &= ~OPOST;
new_settings.c_cc[VMIN] = 0;
new_settings.c_cc[VTIME] = 50;
cfsetspeed(&new_settings, B9600);
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &new_settings);
}
while ((nbytes = read(fd, &response[writePos], BUFFERSIZE - readPos)) > 0)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?