Date: Thu, 8 Jul 2004 00:50:40 +0200 From: Bernd Walter <ticso@cicely12.cicely.de> To: Greg Hormann <ghormann@alumni.indiana.edu> Cc: hackers@freebsd.org Subject: Re: Controlling the Serial port Message-ID: <20040707225039.GV12877@cicely12.cicely.de> In-Reply-To: <20040706225135.V32380@hormann.tzo.cc> References: <20040706225135.V32380@hormann.tzo.cc>
next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jul 06, 2004 at 10:53:23PM -0400, Greg Hormann wrote: > > I'm working to develop a communications program to control a piece of > vendor supplied hardware. (They only provide a control program for > Windows.) I think I'm close. The device uses a RS-232 -> RS-485 convert > which I belive is powered by either the RTS or DTR line of the serial > port. How can I force these two lines to say powered in FreeBSD inside a > C program thus providing power to the converter? I only need to > write to the device. So you are doing half duplex rs485 and need to control the transmitter. Be aware that the code uses variables in a way which is generally a bad idea - I was into uC programming when I did this... static int fd; static int tciotmp; inline void txon() { ioctl(fd, TIOCMGET, &tciotmp); tciotmp &= ~TIOCM_RTS; ioctl(fd, TIOCMSET, &tciotmp); tciotmp |= TIOCM_RTS; } inline void txoff() { tcdrain(fd); // wait until all data is send ioctl(fd, TIOCMSET, &tciotmp); } The problem is timing as we need to have the transmitter disabled bevor the connected device responds to our request. There is no garanty that this is allways fast enough from userland. It can also be a good idea to clear the receive buffer after enabling the transmitter and bevor sending anything to wast stall data. -- B.Walter BWCT http://www.bwct.de bernd@bwct.de info@bwct.de
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040707225039.GV12877>