-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | POSIX serial port wrapper -- -- Provides a clean interface to working with POSIX serial ports in -- Haskell @package serial @version 0.2.2 -- | This is a largely drop-in replacement for System.Serial.Manager -- which sends and receives one command at a time from the port, and so -- is garuanteed to send the write information back to the right -- function. It may be necessary when working with devices that have -- ambiguous returns, such as a single acknowledgement character for all -- successful commands. See the analagous functions in -- System.Serial.Manager for the full documentation. The notes -- here only point out the differences. module System.Serial.BlockingManager -- | The blocking serialManager function takes one additional -- argument, the timeout (since it cannot continue executing commands in -- parallel while one command freezes). serialManager :: Handle -> Int -> IO BlockingSerialManager -- | Wrapping commands is identical to the non-blocking version except that -- there is no predicate to recognize return values. wrapCommand :: String -> String -> BlockingSerialManager -> IO (Maybe String) type BlockingSerialManager = MVar BlockingSerialCommand type BlockingSerialCommand = (String, MVar (Maybe String)) -- | Many serial devices allow multiple commands to run at once, and | -- return their results as they finish. To make use of this, | multiple -- commands needs to read and write to the serial port at | once, and the -- return values must somehow be sorted and returned | back to the -- callers. module System.Serial.Manager -- | serialManager takes produces a structure around a Handle -- to | handle multiple callers to the serial port. The return value is | -- the channel to which all commands will flow. Users should use | the -- wrapCommand function to access it instead of trying to | access -- its details directly. serialManager :: Handle -> IO SerialManager -- | All the commands to operate a SerialManager should be -- specializations of wrapCommand, created by applying it to the -- first three arguments, then using that thereafter as the command to -- the serial port. -- -- For example, the Olympus IX-81 requires a login command from the user -- (2LOG IN) followed by rn as an end of line. The -- response will be 2LOG + followed by r. So a login -- command would look like -- --
--   p = do string "2LOG +\r"
--          return True
--   
-- --
--   login mgr = wrapCommand "\r\n" "2LOG IN" p
--   
-- -- wrapCommand uses parsers that return Bool so users can -- choose whether or not to match any given command based upon its -- contents, rather than just blindly saying whether it matches or not. -- This may change to simple predicates of String -> Bool in -- future. wrapCommand :: String -> String -> (String -> Bool) -> SerialManager -> IO String type SerialManager = MVar (Either SerialCommand String) type SerialCommand = (String, String -> Bool, MVar String) -- | Serial provides access to serial ports on POSIX compatible systems. -- The utility functions in System.Serial are in line-at-a-time -- mode by default, but you can set other, more raw modes with -- hSetBuffering from System.IO. The serial port managers -- in System.Serial.Manager and -- System.Serial.BlockingManager only work with line-at-a-time -- mode. -- -- Most devices hanging off of serial ports today work by reading and -- writing commands. In many cases, commands are non-blocking and you can -- send additional commands before you receive the response to the last -- one. System.Serial.SerialManager provides a wrapper around this -- access which tries to match up responses to waiting functions which -- have called it. -- -- The only function here is openSerial, since thereafter the -- normal functions from System.IO such as hClose, -- hGetLine, and hPutStr work normally. Just be sure you -- send the right end of line sequence for your hardware! Some devices -- want CR-LF, others just LF, others just CR, and they may return their -- results using a different end of line than they accept. module System.Serial -- | openSerial opens the serial port and sets the options the user -- passes, makes its buffering line oriented, and returns the handle to -- control it. For example, an Olympus IX-81 microscope attached to the -- first serial port on Linux would be opened with -- --
--   openSerial "/dev/ttyS0" B19200 8 One Even Software
--   
openSerial :: String -> BaudRate -> Int -> StopBits -> Parity -> FlowControl -> IO Handle -- | Serial lets the user set the number of stop bits, the parity, -- flow control (there is no hardware flow control, since it isn't -- supported in the System.Posix.IO library), number of bits per -- byte, and the baud rate. The baud rate is declared by the -- BaudRate in System.Posix.Terminal. StopBits, -- Parity, and FlowControl are defined here. data StopBits One :: StopBits Two :: StopBits data Parity Even :: Parity Odd :: Parity NoParity :: Parity data FlowControl Software :: FlowControl NoFlowControl :: FlowControl