{-# LANGUAGE CPP #-}
module System.Hardware.Serialport (
CommSpeed(..)
,StopBits(..)
,Parity(..)
,FlowControl(..)
,SerialPort
,SerialPortSettings(..)
,defaultSerialSettings
,setSerialSettings
,getSerialSettings
,hOpenSerial
,openSerial
,closeSerial
,withSerial
,hWithSerial
,send
,recv
,flush
,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
import System.IO (Handle, hClose)
import qualified Control.Exception as Ex
withSerial :: FilePath -> SerialPortSettings -> ( SerialPort -> IO a ) -> IO a
withSerial :: FilePath -> SerialPortSettings -> (SerialPort -> IO a) -> IO a
withSerial FilePath
dev SerialPortSettings
settings = IO SerialPort
-> (SerialPort -> IO ()) -> (SerialPort -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
Ex.bracket (FilePath -> SerialPortSettings -> IO SerialPort
openSerial FilePath
dev SerialPortSettings
settings) SerialPort -> IO ()
closeSerial
hWithSerial :: FilePath -> SerialPortSettings -> (Handle -> IO a) -> IO a
hWithSerial :: FilePath -> SerialPortSettings -> (Handle -> IO a) -> IO a
hWithSerial FilePath
dev SerialPortSettings
settings = IO Handle -> (Handle -> IO ()) -> (Handle -> IO a) -> IO a
forall a b c. IO a -> (a -> IO b) -> (a -> IO c) -> IO c
Ex.bracket (FilePath -> SerialPortSettings -> IO Handle
hOpenSerial FilePath
dev SerialPortSettings
settings) Handle -> IO ()
hClose