Date: Fri, 9 Sep 2005 15:39:52 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: vittorio <vdemart1@tin.it> Cc: freebsd-questions@freebsd.org Subject: Re: Fwd: Re: C program to write to the com port - RESOLVED Message-ID: <20050909123952.GC7464@orion.daedalusnetworks.priv> In-Reply-To: <200509091353.49269.vdemart1@tin.it> References: <200509091353.49269.vdemart1@tin.it>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-09-09 13:53, vittorio <vdemart1@tin.it> 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. */ ... }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050909123952.GC7464>