serialport-0.6.0: Cross platform serial port library.
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.Hardware.Serialport

Description

This module provides the serial port interface.

import qualified Data.ByteString.Char8 as B
import System.Hardware.Serialport
let port = "COM3"          -- Windows
let port = "/dev/ttyUSB0"  -- Linux
withSerial port defaultSerialSettings{ commSpeed = CS2400 } $ \s -> do
  send s $ B.pack "AT\r"
  recv s 10 >>= print

Alternatively, use handles to perform IO:

import System.IO
import System.Hardware.Serialport
let port = "COM3"           -- Windows
let port = "/dev/ttyUSB0"   -- Linux
hWithSerial port defaultSerialSettings $ \h -> do
  hPutStr h "AT\r"
  hGetLine h >>= print
Synopsis

Types

data CommSpeed Source #

Supported baudrates

Instances

Instances details
Bounded CommSpeed Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Read CommSpeed Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

readsPrec :: Int -> ReadS CommSpeed

readList :: ReadS [CommSpeed]

readPrec :: ReadPrec CommSpeed

readListPrec :: ReadPrec [CommSpeed]

Show CommSpeed Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

showsPrec :: Int -> CommSpeed -> ShowS

show :: CommSpeed -> String

showList :: [CommSpeed] -> ShowS

Eq CommSpeed Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

(==) :: CommSpeed -> CommSpeed -> Bool

(/=) :: CommSpeed -> CommSpeed -> Bool

data StopBits Source #

Constructors

One 
Two 

Instances

Instances details
Bounded StopBits Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Read StopBits Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

readsPrec :: Int -> ReadS StopBits

readList :: ReadS [StopBits]

readPrec :: ReadPrec StopBits

readListPrec :: ReadPrec [StopBits]

Show StopBits Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

showsPrec :: Int -> StopBits -> ShowS

show :: StopBits -> String

showList :: [StopBits] -> ShowS

Eq StopBits Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

(==) :: StopBits -> StopBits -> Bool

(/=) :: StopBits -> StopBits -> Bool

data Parity Source #

Constructors

Even 
Odd 
NoParity 

Instances

Instances details
Read Parity Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

readsPrec :: Int -> ReadS Parity

readList :: ReadS [Parity]

readPrec :: ReadPrec Parity

readListPrec :: ReadPrec [Parity]

Show Parity Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

showsPrec :: Int -> Parity -> ShowS

show :: Parity -> String

showList :: [Parity] -> ShowS

Eq Parity Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

(==) :: Parity -> Parity -> Bool

(/=) :: Parity -> Parity -> Bool

data FlowControl Source #

Constructors

Software 
NoFlowControl 

Instances

Instances details
Read FlowControl Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

readsPrec :: Int -> ReadS FlowControl

readList :: ReadS [FlowControl]

readPrec :: ReadPrec FlowControl

readListPrec :: ReadPrec [FlowControl]

Show FlowControl Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

showsPrec :: Int -> FlowControl -> ShowS

show :: FlowControl -> String

showList :: [FlowControl] -> ShowS

Eq FlowControl Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

(==) :: FlowControl -> FlowControl -> Bool

(/=) :: FlowControl -> FlowControl -> Bool

data SerialPort Source #

Instances

Instances details
Show SerialPort Source # 
Instance details

Defined in System.Hardware.Serialport.Posix

Methods

showsPrec :: Int -> SerialPort -> ShowS

show :: SerialPort -> String

showList :: [SerialPort] -> ShowS

Configure port

You don't need the get or set functions, they are used by openSerial

data SerialPortSettings Source #

Constructors

SerialPortSettings 

Fields

Instances

Instances details
Read SerialPortSettings Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Show SerialPortSettings Source # 
Instance details

Defined in System.Hardware.Serialport.Types

Methods

showsPrec :: Int -> SerialPortSettings -> ShowS

show :: SerialPortSettings -> String

showList :: [SerialPortSettings] -> ShowS

Eq SerialPortSettings Source # 
Instance details

Defined in System.Hardware.Serialport.Types

defaultSerialSettings :: SerialPortSettings Source #

Most commonly used configuration

  • 9600 baud
  • 8 data bits
  • 1 stop bit
  • no parity
  • no flow control
  • 0.1 second receive timeout

setSerialSettings Source #

Arguments

:: SerialPort

The currently opened serial port

-> SerialPortSettings

The new settings

-> IO SerialPort

New serial port

Configure the serial port

getSerialSettings :: SerialPort -> SerialPortSettings Source #

Get configuration from serial port

Serial methods

Device

hOpenSerial :: FilePath -> SerialPortSettings -> IO Handle Source #

Open and configure a serial port returning a standard Handle

openSerial Source #

Arguments

:: FilePath

Serial port, such as /dev/ttyS0 or /dev/ttyUSB0

-> SerialPortSettings 
-> IO SerialPort 

Open and configure a serial port

closeSerial :: SerialPort -> IO () Source #

Close the serial port

withSerial :: FilePath -> SerialPortSettings -> (SerialPort -> IO a) -> IO a Source #

Safer device function, so you don't forget to close the device

hWithSerial :: FilePath -> SerialPortSettings -> (Handle -> IO a) -> IO a Source #

Like withSerial but using Handle

Sending & receiving

send Source #

Arguments

:: SerialPort 
-> ByteString 
-> IO Int

Number of bytes actually sent

Send bytes

recv :: SerialPort -> Int -> IO ByteString Source #

Receive bytes, given the maximum number

flush :: SerialPort -> IO () Source #

Flush buffers

Line control

setDTR :: SerialPort -> Bool -> IO () Source #

Set the Data Terminal Ready level

setRTS :: SerialPort -> Bool -> IO () Source #

Set the Ready to send level