serial-0.2.1: POSIX serial port wrapper



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.



serialManager :: Handle -> IO SerialManagerSource

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.



:: String

The end of line character for this port

-> String

The command to send

-> (String -> Bool)

The predicate to recognize the returning value

-> SerialManager

The serial port to access

-> IO String

The response from the port

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.