Create a gist now

Instantly share code, notes, and snippets.

Infinite serial listener in Haskell.
import Control.Monad (forever)
import Control.Concurrent (forkIO, killThread)
import qualified Data.ByteString.Char8 as B
import System.Hardware.Serialport
(openSerial, recv, closeSerial, defaultSerialSettings)
port = "COM1" -- Windows
--port = "/dev/ttyUSB0" -- Unix
main = do
putStrLn "Press ENTER to exit."
s <- openSerial port defaultSerialSettings
t <- forkIO $ forever $ do
recv s 1 >>= B.putStr
_ <- getLine
killThread t
closeSerial s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment