serialport 0.5.6 → 0.6.0
raw patch · 7 files changed
+157/−9 lines, 7 filesdep +asyncdep +optparse-applicativedep ~basenew-component:exe:serialport
Dependencies added: async, optparse-applicative
Dependency ranges changed: base
Files
- CHANGELOG.md +6/−0
- System/Hardware/Serialport/Cli.hs +114/−0
- System/Hardware/Serialport/Posix.hsc +0/−1
- System/Hardware/Serialport/Types.hs +1/−2
- System/Win32/Comm.hsc +0/−1
- exe/Main.hs +19/−0
- serialport.cabal +17/−5
CHANGELOG.md view
@@ -1,3 +1,9 @@+0.6.0 (9/21/2025)+==================+* Remove custom baud rates [22](https://github.com/standardsemiconductor/serialport/pull/22)+* Update package dependency constraints+* Add `serialport` command-line executable [16](https://github.com/standardsemiconductor/serialport/pull/16)+ 0.5.6 (11/23/2024) ================== * Add custom baud rates [13](https://github.com/standardsemiconductor/serialport/pull/13)
+ System/Hardware/Serialport/Cli.hs view
@@ -0,0 +1,114 @@+module System.Hardware.Serialport.Cli+ ( SerialPortCli(..)+ , serialPortCli+ , -- * Parsers+ serialPortCliParser+ , serialPortPathParser+ , serialPortSettingsParser+ , commSpeedParser+ , bitsPerWordParser+ , stopBitsParser+ , parityParser+ , flowControlParser+ , timeoutParser+ ) where++import Data.Word+import Options.Applicative+import System.Hardware.Serialport.Types++data SerialPortCli = SerialPortCli+ { serialPortPath :: FilePath+ , serialPortSettings :: SerialPortSettings+ }++serialPortCli :: IO SerialPortCli+serialPortCli =+ customExecParser serialPortCliPrefs $+ info (serialPortCliParser <**> helper) mempty++serialPortCliPrefs :: ParserPrefs+serialPortCliPrefs = prefs $ showHelpOnError <> showHelpOnEmpty++serialPortCliParser :: Parser SerialPortCli+serialPortCliParser =+ SerialPortCli+ <$> serialPortPathParser+ <*> serialPortSettingsParser++serialPortPathParser :: Parser FilePath+serialPortPathParser = strArgument $ mconcat+ [ help "serial port file path"+ , metavar "<tty-device>"+ , completer $ bashCompleter "file"+ ]++serialPortSettingsParser :: Parser SerialPortSettings+serialPortSettingsParser =+ SerialPortSettings+ <$> commSpeedParser+ <*> bitsPerWordParser+ <*> stopBitsParser+ <*> parityParser+ <*> flowControlParser+ <*> timeoutParser++commSpeedParser :: Parser CommSpeed+commSpeedParser = option auto $ mconcat+ [ long "baudrate"+ , short 'b'+ , value CS115200+ , showDefault+ , metavar "<bps>"+ , help "Baud rate"+ ]++bitsPerWordParser :: Parser Word8+bitsPerWordParser = option auto $ mconcat+ [ long "databits"+ , short 'd'+ , value $ bitsPerWord defaultSerialSettings+ , showDefault+ , metavar "7|8"+ , help "Data bits"+ ]++stopBitsParser :: Parser StopBits+stopBitsParser = option auto $ mconcat+ [ long "stopbits"+ , short 's'+ , value $ stopb defaultSerialSettings+ , showDefault+ , metavar "One|Two"+ , help "Stop bits"+ ]++parityParser :: Parser Parity+parityParser = option auto $ mconcat+ [ long "parity"+ , short 'p'+ , value $ parity defaultSerialSettings+ , showDefault+ , metavar "Even|Odd|NoParity"+ , help "Parity"+ ]++flowControlParser :: Parser FlowControl+flowControlParser = option auto $ mconcat+ [ long "flow"+ , short 'f'+ , value $ flowControl defaultSerialSettings+ , showDefault+ , metavar "Software|NoFlowControl"+ , help "Flow control"+ ]++timeoutParser :: Parser Int+timeoutParser = option auto $ mconcat+ [ long "timeout"+ , short 't'+ , value $ timeout defaultSerialSettings+ , showDefault+ , metavar "TIME"+ , help "Timeout in tenth-of-seconds"+ ]
System/Hardware/Serialport/Posix.hsc view
@@ -210,4 +210,3 @@ CS38400 -> B38400 CS57600 -> B57600 CS115200 -> B115200- CS b -> fromIntegral b
System/Hardware/Serialport/Types.hs view
@@ -16,8 +16,7 @@ | CS38400 | CS57600 | CS115200- | CS Word32- deriving (Show, Read, Eq)+ deriving (Show, Read, Eq, Bounded) data StopBits = One | Two deriving (Show, Read, Eq, Bounded)
System/Win32/Comm.hsc view
@@ -230,4 +230,3 @@ CS38400 -> (#const CBR_38400) CS57600 -> (#const CBR_57600) CS115200 -> (#const CBR_115200)- CS b -> fromIntegral b
+ exe/Main.hs view
@@ -0,0 +1,19 @@+import Control.Concurrent.Async+import Control.Monad+import System.Hardware.Serialport+import System.Hardware.Serialport.Cli+import System.IO++main :: IO ()+main = do+ opts <- serialPortCli+ hWithSerial (serialPortPath opts) (serialPortSettings opts) com++com :: Handle -> IO ()+com hndl = do+ hSetBuffering stdin NoBuffering+ hSetBuffering stdout NoBuffering+ concurrently_ readUart writeUart+ where+ readUart = forever $ putChar =<< hGetChar hndl+ writeUart = forever $ hPutChar hndl =<< getChar
serialport.cabal view
@@ -1,11 +1,11 @@ Name: serialport-Version: 0.5.6+Version: 0.6.0 Cabal-Version: >= 1.10 Build-Type: Simple license: BSD3 license-file: LICENSE copyright: (c) 2009-2011 Joris Putcuyps,- (c) 2020-2024 David Cox+ (c) 2020-2025 David Cox author: Joris Putcuyps, David Cox maintainer: David Cox <standard.semiconductor@gmail.com> homepage: https://github.com/standardsemiconductor/serialport@@ -23,10 +23,12 @@ Library Exposed-Modules: System.Hardware.Serialport+ System.Hardware.Serialport.Cli Other-Modules: System.Hardware.Serialport.Types- Build-Depends: base >= 4.12 && < 4.21,- bytestring >= 0.11 && < 0.13- ghc-options: -Wall -fno-warn-orphans+ Build-Depends: base >= 4.12 && < 4.22,+ bytestring >= 0.11 && < 0.13,+ optparse-applicative >= 0.18 && < 0.20+ ghc-options: -Wall default-language: Haskell2010 if !os(windows)@@ -36,6 +38,16 @@ Build-Depends: Win32 >= 2.11 && < 2.15 Other-Modules: System.Hardware.Serialport.Windows System.Win32.Comm++executable serialport+ ghc-options: -Wall -O2 -threaded+ main-is: Main.hs+ hs-source-dirs: exe+ default-language: Haskell2010+ build-depends: async >= 2.2 && < 2.3,+ base,+ optparse-applicative >= 0.18 && < 0.19,+ serialport Test-Suite Tests type: exitcode-stdio-1.0