This module provides the serial port interface.
import System.Hardware.Serialport let port = "COM3" -- Windows let port = "/dev/ttyUSB0" -- Linux s <- openSerial port defaultSerialSettings { commSpeed = CS2400 } sendString s "AT\r" recvString s >>= print closeSerial s
- data CommSpeed
- data StopBits
- data Parity
- data FlowControl
- data SerialPort
- data SerialPortSettings = SerialPortSettings {
- commSpeed :: CommSpeed
- bitsPerWord :: Word8
- stopb :: StopBits
- parity :: Parity
- flowControl :: FlowControl
- timeout :: Int
- defaultSerialSettings :: SerialPortSettings
- setSerialSettings :: SerialPort -> SerialPortSettings -> IO SerialPort
- getSerialSettings :: SerialPort -> SerialPortSettings
- openSerial :: FilePath -> SerialPortSettings -> IO SerialPort
- closeSerial :: SerialPort -> IO ()
- sendChar :: SerialPort -> Char -> IO ()
- sendString :: SerialPort -> String -> IO ()
- recvChar :: SerialPort -> IO (Maybe Char)
- recvString :: SerialPort -> IO String
- setDTR :: SerialPort -> Bool -> IO ()
- setRTS :: SerialPort -> Bool -> IO ()
Types
Supported baudrates
data SerialPort Source
Configure port
You don't need the get or set functions, they are used by openSerial
data SerialPortSettings Source
SerialPortSettings | |
|
defaultSerialSettings :: SerialPortSettingsSource
Most commonly used configuration
- 9600 baud
- 8 data bits
- 1 stop bit
- no parity
- no flow control
- 0.1 millisecond receive timeout
:: SerialPort | The currently opened serial port |
-> SerialPortSettings | The new settings |
-> IO SerialPort | New serial port |
Configure the serial port
getSerialSettings :: SerialPort -> SerialPortSettingsSource
Get configuration from serial port
Serial methods
Device
:: FilePath | The filename of the serial port, such as |
-> SerialPortSettings | |
-> IO SerialPort |
Open and configure a serial port
closeSerial :: SerialPort -> IO ()Source
Close the serial port
Sending & receiving
sendString :: SerialPort -> String -> IO ()Source
Send a string
recvChar :: SerialPort -> IO (Maybe Char)Source
Possibly receive a character unless the timeout given in openSerial is exceeded.
recvString :: SerialPort -> IO StringSource
Receive a string