From owner-freebsd-questions@FreeBSD.ORG Fri Sep 9 12:39:56 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 A58AA16A41F for ; Fri, 9 Sep 2005 12:39:56 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from kane.otenet.gr (kane.otenet.gr [195.170.0.95]) by mx1.FreeBSD.org (Postfix) with ESMTP id E6F3E43D48 for ; Fri, 9 Sep 2005 12:39:55 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from orion.daedalusnetworks.priv (aris.bedc.ondsl.gr [62.103.39.226]) by kane.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j89Cdr9Z025190; Fri, 9 Sep 2005 15:39:53 +0300 Received: from orion.daedalusnetworks.priv (orion [127.0.0.1]) by orion.daedalusnetworks.priv (8.13.4/8.13.4) with ESMTP id j89CdrvA007694; Fri, 9 Sep 2005 15:39:53 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by orion.daedalusnetworks.priv (8.13.4/8.13.4/Submit) id j89Cdqdg007693; Fri, 9 Sep 2005 15:39:52 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) X-Authentication-Warning: orion.daedalusnetworks.priv: keramida set sender to keramida@ceid.upatras.gr using -f Date: Fri, 9 Sep 2005 15:39:52 +0300 From: Giorgos Keramidas To: vittorio Message-ID: <20050909123952.GC7464@orion.daedalusnetworks.priv> References: <200509091353.49269.vdemart1@tin.it> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200509091353.49269.vdemart1@tin.it> Cc: freebsd-questions@freebsd.org Subject: Re: Fwd: Re: C program to write to the com port - RESOLVED 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: Fri, 09 Sep 2005 12:39:56 -0000 On 2005-09-09 13:53, vittorio wrote: > > As a C++ absolute beginner I'm trying to compile your testssc.c file with > > g++ testssc.c -o testssc > (under freebsd 5.4, gcc version 3.4.2) It's not a C++ program. You should use `cc', not `g++'. > SerialPort.C: In function `int main(int, char*)': > SerialPort.C:62: error: invalid conversion from `unsigned char*' to `char*' > SerialPort.C:62: error: initializing argument 1 of `int snprintf(char*, > size_t, const char*, ...)' > SerialPort.C:66: error: `err' undeclared (first use this function) > SerialPort.C:66: error: (Each undeclared identifier is reported only once for > each function it appears in.) > SerialPort.C:69:3: warning: no newline at end of file > > Could you please help to straighten things up? The snprintf() function is what's causing you trouble in this line: snprintf(buf,4,"%c%c%c%c",0xff,0x00,0x01,0); As I said to Paul, in personal email messages, when there is a structure that the serial data has to conform too, I usually prefer using explicitly named fields in structs, temporary buffers, and memcpy() or plain assignments instead of printf()-family functions. #define SERVO_CMD_MAXBUF 4 struct servo_cmd { unsigned char sc_id; unsigned char sc_cmd; unsigned char sc_arg; }; int servo_cmd_send(struct servo_cmd *sp) { unsigned char buf[SERVO_CMD_MAXBUF]; buf[0] = sp->sc_id; buf[1] = sp->sc_cmd; buf[2] = sp->sc_arg; buf[3] = '\0'; /* Command end char. */ ... }