asrob-uc3m / yarp-devices

Yet another place for YARP devices.
https://asrob.uc3m.es/yarp-devices/
GNU Lesser General Public License v2.1
0 stars 2 forks source link

Think about multi-platform serial comm solutions #13

Closed jgvictores closed 1 year ago

jgvictores commented 6 years ago

From bottom of https://ubuntuforums.org/archive/index.php/t-896869.html (mujambee):

Under Unix, a serial port is a virtual file, names start at /dev/ttys0 and count up. Under Windows is the same, but names start at COM1, so to open a serial port you should use to fopen( "/dev/tty0", "r" ) under ux and fopen( "COM1", "r" ) under win. Unfortunately fopen cant open COM ports in recent versions of Windows.

Not sure how it works with streams, so you may be able to use C++ streams, you just need to conditionaly compile device names; something like:

#include <iostream>
#include <fstream>

#ifdef WINDOWS
const char pnames[][12]={ "COM1", "COM2", "COM3", "COM4" };
#else
const char pnames[][12]={ "/dev/ttys0", "/dev/ttys1", "/dev/ttys2", "/dev/ttys3" };
#endif
...
...
...

std::ifstream ifs( pnames[port_number] );

Anyway, if you are just learning C, it could be a good exercise to create wrapper functions and conditionaly include calls to fopen, fread, fclose in your unix version and OpenFile, ReadFile and CloseHandle in your Windows version.
jgvictores commented 5 years ago

libserial is not multiplatform (no LaserTowerOfDeath connected to Windows?) and seems pretty stale:

Back in ECROnian times, we used a plain C approach:

The protocol allowed specifying individual motor movements, unlike contrast to the current one: https://github.com/asrob-uc3m/yarp-devices/blob/29965f0c296c07d0e0dc74e60a628566df00eaa0/libraries/YarpPlugins/LaserTowerOfDeathController/LaserTowerOfDeathController.cpp#L65-L77

What would you think about moving to this plain-C approach?

PeterBowman commented 5 years ago

Isn't that plain-C approach heavily Linux-specific? I mean, check all those read, write and open calls in this file (plus termios.h and so on). I've never bothered to learn IO on Windows, perhaps it's not that hard to adopt the C standard way - or just wrap platform-specific lines in their corresponding #ifdefs: https://stackoverflow.com/a/13198670. Alternatively, we could manage serial comms with ACE, which is indeed multi-platform as already implemented in YARP's serialport device.

jgvictores commented 5 years ago

Oh, ok!

Thanks for all this info. I guess https://github.com/asrob-uc3m/yarp-devices/issues/21 is the priority now, but it's great to have some pointers towards a multiplatform solution.

Within the 3 options presented (ACE, yarp device that uses ACE, preprocessor), I have no clear preferences.

PeterBowman commented 3 years ago

It turns out libserial is not stale, the libserial-dev package has been upgraded from 0.6 to 1.0 between Ubuntu bionic and focal (ref). These versions are not compatible. I'd strongly advise moving towards YARP's serialport device, as suggested earlier.

PeterBowman commented 1 year ago

I'd strongly advise moving towards YARP's serialport device, as suggested earlier.

Done at https://github.com/asrob-uc3m/yarp-devices/commit/e65ada4dca13977f1d4a547aea9f04a2abf99f04. It is necessary to install libace-dev via apt, then compile YARP with -DSKIP_ACE=OFF (this is the default) and -DENABLE_yarpmod_serialport=ON.