Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

A Nim library for accessing serial ports.

License

NotificationsYou must be signed in to change notification settings

euantorano/serial.nim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 theexamples directory, showing reading from and writing to a serialport.

Listing serial ports

import serial# Or: `import serial/utils`for portinlistSerialPorts():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 bitport.open(9600,Parity.None,8,StopBits.One)# You can modify the baud rate, parity, databits, etc. after opening the portport.baudRate=2400var receiveBuffer=newString(1024)whiletrue: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)whiletrue:# 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, usingSetupDiGetClassDevs
    • Mac, using I/O Kit
    • Posix, by iterating possible device files
  • High levelSerialPortStream that complies with thestreams API
  • Async API usingasyncdispatch for reading from and writing to a port

[8]ページ先頭

©2009-2025 Movatter.jp