From owner-freebsd-hackers@FreeBSD.ORG Wed Jul 7 22:51:31 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B816A16A4CE for ; Wed, 7 Jul 2004 22:51:31 +0000 (GMT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1701643D41 for ; Wed, 7 Jul 2004 22:51:31 +0000 (GMT) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) i67MpOaI005982 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Thu, 8 Jul 2004 00:51:27 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [IPv6:3ffe:400:8d0:301::12]) by cicely5.cicely.de (8.12.10/8.12.10) with ESMTP id i67MofUi010470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 8 Jul 2004 00:50:42 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.12.11/8.12.11) with ESMTP id i67MofYp025024; Thu, 8 Jul 2004 00:50:41 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.11/8.12.11/Submit) id i67Mof4X025023; Thu, 8 Jul 2004 00:50:41 +0200 (CEST) (envelope-from ticso) Date: Thu, 8 Jul 2004 00:50:40 +0200 From: Bernd Walter To: Greg Hormann Message-ID: <20040707225039.GV12877@cicely12.cicely.de> References: <20040706225135.V32380@hormann.tzo.cc> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040706225135.V32380@hormann.tzo.cc> X-Operating-System: FreeBSD cicely12.cicely.de 5.2-CURRENT alpha User-Agent: Mutt/1.5.6i X-Spam-Status: No, hits=-4.9 required=3.0 tests=BAYES_00 autolearn=ham version=2.61 X-Spam-Report: * -4.9 BAYES_00 BODY: Bayesian spam probability is 0 to 1% * [score: 0.0000] X-Spam-Checker-Version: SpamAssassin 2.61 (1.212.2.1-2003-12-09-exp) on cicely5.cicely.de cc: hackers@freebsd.org Subject: Re: Controlling the Serial port X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Jul 2004 22:51:31 -0000 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