From owner-freebsd-questions@FreeBSD.ORG Sun Sep 20 05:36:29 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 384EB1065672 for ; Sun, 20 Sep 2009 05:36:29 +0000 (UTC) (envelope-from pldrouin@pldrouin.net) Received: from smtp.cyberfingers.net (smtp.cyberfingers.net [198.177.254.227]) by mx1.freebsd.org (Postfix) with ESMTP id 16AF78FC0A for ; Sun, 20 Sep 2009 05:36:28 +0000 (UTC) Received: from mdaemon.pldrouin.net (CPE0023695b905f-CM001a666aca96.cpe.net.cable.rogers.com [99.246.67.95]) by smtp.cyberfingers.net (Postfix) with ESMTP id ACE0FAB6C53 for ; Sun, 20 Sep 2009 01:36:27 -0400 (EDT) Message-ID: <4AB5BF53.80908@pldrouin.net> Date: Sun, 20 Sep 2009 01:36:19 -0400 From: Pierre-Luc Drouin User-Agent: Thunderbird 2.0.0.23 (X11/20090824) MIME-Version: 1.0 To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Newbie question about ASYNC communication with FTDI-based device (via uftdi) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Sep 2009 05:36:29 -0000 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!