Discussion:
Windows and Linux compatible Serial (RS232) comm. code in C++
(too old to reply)
2005-02-14 14:57:29 UTC
Permalink
Is there any C++ code for Serial (RS232) communication compatible both with
Windows and Linux ?
Wolfgang Draxinger
2005-02-15 11:26:57 UTC
Permalink
Post by
Is there any C++ code for Serial (RS232) communication
compatible both with
Windows and Linux ?
Only using the pure System API? As long as you don't want to set
comm parameters (speed, databits, parity): Yes. Just do an

char comm_dev[80];
int const comm_nr;

#ifdef WIN32
#define COMM "COM%d"
#elseif
#define COMM "/dev/ttyS%d"
#endif

sprintf(comm_dev, COMM, comm_nr);
FILE *comm_f=fopen(comm_dev, "w+");

// your comm here

fclose(comm_f);

However if you want to set comm parameteres you will have to use
an OS dependent API. For windows that means that you will have
to use it's ugly file API.
--
Wolfgang Draxinger
P.M. Groen
2005-02-19 09:44:37 UTC
Permalink
Post by
Is there any C++ code for Serial (RS232) communication compatible both with
Windows and Linux ?
Sort of.... It you use the Qt-toolkit, there is an extension called
QExtSerialPort that provides what youŕe looking for.

Regards

Peter

Loading...