Interfacing C++, Linux ?

What is a good choice to communicate with the Arduino using C/ C++ ? I tried to install libSerial (sourceforge), but it does not compile on my OpenSuse. Is there a more compact way than the use of termios.h ?

One of my pet peeves is people who post and say "I tried this or that, and it didn't work. What did I do wrong?". Unless it is obvious ("I powered the Arduino using 440V AC, 3 phase..."), no one can guess what didn't work, or how to fix the problem.

You say that you tried to install libSerial, but that it doesn't compile. Well, it certainly should. Why didn't it? What error messages did you get?

The serial port(s) on Linux are nothing more than files. You can connect the Arduino to the PC using a USB cable, and echo data to the appropriate file, and the Arduino will see it as serial data. Anything that the Arduino sends to the serial port will appear in that file.

So, reading from and writing to the serial port is just like reading from and writing to a file. The only trick is knowing which file to write to.

I really do not understand what makes you so angry. If i would post the ./configure and make logs from libSerial here you will be more angry because this does not belong to Arduino forum. I just mentioned that i already tried libSerial as a potential candidate for my choice. But i still did not fix the problem compiling it and wanted just to ask if there are alternatives available.

If you want to help, i'll send you the logs immediately.

So, reading from and writing to the serial port is just like reading from and writing to a file. The only trick is knowing which file to write to.

The only i know so far, is the filedescriptor created by open() using the termios.h

If there are alternatives please tell me.

regs wally

Any problem related to interfacing software with the Arduino is fair game in this forum. You are trying to create some software that interfaces to the Arduino, and having problems. Post about those problems, and you can get help.

Regardless of whether you choose to do that, or not, your original question was

Is there a more compact way than the use of termios.h ?

The answer to that is no. That include file includes the lowest level stuff needed to communicate with a file, which, on Linux, is what the serial port is. Any library that is built to facilitate communicating with the serial port will need to build on that low level functionality.

My initial comments were not directed solely at you. Read all the posts in the forum for a week, and you'll see that there are a lot of "It tried this and it doesn't work" posts, with no details about what "it doesn't work" means.

If you post here, or any forum, the more information you can provide, the more likely it is that someone will say "Hey, I've had that problem before, and I was able to fix it/work around it/find a solution for it/find that it can't be fixed" and post a reply that will help.

I wasn't trying to be offensive. If I came across that way, I apologize.

I have following error message trying to complie libserial-0.5.2 on OpenSuse 11.1

./configure and ./configue --prefix=/usr does not change the error

checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gawk... (cached) gawk
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking dependency style of gcc... gcc3
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking whether make sets $(MAKE)... (cached) yes
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for a sed that does not truncate output... /usr/bin/sed
checking for egrep... grep -E
checking for ld used by gcc... /usr/i586-suse-linux/bin/ld
checking if the linker (/usr/i586-suse-linux/bin/ld) is GNU ld... yes
checking for /usr/i586-suse-linux/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking how to recognise dependent libraries... pass_all
checking how to run the C preprocessor... gcc -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking how to run the C++ preprocessor... g++ -E
checking for g77... no
checking for f77... no
checking for xlf... no
checking for frt... no
checking for pgf77... no
checking for fort77... no
checking for fl32... no
checking for af77... no
checking for f90... no
checking for xlf90... no
checking for pgf90... no
checking for epcf90... no
checking for f95... no
checking for fort... no
checking for xlf95... no
checking for ifc... no
checking for efc... no
checking for pgf95... no
checking for lf95... no
checking for gfortran... no
checking whether we are using the GNU Fortran 77 compiler... no
checking whether  accepts -g... no
checking the maximum length of command line arguments... 32768
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking for correct ltmain.sh version... yes
checking if gcc supports -fno-rtti -fno-exceptions... no
checking for gcc option to produce PIC... -fPIC
checking if gcc PIC flag -fPIC works... yes
checking if gcc static flag -static works... yes
checking if gcc supports -c -o file.o... yes
checking whether the gcc linker (/usr/i586-suse-linux/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
configure: creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/i586-suse-linux/bin/ld
checking if the linker (/usr/i586-suse-linux/bin/ld) is GNU ld... yes
checking whether the g++ linker (/usr/i586-suse-linux/bin/ld) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/i586-suse-linux/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
appending configuration tag "F77" to libtool
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking for inline... inline
configure: creating ./config.status
config.status: creating ./Makefile
config.status: creating ./doxygen.conf
config.status: creating ./libserial.spec
config.status: creating ./doc/UML/Makefile
config.status: creating ./doc/Makefile
config.status: creating ./examples/Makefile
config.status: creating ./src/Makefile
config.status: creating config.h
config.status: executing depfiles commands

make log

make  all-recursive
make[1]: Entering directory `/home/op/Desktop/cserial/libserial/libserial-0.5.2'
Making all in src
make[2]: Entering directory `/home/op/Desktop/cserial/libserial/libserial-0.5.2/src'
if /bin/sh ../libtool --tag=CXX --mode=compile g++ -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -MT SerialStreamBuf.lo -MD -MP -MF ".deps/SerialStreamBuf.Tpo" -c -o SerialStreamBuf.lo SerialStreamBuf.cc; \
      then mv -f ".deps/SerialStreamBuf.Tpo" ".deps/SerialStreamBuf.Plo"; else rm -f ".deps/SerialStreamBuf.Tpo"; exit 1; fi
mkdir .libs
 g++ -DHAVE_CONFIG_H -I. -I. -I.. -g -O2 -MT SerialStreamBuf.lo -MD -MP -MF .deps/SerialStreamBuf.Tpo -c SerialStreamBuf.cc  -fPIC -DPIC -o .libs/SerialStreamBuf.o
make[2]: Leaving directory `/home/op/Desktop/cserial/libserial/libserial-0.5.2/src'
make[1]: Leaving directory `/home/op/Desktop/cserial/libserial/libserial-0.5.2'


SerialStreamBuf.cc:171: error: 'bzero' was not declared in this scope
make[2]: *** [SerialStreamBuf.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2
..libserial/libserial-0.5.2>

And to my question above: I'm not looking for a more compact alternative than ternios.h but for a more easy and higher level solution as maybe libSerial is.

thanks for help wally

Problem solved:
just add the following headers at the bottom, of the #include-section of file:

src/PosixSignalDispatcher.cpp
#include <string.h>

src/SerialPort.cpp
#include <string.h>
#include <stdlib.h>

src/SerialStreamBuf.cc
#include <string.h>

examples/read_port.cpp
#include <stdlib.h>

examples/write_port.cpp
#include <stdlib.h>

on OpenSuse i did:
./configure --prefix=/usr
make
su (pw)
make install

Excellent. Thank you for adding to the body of knowledge on the forum.