Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/euantorano/serial.nim
A Nim library for accessing serial ports.
https://github.com/euantorano/serial.nim
hacktoberfest nim rs232 serial-ports serialport
Last synced: about 8 hours ago
JSON representation
A Nim library for accessing serial ports.
- Host: GitHub
- URL: https://github.com/euantorano/serial.nim
- Owner: euantorano
- License: bsd-3-clause
- Created: 2016-10-14T17:13:26.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-01-24T11:13:46.000Z (10 months ago)
- Last Synced: 2024-08-04T03:05:19.421Z (3 months ago)
- Topics: hacktoberfest, nim, rs232, serial-ports, serialport
- Language: Nim
- Homepage:
- Size: 192 KB
- Stars: 70
- Watchers: 7
- Forks: 10
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nim - serial - A Nim library for accessing serial ports. (Operating System / System API)
README
# serial.nim
A library to work with serial ports using pure Nim.
## Installation
`serial` can be installed using Nimble:
```
nimble install serial
```Or add the following to your .nimble file:
```
# Dependenciesrequires "serial >= 1.0.0"
```## Usage
There are some examples in the `examples` directory, showing reading from and writing to a serialport.
### Listing serial ports
```nim
import serial # Or: `import serial/utils`for port in listSerialPorts():
echo port
```### Reading from/writing to a serial port (echoing data)
```nim
import serial # Or: `import serial/serialport`let port = newSerialPort("COM1")
# use 9600bps, no parity, 8 data bits and 1 stop bit
port.open(9600, Parity.None, 8, StopBits.One)# You can modify the baud rate, parity, databits, etc. after opening the port
port.baudRate = 2400var receiveBuffer = newString(1024)
while true:
let numReceived = port.read(receiveBuffer)
discard port.write(receiveBuffer[0 ..< numReceived])
```### Using the SerialStream
```nim
import serial # Or: `import serial/serialstream`let port = newSerialStream("COM1", 9600, Parity.None, 8, StopBits.One, buffered=true)
while true:
# Read a line from the serial port then write it back.
port.writeLine(port.readLine())
```## Features
- Basic port reading/writing for Windows/Posix
- Port setting control - baud rate, stop bits, databits, parity, handshaking
- Port listing to list available serial ports
- Windows, using `SetupDiGetClassDevs`
- Mac, using I/O Kit
- Posix, by iterating possible device files
- High level `SerialPortStream` that complies with the `streams` API
- Async API using `asyncdispatch` for reading from and writing to a port