Created
October 1, 2013 08:27
-
-
Save crabmusket/6775408 to your computer and use it in GitHub Desktop.
Infinite serial listener in Haskell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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