@hackage serialport0.6.0
Cross platform serial port library.
Categories
License
BSD-3-Clause
Maintainer
David Cox <standard.semiconductor@gmail.com>
Links
Versions
Installation
Dependencies (5)
- Win32 >=2.11 && <2.15
- base >=4.12 && <4.22
- bytestring >=0.11 && <0.13
- optparse-applicative >=0.18 && <0.20
- unix >=2.8 && <2.9 Show all…
Dependents (18)
@hackage/crystalfontz, @hackage/ham, @hackage/NXT, @hackage/tidal-serial, @hackage/HaMinitel, @hackage/tidal, Show all…
Serialport
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
- Arduino Leonardo + Sparkfun FTDI breakout board.
- Connections: TX, RX and GND
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"