serialport 0.3.2 → 0.3.3
raw patch · 6 files changed
+50/−26 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- System.Hardware.Serialport.Posix: c_ioctl' :: Fd -> Int -> Ptr d -> IO ()
+ System.Hardware.Serialport: setRTS :: SerialPort -> Bool -> IO ()
+ System.Hardware.Serialport.Posix: cIoctl' :: Fd -> Int -> Ptr d -> IO ()
+ System.Hardware.Serialport.Posix: setRTS :: SerialPort -> Bool -> IO ()
Files
- System/Hardware/Serialport.hs +2/−1
- System/Hardware/Serialport/Posix.hsc +13/−6
- System/Hardware/Serialport/Types.hs +5/−4
- System/Hardware/Serialport/Windows.hs +8/−0
- System/Win32/Comm.hsc +21/−14
- serialport.cabal +1/−1
System/Hardware/Serialport.hs view
@@ -18,11 +18,12 @@ ,recvChar ,closeSerial ,setDTR+ ,setRTS ) where #if defined(mingw32_HOST_OS) import System.Hardware.Serialport.Windows-#elif defined(linux_HOST_OS)+#else import System.Hardware.Serialport.Posix import System.Posix.Terminal #endif
System/Hardware/Serialport/Posix.hsc view
@@ -1,7 +1,6 @@ {-# LANGUAGE ForeignFunctionInterface #-} module System.Hardware.Serialport.Posix where -import System.IO import System.IO.Error import System.Posix.IO import System.Posix.Types@@ -9,7 +8,6 @@ import System.Hardware.Serialport.Types import Foreign import Foreign.C-import Data.Bits -- |Open and configure a serial port@@ -47,20 +45,20 @@ foreign import ccall "ioctl" c_ioctl :: CInt -> CInt -> Ptr () -> IO CInt -c_ioctl' :: Fd -> Int -> Ptr d -> IO ()-c_ioctl' f req =+cIoctl' :: Fd -> Int -> Ptr d -> IO ()+cIoctl' f req = throwErrnoIfMinus1_ "ioctl" . c_ioctl (fromIntegral f) (fromIntegral req) . castPtr getTIOCM :: Fd -> IO Int getTIOCM fd' =- alloca $ \p -> c_ioctl' fd' (#const TIOCMGET) p >> peek p+ alloca $ \p -> cIoctl' fd' (#const TIOCMGET) p >> peek p setTIOCM :: Fd -> Int -> IO () setTIOCM fd' val =- with val $ c_ioctl' fd' (#const TIOCMSET)+ with val $ cIoctl' fd' (#const TIOCMSET) -- |Set the Data Terminal Ready level@@ -70,6 +68,15 @@ setTIOCM fd' $ if set then current .|. (#const TIOCM_DTR) else current .&. (complement (#const TIOCM_DTR))+++-- |Set the Ready to send level+setRTS :: SerialPort -> Bool -> IO ()+setRTS (SerialPort fd' _) set =+ do current <- getTIOCM fd'+ setTIOCM fd' $ if set+ then current .|. (#const TIOCM_RTS)+ else current .&. (complement (#const TIOCM_RTS)) setSerialSettings :: Fd -> SerialPortSettings -> IO ()
System/Hardware/Serialport/Types.hs view
@@ -2,10 +2,7 @@ module System.Hardware.Serialport.Types where import Data.Word-#if defined(linux_HOST_OS)-import System.Posix.Terminal-import System.Posix.Types-#elif defined(mingw32_HOST_OS)+#if defined(mingw32_HOST_OS) import System.Win32.Types -- | Same as System.Posix.Terminal@@ -28,6 +25,10 @@ | B38400 | B57600 | B115200++#else+import System.Posix.Terminal+import System.Posix.Types #endif fromBaudToInt :: BaudRate -> Int
System/Hardware/Serialport/Windows.hs view
@@ -67,6 +67,14 @@ else Comm.clrDTR +-- |Set the Ready to send level+setRTS :: SerialPort -> Bool -> IO ()+setRTS (SerialPort h _ ) set =+ Comm.escapeCommFunction h $ if set + then Comm.setRTS+ else Comm.clrRTS++ setSerialSettings :: HANDLE -> SerialPortSettings -> IO () setSerialSettings h settings = do let ct = Comm.COMMTIMEOUTS {
System/Win32/Comm.hsc view
@@ -46,12 +46,13 @@ (#poke DCB, XoffLim) buf (512 :: WORD) (#poke DCB, ByteSize) buf (byteSize dcb :: BYTE) (#poke DCB, Parity) buf (case (parity dcb) of- STypes.NoParity -> 0- STypes.Odd -> 1- STypes.Even -> 2 :: BYTE)+ STypes.NoParity -> (#const NOPARITY)+ STypes.Odd -> (#const ODDPARITY)+ STypes.Even -> (#const EVENPARITY) + :: BYTE) (#poke DCB, StopBits) buf (case (stopBits dcb) of- STypes.One -> 0- STypes.Two -> 2+ STypes.One -> (#const ONESTOPBIT)+ STypes.Two -> (#const TWOSTOPBITS) :: BYTE) (#poke DCB, wReserved1) buf (0 :: WORD) peek buf = do@@ -62,17 +63,17 @@ _byteSize <- (#peek DCB, ByteSize) buf :: IO BYTE _parity <- do _par <- (#peek DCB, Parity) buf :: IO BYTE case _par of- 0 -> return STypes.NoParity- 1 -> return STypes.Odd- 2 -> return STypes.Even- 3 -> fail $ "unsupported markparity"- 4 -> fail $ "unsupported spaceparity"- _ -> fail $ "unsupported parity" ++ (show _par)+ (#const NOPARITY) -> return STypes.NoParity+ (#const ODDPARITY) -> return STypes.Odd+ (#const EVENPARITY) -> return STypes.Even+ (#const MARKPARITY) -> fail $ "unsupported markparity"+ (#const SPACEPARITY) -> fail $ "unsupported spaceparity"+ _ -> fail $ "unsupported parity" ++ (show _par) _stopBits <- do _stopb <- (#peek DCB, StopBits) buf :: IO BYTE case _stopb of- 0 -> return STypes.One- 1 -> fail $ "unsupported one5stopbits"- 2 -> return STypes.Two+ (#const ONESTOPBIT) -> return STypes.One+ (#const ONE5STOPBITS) -> fail $ "unsupported one5stopbits"+ (#const TWOSTOPBITS) -> return STypes.Two _ -> fail "unexpected stop bit count" _XonLim <- (#peek DCB, XonLim) buf :: IO WORD _XoffLim <- (#peek DCB, XoffLim) buf :: IO WORD@@ -190,6 +191,12 @@ setDTR :: DWORD setDTR = #const SETDTR++clrRTS :: DWORD+clrRTS = #const CLRRTS++setRTS :: DWORD+setRTS = #const SETRTS -- --
serialport.cabal view
@@ -1,5 +1,5 @@ Name: serialport-Version: 0.3.2+Version: 0.3.3 Cabal-Version: >= 1.2 Build-Type: Simple license: BSD3