From owner-freebsd-questions@FreeBSD.ORG Sun Jul 31 14:50:29 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 49E8016A41F for ; Sun, 31 Jul 2005 14:50:29 +0000 (GMT) (envelope-from paulh@bdug.org.au) Received: from mail.bdug.org.au (mail.bdug.org.au [202.72.170.31]) by mx1.FreeBSD.org (Postfix) with ESMTP id CCD6543D45 for ; Sun, 31 Jul 2005 14:50:27 +0000 (GMT) (envelope-from paulh@bdug.org.au) Received: from localhost (localhost.bdug.org.au [127.0.0.1]) by mail.bdug.org.au (Postfix) with ESMTP id 76FB5DA9 for ; Sun, 31 Jul 2005 22:50:53 +0800 (WST) Received: from mail.bdug.org.au ([127.0.0.1]) by localhost (ant.bdug.org.au [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 18338-07 for ; Sun, 31 Jul 2005 22:50:47 +0800 (WST) Received: from w2k2 (unknown [192.168.0.102]) by mail.bdug.org.au (Postfix) with ESMTP id 1050A4D for ; Sun, 31 Jul 2005 22:50:47 +0800 (WST) From: "Paul Hamilton" To: Date: Sun, 31 Jul 2005 22:50:59 +0800 Message-ID: <01cb01c595df$435ed060$6600a8c0@w2k2> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.6626 Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 X-Virus-Scanned: amavisd-new at bdug.org.au Subject: C program to write to the com port 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, 31 Jul 2005 14:50:29 -0000 Hi, I am trying to write a C program that will send 3 bytes to the cuaa0 com port at 9600 baud, 8n1. I am trying to control a Northlight 8 Channel = Servo motor controller: http://home.att.net/~northlightsystems/DMX512toRCservo.htm Most of the code came from this page: http://www.easysw.com/~mike/serial/serial.html Here is what I have so far:- ----------------------------------------------------------------------- #include #include #include #include #include /*Originally it was termio.h*/ #include #include static char *opt_comport=3D"/dev/cuaa0"; int main(int argc, char **argv) { int n; int dcf_dev; int sdata =3D 0xFF0090; // sync byte, address, servo value to be = sent to the Servo Controller struct termios options; // ok, lets try opening the com port printf("Opening Com port: %s\n\n", opt_comport); if((dcf_dev =3D open(opt_comport, O_RDWR | O_NOCTTY | O_NDELAY)) < = 0)=20 { printf("Problems opening %s\n", opt_comport); return (-1); } // set the required com port parrameters options.c_cflag &=3D ~CSIZE; /* Mask the character size bits */ options.c_cflag |=3D CS8; /* Select 8 data bits */ options.c_cflag &=3D ~PARENB; // set no parity options.c_cflag &=3D ~CSTOPB; // set 1 stop bit options.c_oflag &=3D ~OPOST; // Raw output tcgetattr(dcf_dev, &options); /* * Set the baud rates to 9600... */ cfsetispeed(&options, B9600); cfsetospeed(&options, B9600); /* * Enable the receiver and set local mode... */ options.c_cflag |=3D (CLOCAL | CREAD); /* * Set the new options for the port... */ tcsetattr(dcf_dev, TCSANOW, &options); // ok, lets transmit our 3 bytes to com port 1 n =3D write(dcf_dev, &sdata, 3); if (n < 0) fputs("write() of 3 bytes failed!\n", stderr); printf("Output status: %d bytes written out\n", n); exit(1); }; ----------------------------------------------------------------------- Now I am just a beginner at C code, so I feel pretty good getting this = far (hey, it compiles :-) However, a miss is as good as a mile, and so it doesn't work :-( Having said that, I have a serial port LED breakout device watching, and I can see a blip on the TX line when I run the = compiled program. This is just meant to be test code, i.e.. Get it working = before cleaning it up etc :-) I have tried connecting the computers serial port to another one, = running: 'cu -s 9600 -l cuaa0' but I don't see anything. Having said that, I = don't see anything if I run the same on the other PC (yes, the TX-RX lines are swapped over), so maybe that is a problem with my serial cable between = the two computers. The Servo Controller only needs two wires: signal ground and TX so not much to go wrong there, and as I said above, I do see a blip on the TX = LED when I run the program. Questions: 1. Am I really sending the data correctly at 9600baud, 8n1? 2. Am I really sending the hex bytes: FF 00 90 out (or am I sending an pointer address)? 3. What am I missing? Thanks. Cheers, Paul Hamilton