serialport-0.4.2: System/Hardware/Serialport.hs
{-# LANGUAGE CPP #-}
-- |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
--
module System.Hardware.Serialport (
-- * Types
CommSpeed(..)
,StopBits(..)
,Parity(..)
,FlowControl(..)
,SerialPort
-- * Configure port
-- | You don't need the get or set functions, they are used by openSerial
,SerialPortSettings(..)
,defaultSerialSettings
,setSerialSettings
,getSerialSettings
-- * Serial methods
-- ** Device
,openSerial
,closeSerial
,withSerial
-- ** Sending & receiving
,sendChar
,sendString
,recvChar
,recvString
,flush
-- ** Line control
,setDTR
,setRTS
) where
#if defined(mingw32_HOST_OS)
import System.Hardware.Serialport.Windows
#else
import System.Hardware.Serialport.Posix
#endif
import System.Hardware.Serialport.Types
-- |Safer device function, so you don't forget to close the device
withSerial :: String -> SerialPortSettings -> ( SerialPort -> IO a ) -> IO a
withSerial dev settings f = do
s <- openSerial dev settings
res <- f s
closeSerial s
return res