Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Infinite serial listener in Haskell.

View Serial.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
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
Something went wrong with that request. Please try again.