Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Sep 2005 20:41:42 +0800
From:      "Paul Hamilton" <paulh@bdug.org.au>
To:        "'vittorio'" <vdemart1@tin.it>, <freebsd-questions@freebsd.org>
Subject:   RE: Re: C program to write to the com port - RESOLVED
Message-ID:  <056c01c5b53b$d4c6bf60$6600a8c0@w2k2>
In-Reply-To: <200509091353.49269.vdemart1@tin.it>

next in thread | previous in thread | raw e-mail | index | archive | help
Hi vittorio,

Hey I am just a beginner myself, but this is a C program, not a C++ =
program.
My gcc is version 3.4.2 too.

Hmm, did you cut and paste ALL of the source code, including the =
#include
statements?  I also see that it's mentioning code on lines 62, 66 and =
69.
My testssc.c only has around 57 lines of code.  What else have you =
included?


Cheers,

Paul

> -----Original Message-----
> From: owner-freebsd-questions@freebsd.org=20
> [mailto:owner-freebsd-questions@freebsd.org] On Behalf Of vittorio
> Sent: Friday, 9 September 2005 7:54 PM
> To: freebsd-questions@freebsd.org
> Subject: Fwd: Re: C program to write to the com port - RESOLVED
>=20
>=20
>=20
> As a C++ absolute beginner I'm trying to compile your=20
> testssc.c file with
>=20
> g++ testssc.c -o testssc
> (under freebsd 5.4, gcc version 3.4.2)
>=20
> But...
> I only get:
>=20
> SerialPort.C: In function `int main(int, char*)':
> SerialPort.C:62: error: invalid conversion from `unsigned=20
> char*' to `char*'
> SerialPort.C:62: error:   initializing argument 1 of `int=20
> snprintf(char*,=20
> size_t, const char*, ...)'
> SerialPort.C:66: error: `err' undeclared (first use this function)
> SerialPort.C:66: error: (Each undeclared identifier is=20
> reported only once for=20
> each function it appears in.)
> SerialPort.C:69:3: warning: no newline at end of file
>=20
> Could you please help to straighten things up?
>=20
> Vittorio
>=20
> ----------  Messaggio inoltrato  ----------
>=20
> Subject: Re: C program to write to the com port - RESOLVED
> Date: 02:23, venerd=EC 09 settembre 2005
> From: "Paul Hamilton" <paulh@bdug.org.au>
> To: freebsd-questions@freebsd.org
>=20
> .....................................................................
> --------------------------------------------------------------
> --------------
> --------
> /*  Name: testssc.c
>  *  compile with:  gcc testssc.c -o testssc
>  *
>  *  Your serial cable should be plugged into com port 1.
>  *  You only need the pin 3 and pin 5 (DB9) plugged into the=20
> controller.
>  *  The servo should be plugged into the first servo channel/port.
>  *  This test program when run will move the servo from midrange,
>  *  to position 01.  This is for demonstrational use only.
>  *  Tested with FreeBSD 5.4
>  *  Paul Hamilton  8th Aug 2005
>  */
>=20
>     #include <sys/time.h>
>     #include <sys/ioctl.h>
>     #include <errno.h>
>     #include <fcntl.h>
>     #include <termios.h> /*Originally it was termio.h*/
>     #include <stdio.h>
>     #include <unistd.h>
>     // Use serial port 0  (com port 1)
>     static char *opt_comport=3D"/dev/cuaa0";
>=20
> int main(int argc, char **argv)
> {
>     int fd;
>     struct termios options;
>     unsigned char buf[4];
>=20
>     // ok, lets try opening the com port
>     printf("Opening Com port: %s\n\n", opt_comport);
>     if((fd =3D open(opt_comport, O_RDWR | O_NOCTTY )) < 0)
>       {
>          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
>=20
>     tcgetattr(fd, &options);
>=20
>     /*
>      * Set the baud rates to 9600...
>      */
>     cfsetispeed(&options, B9600);
>     cfsetospeed(&options, B9600);
>=20
>     /*
>      * Enable the receiver and set local mode...
>      */
>     options.c_cflag |=3D (CLOCAL | CREAD);
>=20
>     /*
>      * Set the new options for the port...
>      */
>     tcsetattr(fd, TCSANOW, &options);
>=20
>     // ok, lets transmit our 3 bytes through com port 1
>     snprintf(buf,4,"%c%c%c%c",0xff,0x00,0x01,0);
>     printf("buf=3D%x,%x,%x,%x\n", buf[0],buf[1],buf[2],buf[3]);
>=20
>   if (write(fd, buf, 3) !=3D 3)
>     err(1, "write");
>=20
>     close(fd);
> };
> --------------------------------------------------------------
> --------------
> --------
>=20
> Cheers,
>=20
> Paul Hamilton
>=20
> PS.  I have three books on programming in C winging their way=20
> to Australia. I have a lot to learn  :-)
>=20
> _______________________________________________
> freebsd-questions@freebsd.org mailing list=20
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to=20
> "freebsd-questions-unsubscribe@freebsd.org"
>=20
> -------------------------------------------------------
> _______________________________________________
> freebsd-questions@freebsd.org mailing list=20
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to=20
> "freebsd-questions-unsubscribe@freebsd.org"
>=20
>=20




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?056c01c5b53b$d4c6bf60$6600a8c0>