I'm trying to send a message via the serial port to a Lego NXT using Haskell's interactive mode but I cannot figure out how to use the serialport functions correctly.
I have a message that should play a tone on the NXT which is of type ByteString
> let message = pack ([6, 0 ,0, 3, 224, 1, 208, 7]::[Word8])
I can open the serial port using openSerial
.
openSerial :: FilePath -> SerialPortSettings -> IO SerialPort
> let mybrick = openSerial "/dev/tty.NXT-DevB" defaultSerialSettings
But then I get stuck. How should I use the send
function?
send :: SerialPort -> B.ByteString -> IO Int
> send mybrick message
This gives my the following error message.
<interactive>:31:6:
Couldn't match expected type `SerialPort'
with actual type `IO SerialPort'
In the first argument of `send', namely `mybrick'
In the expression: send mybrick message
In an equation for `it': it = send mybrick message