OSX replace <linux / serial.h>

He is currently working on a program that uses a third party library that was written on linux and includes <linux/serial.h>

. Is there any easy replacement I can make to get the program to work on OSX, or will I have to rewrite the serial code to use a different library?

+3


source to share


1 answer


It depends on what kind of control over the serial port you want. Both Linux and MacOS / X allow you to access serial ports through a file descriptor (obtained by a simple open () call with the appropriate device address as an argument), so if all you have to do is read and / or write bytes to / from the serial port as if it were a socket, you shouldn't have much of a problem. If you have to do more complex things like turn handshaking on / off and the like, things get a little more proactive.



FWIW I wrote a simple serial port interface class ( w / header ) as part of my networking library ; it works under Linux, MacOS / X and Windows. You can take a look at it for inspiration if you like; note that the macOS / X and Linux implementation is pretty much the same, except for the (GetAvailableSerialPortNames ()) method, which lists the available serial devices.

0


source







All Articles