serialport: Cross platform serial port library.

[ bsd3, hardware, library ] [ Propose Tags ]

Cross platform haskell library for using the serial port.


[Skip to Readme]
Versions [RSS] [faq] 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
Change log CHANGELOG.md
Dependencies base (>=4.12 && <4.16), bytestring (==0.11.*), unix (==2.7.*), Win32 (>=2.11 && <2.14) [details]
License BSD-3-Clause
Copyright (c) 2009-2011 Joris Putcuyps, (c) 2020-2021 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 2021-09-26T20:29:53Z
Distributions NixOS:0.5.2
Downloads 14319 total (172 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
All reported builds failed as of 2021-09-26 [all 1 reports]

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees

Candidates


Readme for serialport-0.5.3

[back to package description]

Serialport

Haskell CI Hackage Hackage Dependencies

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 ( concurrently_ )
import Control.Monad            ( forever )
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"