-- 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.5 -- | 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 -> String -> String -> IO SerialManager -- | Having multiple serial managers running on the same port is a disaster -- waiting to happen. When you're done with a SerialManager, run -- closeSerialManager on it to shut it down. closeSerialManager :: SerialManager -> IO () -- | 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 = ("2LOG" `isPrefixOf`)
--   
-- --
--   login mgr = wrapCommand "\r\n" "2LOG IN" p
--   
-- -- wrapCommand uses functions of type 'String -> Bool' 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. wrapCommand :: String -> (String -> Bool) -> SerialManager -> IO String -- | Sometimes we don't want the current thread to block, but we still want -- some action when the a command returns from the serial port. To that -- end, wrapCommandWithCallback lets us pass a function of type -- 'String -> IO ()' to be executed when a response is recognized by -- the predicate. wrapCommandWithCallback :: String -> (String -> Bool) -> (String -> IO ()) -> SerialManager -> IO ThreadId data SerialManager 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