serialport: Cross platform serial port library.

[ bsd3, hardware, library ] [ Propose Tags ] [ Report a vulnerability ]

Cross platform haskell library for using the serial port.


[Skip to Readme]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0, 0.1.0.1, 0.1.0.2, 0.2.0, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.4.0, 0.4.0.1, 0.4.1, 0.4.2, 0.4.3, 0.4.4, 0.4.5, 0.4.6, 0.4.7, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.5.6
Change log CHANGELOG.md
Dependencies base (>=4.12 && <4.21), bytestring (>=0.11 && <0.13), unix (>=2.8 && <2.9), Win32 (>=2.11 && <2.15) [details]
License BSD-3-Clause
Copyright (c) 2009-2011 Joris Putcuyps, (c) 2020-2024 David Cox
Author Joris Putcuyps, David Cox
Maintainer David Cox <standard.semiconductor@gmail.com>
Category Hardware
Home page https://github.com/standardsemiconductor/serialport
Bug tracker https://github.com/standardsemiconductor/serialport/issues
Source repo head: git clone https://github.com/standardsemiconductor/serialport
Uploaded by dopamane at 2024-11-23T10:21:31Z
Distributions NixOS:0.5.5
Reverse Dependencies 15 direct, 6 indirect [details]
Downloads 16922 total (71 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
All reported builds failed as of 2024-11-23 [all 1 reports]

Readme for serialport-0.5.6

[back to package description]

Serialport

Haskell CI Hackage

Cross platform (Linux, Windows and Mac OS) serial port interface.

Sample Usage

import System.IO
import System.Hardware.Serialport
import qualified Data.ByteString.Char8 as B

let port = "COM3"         -- Windows
let port = "/dev/ttyUSB0" -- Linux
withSerial port defaultSerialSettings $ \s -> do
  send s $ B.pack "AT\r"
  recv s 10 >>= print

Concurrently read and write a serial port at 19200 baud using hWithSerial:

import Control.Concurrent.Async
import Control.Monad
import System.Hardware.Serialport
import System.IO

com :: String -> IO ()
com portPath = hWithSerial portPath serialPortSettings $ \hndl -> do
  hSetBuffering stdin NoBuffering
  hSetBuffering stdout NoBuffering
  concurrently_ (readUart hndl) (writeUart hndl)
    where
      readUart  hndl = forever $ putChar =<< hGetChar hndl
      writeUart hndl = forever $ hPutChar hndl =<< getChar

serialPortSettings :: SerialPortSettings
serialPortSettings = defaultSerialSettings{ commSpeed = CS19200 }

Tests

Setup

Prepare Arduino

  • Upload arduino code using Arduino IDE or avrdude

Prepare haskell test program

  • Configure cabal to build the tests: cabal configure --enable-tests.
  • Build: cabal build

Running the tests

  • Run the tests: cabal test --test-options="/dev/ttyACM0 /dev/ttyUSB0"