All Projects → rm5248 → CSerial

rm5248 / CSerial

Licence: Apache-2.0 license
Cross-platform serial port access through C

Programming Languages

c
50402 projects - #5 most used programming language
C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to CSerial

Cserialport
The latest modified version of Remon Spekreijse's serial port class
Stars: ✭ 64 (+236.84%)
Mutual labels:  serial-ports
Common
Yet another serial port debugger.
Stars: ✭ 245 (+1189.47%)
Mutual labels:  serial-ports
ConsolePi
Raspberry Pi Based Serial Console Server, with PushBullet Notification of IP changes, Automatic VPN termination, custom menu, Power Outlet Control, and a lot more
Stars: ✭ 109 (+473.68%)
Mutual labels:  serial-ports
Akka Serial
Reactive serial communication library for Akka and Scala.
Stars: ✭ 123 (+547.37%)
Mutual labels:  serial-ports
Arduinostl
An STL and iostream implementation based on uClibc++ that supports my CS-11M class.
Stars: ✭ 201 (+957.89%)
Mutual labels:  serial-ports
RxSerialPort
基于Rxjava2.x的串口通信library
Stars: ✭ 11 (-42.11%)
Mutual labels:  serial-ports
Uduino
Simple and easy connection between Arduino and Unity
Stars: ✭ 25 (+31.58%)
Mutual labels:  serial-ports
pros-cli
Command Line Interface for managing PROS projects. Works with V5 and the Cortex
Stars: ✭ 92 (+384.21%)
Mutual labels:  serial-ports
Libserial
Serial Port Programming in C++
Stars: ✭ 201 (+957.89%)
Mutual labels:  serial-ports
SerialProtocol
A protocol for sending data between two Arduino devices, or between an Arduino and another device through a serial port
Stars: ✭ 36 (+89.47%)
Mutual labels:  serial-ports
Rubyserial
FFI Ruby library for RS-232 serial port communication
Stars: ✭ 142 (+647.37%)
Mutual labels:  serial-ports
Usbdeviceswift
wrapper for IOKit.usb and IOKit.hid written on pure Swift that allows you convenient work with USB devices
Stars: ✭ 156 (+721.05%)
Mutual labels:  serial-ports
JavaSerial
Use serial ports from Java using standard IO methods.
Stars: ✭ 14 (-26.32%)
Mutual labels:  serial-ports
Androidserialport
Android Serial Port , 基本的Android 串口通信库
Stars: ✭ 99 (+421.05%)
Mutual labels:  serial-ports
etherport-client
Client-side virtual serial port for Etherport. Used to implement firmata-compatible boards and relays.
Stars: ✭ 20 (+5.26%)
Mutual labels:  serial-ports
Sers
Serial port access for the Go programming language.
Stars: ✭ 30 (+57.89%)
Mutual labels:  serial-ports
open-serial-port-monitor
Open source application to monitor traffic over a serial port
Stars: ✭ 100 (+426.32%)
Mutual labels:  serial-ports
serial.nim
A Nim library for accessing serial ports.
Stars: ✭ 59 (+210.53%)
Mutual labels:  serial-ports
bluetooth-serial-port
multi-platform bluetooth serial port library for C++
Stars: ✭ 59 (+210.53%)
Mutual labels:  serial-ports
Commander
Arduino Command Line Utility
Stars: ✭ 20 (+5.26%)
Mutual labels:  serial-ports

CSerial

Cross-platform serial port implementation.

Homepage

Based largely off of JavaSerial, CSerial aims to bring cross-platform serial programming to a computer near you.

The library is structured along the lines of the Apache Portable Runtime(APR). It aims to provide as much low-level support as is required to create a working serial port implementation.

CSerial is designed to be fully POSIX-compliant, however if it is not please open an issue on GitHub. See the 'Bugs' section for more details on this.

Continuous Integration

Build Status

Find builds on Jenkins!

Install(Debian-based systems)

There is an APT server setup that provides CSerial that you can find here. Note that because the 'nightly' repo contains packages for both amd64 and armhf, you may need to specify the exact version to install, as otherwise it may attempt to install one from an incorrect arch.

Build / Install from source

Building is done using CMake. On Linux, this should be done like the following:

~$ mkdir CSerial_build
~$ cd CSerial_build
~$ cmake /path/to/CSerial_code
~$ make
~$ make install

On Windows, I recommend using CMake to create a new Visual Studio project and building the code that way. I have not tested cygwin nor MinGW makefiles as generated by CMake.

Example

For information on how to use the library, check out the example program under the 'examples' directory.

The simplified flow of how to use the library is below:

  1. Allocate a new c_serial_port_t struct. Note that this is an opaque type, and can only be passed as a pointer. Use the c_serial_new function.
  2. Set the name of the serial port. This is the actual serial port that will be opened. It will be something like /dev/ttyS0 on Linux systems, and COM1 on Windows systems. Use the c_serial_set_port_name function.
  3. Set the serial port parameters. By default, the port will be opened at 9600-8-N-1. Any other settings can be set with the appropriate setters.
  • To set the baud rate, use c_serial_set_baud_rate
  • To set the number of data bits, use c_serial_set_data_bits
  • To set the number of stop bits, use c_cserial_set_stop_bits
  • To set the parity, use c_serial_set_parity
  • To set the flow control, use c_serial_set_flow_control
  1. (optional) Set the serial line change flags. This determines what changes on a serial line will cause a read to return. By default, no flags are set. Use the c_serial_set_serial_line_change_flags function to set the flags.
  2. Open the port. Use c_serial_open
  3. Read and write data. Use c_serial_read_data and c_serial_write_data, respectively.

Logging

The library has some rudimentary logging. This may be set as either a global log function, or as a log function per-port. There exists a simple implementation of a logger which will print out every message to stderr. This is intended for use with a secondary logging framework, so that logs may all be used by one logging facility.

The relevant functions for logging are c_serial_set_log_function for logging a single serial port, and c_serial_set_global_log_function for logging all messages. Note that some messages can only go to the global log function, as there is not always a serial port associated with some of the operations.

Other Important Functions

Note that all functions can be see in the Doxygen documentation with the proper documentation.

The following presents a brief list of other functions which may be important:

  • c_serial_get_serial_ports_list - Go through the system and find all of the valid serial ports.
  • c_serial_get_last_native_errnum - Return the last native error number.
    This corresponds to errno on POSIX and GetLastError on Windows.
  • c_serial_[set|get]_user_data - Set / get user data(void*) associated with the port.
  • c_serial_get_available - Get the number of bytes to read.
  • c_serial_get_native_handle - Get the native handle(int on POSIX, HANDLE on Windows) for raw I/O access
  • c_serial_get_poll_handle - Get the handle used to poll for changes on a port. Useful for use with a poll()-like function. On POSIX systems, this returns the same as c_serial_get_native_handle. On Windows, this returns a HANDLE corresponding to an event created with CreateEvent on the OVERLAPPED struct associated with the serial port.

RTS Handling

The library also supports toggling of the RTS line when transmitting data over the serial port. This is generally used for RS-485 transmitting. This can be set to several different settings(see the enum CSerial_RTS_Handling for more details). If set to HARDWARE, this will attempt to use the built-in kernel level functions for controlling the RTS line(using struct serial_rs485 on Linux, or setting fRtsControl on Windows). Setting it to SOFTWARE will cause the library to manually toggle the RTS line when sending data.

Bugs

Questions? Bugs? Open an issue in GitHub and I will take a look at it.

License

Licensed under Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].