packages feed

serialport 0.3.0 → 0.3.1

raw patch · 5 files changed

+23/−102 lines, 5 files

Files

− README
@@ -1,47 +0,0 @@-% Haskell serialport--Name------	serialport - Cross platform serial port library.---Description--------------This library provides a way to interface the serial port from haskell in a cross platform way.--Tested on the following platforms:- - - Linux (Arch, Fedora 11, OpenSuse 11.1)- - Windows XP 32-bit --This library is far from finished and is currently in a "Eureka, I can talk to a -raw serial device on Linux and Windows" state. I released it because some people were looking-for something like this. Especially on Windows it was a challenge.---Install----------Install using the standard Hackagedb way:--	cabal update-	cabal install serialport---Problems & suggestions-------------------------Can be reported via e-mail: joris.putcuyps@gmail.com---References------------ - Frederick Ross with his serial package: http://hackage.haskell.org/package/serial- - Python serial library http://pyserial.sourceforge.net/- - http://www.easysw.com/~mike/serial/serial.html- - Ruby serial port library http://ruby-serialport.rubyforge.org/- - C++ libraries -   - Common cpp: http://www.gnu.org/software/commoncpp/-   - Boost asio serial: http://www.boost.org/-
System/Hardware/Serialport.hs view
@@ -1,23 +1,5 @@ {-# LANGUAGE CPP #-} --- | Example usage:------ > import System.Hardware.Serialport--- > --- > s <- openSerial "/dev/ttyUSB0" defaultSerialSettings--- > -- or a little different--- > s <- openSerial "/dev/ttyUSB0" defaultSerialSettings { baudRate = B2400 }--- > --- > -- Sending--- > forM_ "AT\r" $ sendChar s--- > --- > -- Receiving, using unfoldM from Control.Monad.Loops--- > response <- unfoldM (recvChar s)--- > --- > print response--- > --- > closeSerial s---   module System.Hardware.Serialport (   -- * Types
System/Hardware/Serialport/Posix.hs view
@@ -1,7 +1,9 @@ module System.Hardware.Serialport.Posix where  import System.IO+import System.IO.Error import System.Posix.IO+import System.Posix.Types import System.Posix.Terminal import System.Hardware.Serialport.Types @@ -11,46 +13,37 @@            -> SerialPortSettings            -> IO SerialPort openSerial dev settings =-  do setSerialSettings dev settings-     h <- openBinaryFile dev ReadWriteMode-     hSetBuffering h NoBuffering-     return $ SerialPort h settings+  do fd' <- openFd dev ReadWrite Nothing defaultFileFlags { noctty = True }+     setSerialSettings fd' settings+     return $ SerialPort fd' settings           -- |Possibly receive a character unless the timeout given in openSerial is exceeded. recvChar :: SerialPort -> IO (Maybe Char)-recvChar (SerialPort h settings) =-  do have_input <- hWaitForInput h ((timeout settings) * 100)-     if have_input-        then do c <- hGetChar h-                return $ Just c-        else return Nothing+recvChar (SerialPort fd' _) =+  do result <- try $ fdRead fd' 1+     case result of+       Right (str, _) -> return $ Just $ head str+       Left _         -> return Nothing   -- |Send a character sendChar :: SerialPort -> Char -> IO ()-sendChar (SerialPort h _ ) c =-    hPutChar h c >> return ()+sendChar (SerialPort fd' _ ) c =+  fdWrite fd' [c] >> return ()   -- |Close the serial port closeSerial :: SerialPort -> IO ()-closeSerial (SerialPort h _ ) =-    hClose h+closeSerial (SerialPort fd' _ ) =+  closeFd fd'   -setSerialSettings :: FilePath -> SerialPortSettings -> IO ()-setSerialSettings dev settings = -  do fd <- openFd dev ReadWrite Nothing -           OpenFileFlags { append = True,-                           exclusive = True,-                           noctty = True,-                           nonBlock = False,-                           trunc = False }-     termOpts <- getTerminalAttributes fd+setSerialSettings :: Fd -> SerialPortSettings -> IO ()+setSerialSettings fd' settings = +  do termOpts <- getTerminalAttributes fd'      let termOpts' = configureSettings termOpts settings-     setTerminalAttributes fd termOpts' Immediately-     closeFd fd+     setTerminalAttributes fd' termOpts' Immediately   withParity :: TerminalAttributes -> Parity -> TerminalAttributes@@ -95,4 +88,6 @@                  `withoutMode` ExtendedFunctions                  `withMode` LocalMode                  `withMode` ReadEnable+                 `withTime` (timeout settings)+                 `withMinInput` 0 
System/Hardware/Serialport/Types.hs view
@@ -4,7 +4,7 @@ import Data.Word #if defined(linux_HOST_OS) import System.Posix.Terminal-import System.IO+import System.Posix.Types #elif defined(mingw32_HOST_OS) import System.Win32.Types @@ -114,7 +114,7 @@ #if defined(mingw32_HOST_OS)                       handle :: HANDLE, #else-                      handle :: Handle,+                      fd :: Fd, #endif                       newSettings :: SerialPortSettings                   }
serialport.cabal view
@@ -1,5 +1,5 @@ Name:           serialport-Version:        0.3.0+Version:        0.3.1 Cabal-Version:  >= 1.2 Build-Type:     Simple license:        BSD3@@ -10,15 +10,6 @@ homepage:       http://users.skynet.be/jputcu/projects/haskell-serialport/index.html bug-reports:    mailto:Joris.Putcuyps@gmail.com synopsis:       Cross platform serial port library.  --description:    This library provides a way to interface the serial port from haskell in a cross platform way.-                .-                Tested on the following platforms:-                . -                 * Linux (Arch)-                .-                 * Windows XP 32-bit- category:       Hardware  Library