I am trying to read serial data which is send by a uC using /dev/tts/0 on the WL-500gP but I don't get anything. I keep on receiving the EAGAIN error (device temporarily unavailable or something like that)
I've written a C program to acces the serial port. Writing to the device goes fine but I don't receive anything.
If I measure the RX line the voltage is nearing the Vdd level 2.9V. I made a levelshifter from 5V (uC) to 3.3V (router) but it seems the RX (input of the router) can't be pulled to gnd... ?! Anyone having the same problem?
I do set the CREAD flag by the way, and I tried several simple reads in the shell
... some other defines ...
#define DEVICE "/dev/tts/0"
#define BAUDRATE B9600
/* Global filediscriptor */
int fd=0;
int initport(void) {
struct termios options;
// Get the current options for the port...
tcgetattr(fd, &options);
// Enable the receiver and set local mode...
options.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD; // 8N1
options.c_iflag = ICRNL;
options.c_oflag = 0;
options.c_lflag = ICANON;
tcflush(fd, TCIFLUSH);
// Set the new options for the port...
tcsetattr(fd, TCSANOW, &options);
return 1;
}
int write_char(char *chars, int len) {
chars[len] = 0x0d; // stick a <CR> after the command
chars[len+1] = 0x00; // terminate the string properly
int n = write(fd, chars, strlen(chars));
if (n < 0) {
fputs("write failed!\n", stderr);
return 0;
}
printf("written:%s\n", chars);
return 1;
}
int read_char(char *result) {
int n = read(fd, result, 254);
result[n-1] = 0x00;
if (n<0) {
if (errno==EAGAIN) {
printf("SERIAL EAGAIN ERROR\n");
return 0;
}
else {
printf("SERIAL read error %d %s\n", errno, strerror(errno));
return 0;
}
}
return 1;
}
... some other functions ...
int main(int argc, char **argv) {
/* Open device port with corresponding options */
fd = open(DEVICE, O_RDWR | O_NOCTTY | O_NDELAY);
if (fd==-1) {
perror("Port: Unable to open\n");
return 1;
}
else {
fcntl(fd, F_SETFL, 0);
}
/* Initialize the serial port */
initport();
// Send things
// Receive things
// etc...
return 0;
}
(Last edited by casio on 20 Aug 2007, 20:10)