GithubHelp home page GithubHelp logo

lucawolf / serial.nim Goto Github PK

View Code? Open in Web Editor NEW

This project forked from euantorano/serial.nim

0.0 1.0 0.0 151 KB

A Nim library for accessing serial ports.

License: BSD 3-Clause "New" or "Revised" License

Nim 100.00%

serial.nim's Introduction

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:

# Dependencies

requires "serial >= 1.0.0"

Usage

There are two examples in the examples directory, showing reading from and writing to a serialport.

Listing serial ports

import serial # Or: `import serial/utils`

for port in listSerialPorts():
  echo port

Reading from/writing to a serial port (echoing data)

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 = 2400

var receiveBuffer = newString(1024)
while true:
  let numReceived = port.read(receiveBuffer)
  discard port.write(receiveBuffer[0 ..< numReceived])

Using the SerialStream

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 iteratng possible device files
  • High level SerialPortStream that complies with the streams API
  • Async API using asyncdispatch for reading from and writing to a port

serial.nim's People

Contributors

euantorano avatar jeff-ciesielski avatar lucawolf avatar markprocess avatar markspanbroek avatar mp035 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.