开发者

C: cross-platform RS-232 serial library? [closed]

开发者 https://www.devze.com 2023-01-02 01:21 出处:网络
Closed. This question does not meet Stack Overfl开发者_StackOverflow社区ow guidelines. It is not currently accepting answers.
Closed. This question does not meet Stack Overfl开发者_StackOverflow社区ow guidelines. It is not currently accepting answers.

We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.

Closed 7 years ago.

Improve this question

I am looking for an open source cross-platform library for working with the serial port in C, something along the lines of the awesome PySerial library (unfortunately I have to use C for this application).

I have only found this one: http://www.teuniz.net/RS-232/, and that doesn't seem to have mention OS X compatibility.


You would think that a cross-platform C library for serial ports is something that would have existed for 20 years already, but as of 2013 there still wasn't one, so I created libserialport.

It is tested on Windows, Mac OS X, Linux (including Android), BSD and will probably build on other Unix systems also. It supports:

  • Port enumeration (obtaining a list of serial ports on the system)
  • Opening, closing and querying ports
  • Setting port parameters (baud rate, parity, etc.)
  • Port signalling operations (modem control lines, breaks, etc.)
  • Reading, writing, and flushing data
  • Waiting for events
  • Obtaining error information

The initial 0.1.0 release is in active use by the Sigrok project for supporting serial hardware and is packaged in several Linux distributions already. The git version also includes new API calls for getting information about USB serial adapters (VID/PID etc).


This is a shameless plug, but I have a MIT licensed library for RS-232 communication which is portable to Windows and Linux and OS X here:

http://wjwwood.io/serial/


I realize that you said C and not C++, but perhaps you could use Boost Asio's serial ports and compile that into a library to be linked with your C application. It claims to be POSIX compatible, and OS X is POSIX.


I released mine under the MIT license: https://github.com/Marzac/rs232

It is programmed in C and works well for Windows, Mac and Linux.


OS X supports the standard POSIX serial API, from <termios.h> and <unistd.h>. Look up the functions tcsetattr(), cfsetspeed() and so on.


Get some additional OS X-specific Objective-C code along the lines of AMSerialPort, goSerial, serialconnect, PolKit, ... and implement a conditional compilation of your C source file.

http://osx.hyperjeff.net/Apps/apps?f=serial

0

精彩评论

暂无评论...
验证码 换一张
取 消