Hi,

I'm trying to hack the code of tbancontrol, a linux tool used to control t-balancer fan controllers that use FTDI FT232BL chips. It seems to be working fine on linux, but when I try to use it on FreeBSD, I noticed that read calls fail with "Interruted system call". It seems there is something wrong with the SIGIO signal since it is generated as soon as tcsetattr is called. I guess there must be something wrong with either the way the device is opened or (more likely) the way the descriptor is configured, but I have very little experience with serial communication... Here is the main lines of the code related to initialization:

tban->port = open("/dev/ttyU0", O_RDWR | O_NOCTTY | O_NONBLOCK);
...
saio.sa_handler = tban_signal_handler_IO;
result = sigemptyset(&saio.sa_mask);
saio.sa_flags = 0;
result = sigaction(SIGIO, &saio, NULL);
result = fcntl(tban->port, F_SETFL, FASYNC);
...
tcgetattr(tban->port, &(tban->oldtio));
...
memcpy(&newtio,&tban->oldtio,sizeof(struct termios)); /*I added this line to avoid the error EINVAL when calling tcsetattr below. This is probably not enough to set all flags properly :S */
...

newtio.c_cflag = intToBaud(tban->baudrate)  /*baudrate is 19200*/
   | CRTSCTS
   | intToDataBits(tban->databits) /*databits is 8*/
   | intToStopBits(tban->stopBits) /*stopBits is 0*/
   | CLOCAL
   | CREAD;
 newtio.c_iflag     = IGNPAR;
 newtio.c_oflag     = 0;
 newtio.c_lflag     = 0;
 newtio.c_cc[VMIN]  = 1;
 newtio.c_cc[VTIME] = 0;
...
result = tcsetattr(tban->port, TCSANOW, &newtio);
/*SIGIO is generated (?)*/
...
result = write(tban->port, sndBuf, cmdLen); /*request device status*/
...
/*Initialize data availability flag to false*/
/*sleep 1 second*/
/*SIGIO is generated */
bytesread = read(tban->port, local_buf, sizeof(local_buf));
/*bytesread is -1, EINTR is generated*/

So does anybody know what could be wrong in this code?

Thanks a lot!
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to