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).
我正在寻找一个开放源码的跨平台库,用于使用C中的串行端口,类似于很棒的PySerial库(不幸的是,我必须为这个应用程序使用C)。
I have only found this one: http://www.teuniz.net/RS-232/, and that doesn't seem to have mention OS X compatibility.
我只找到了这个:http://www.teuniz.net/RS-232/,似乎没有提到OS X兼容性。
6 个解决方案
#1
26
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.
您可能会认为用于串行端口的跨平台C库已经存在了20年,但到2013年还没有,所以我创建了libserialport。
It is tested on Windows, Mac OS X, Linux (including Android), BSD and will probably build on other Unix systems also. It supports:
它在Windows、Mac OS X、Linux(包括Android)和BSD上进行了测试,可能还将构建在其他Unix系统上。它支持:
- 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).
最初的0.1.0版本已经被Sigrok项目用于支持串行硬件,并且已经被打包到几个Linux发行版中。git版本还包括新的API调用,用于获取关于USB串行适配器(VID/PID等)的信息。
#2
6
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.
我知道您说的是C,而不是c++,但是也许您可以使用Boost Asio的串口,并将其编译成一个库,以便与您的C应用程序链接。它声称与POSIX兼容,而OS X是POSIX。
#3
6
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:
这是一个不知如何的插件,但是我有一个MIT的许可库,用于RS-232通信,它可以移植到Windows, Linux和OS X上:
http://wjwwood.io/serial/
#4
4
I released mine under the MIT license: https://github.com/Marzac/rs232
我在MIT的许可下发布了我的代码:https://github.com/Marzac/rs232
It is programmed in C and works well for Windows, Mac and Linux.
它是用C语言编写的,适用于Windows、Mac和Linux。
#5
3
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.
根据AMSerialPort、goSerial、serialconnect、PolKit等行获取一些额外的OS x特定目标- c代码。并实现C源文件的条件编译。
http://osx.hyperjeff.net/Apps/apps?f=serial
http://osx.hyperjeff.net/Apps/apps?f=serial
#6
2
OS X supports the standard POSIX serial API, from <termios.h>
and <unistd.h>
. Look up the functions tcsetattr()
, cfsetspeed()
and so on.
OS X支持来自
#1
26
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.
您可能会认为用于串行端口的跨平台C库已经存在了20年,但到2013年还没有,所以我创建了libserialport。
It is tested on Windows, Mac OS X, Linux (including Android), BSD and will probably build on other Unix systems also. It supports:
它在Windows、Mac OS X、Linux(包括Android)和BSD上进行了测试,可能还将构建在其他Unix系统上。它支持:
- 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).
最初的0.1.0版本已经被Sigrok项目用于支持串行硬件,并且已经被打包到几个Linux发行版中。git版本还包括新的API调用,用于获取关于USB串行适配器(VID/PID等)的信息。
#2
6
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.
我知道您说的是C,而不是c++,但是也许您可以使用Boost Asio的串口,并将其编译成一个库,以便与您的C应用程序链接。它声称与POSIX兼容,而OS X是POSIX。
#3
6
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:
这是一个不知如何的插件,但是我有一个MIT的许可库,用于RS-232通信,它可以移植到Windows, Linux和OS X上:
http://wjwwood.io/serial/
#4
4
I released mine under the MIT license: https://github.com/Marzac/rs232
我在MIT的许可下发布了我的代码:https://github.com/Marzac/rs232
It is programmed in C and works well for Windows, Mac and Linux.
它是用C语言编写的,适用于Windows、Mac和Linux。
#5
3
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.
根据AMSerialPort、goSerial、serialconnect、PolKit等行获取一些额外的OS x特定目标- c代码。并实现C源文件的条件编译。
http://osx.hyperjeff.net/Apps/apps?f=serial
http://osx.hyperjeff.net/Apps/apps?f=serial
#6
2
OS X supports the standard POSIX serial API, from <termios.h>
and <unistd.h>
. Look up the functions tcsetattr()
, cfsetspeed()
and so on.
OS X支持来自