Skip to content

Instantly share code, notes, and snippets.

@caiorss
Forked from crabmusket/recvLn.hs
Last active August 29, 2015 14:23
Show Gist options
  • Save caiorss/29f47171a4fb7fafa000 to your computer and use it in GitHub Desktop.
Save caiorss/29f47171a4fb7fafa000 to your computer and use it in GitHub Desktop.
import qualified Data.ByteString.Char8 as B
import System.Hardware.Serialport (SerialPort, recv)
recvLn :: SerialPort -> IO B.ByteString
recvLn s = do
-- Receive one byte at a time.
first <- recv s 1
rest <- if first == B.singleton '\n'
then return $ B.empty
else recvLn s
-- Once the recursion finishes, we glue the parts together.
return $ first `B.append` rest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment