haskell-serialport

Usage

Examples

Simple ping

Pick out a serial device, for example a modem or a GPS, and connect it to your computer.

Fire up your ghci and import the required libraries:

> import System.Hardware.Serialport
> import Control.Monad
> import Control.Monad.Loops

Open the serial port:

> s <- openSerial "/dev/ttyUSB0" defaultSerialSettings
-- or a little different
> s <- openSerial "/dev/ttyUSB0" defaultSerialSettings { baudRate = B2400 }

Sending a simple AT\r:

> forM_ "AT\r" $ sendChar s

Receiving:

> response <- unfoldM (recvChar s)
> print response

Free the port:

> closeSerial s

Reset Arduino

The reset of Arduino is attached to the DTR, Data Terminal Ready line. By toggling this line, the processor will reset.

> import System.Hardware.Serialport
> import Control.Concurrent
> s <- openSerial "/dev/ttyUSB0" defaultSerialSettings
> setDTR s False
> threadDelay 500000
> setDTR s True
> closeSerial s

API

For a more detailed description of the library, check out the generated documents on hackage.