Module serctl

Copyright © 2011-2021 Michael Santos <michael.santos@gmail.com>

Data Types

dev()

dev() = iodata() | {fd, integer()}

errno()

errno() = {error, file:posix()}

fd()

fd() = any()

termios()

termios() = #termios{} | binary()

Function Index

baud/1Return the constant defined for the baud rate for the platform.
cfsetispeed/2Set the input speed of a serial device.
cfsetospeed/2Set the input speed of the serial device.
close/1Explicitly close a serial device.
constant/0Map of atoms reprsenting terminal attribute constants to integers.
constant/1
flow/1Get/set serial device flow control.
flow/2
getfd/1Returns the file descriptor associated with the NIF resource.
getflag/3Returns whether a flag is enabled.
init/0
ioctl/3Perform operations controlling a serial device.
ispeed/1return the input speed of a serial device.
ispeed/2
mode/1Enable raw mode.
offset/2
open/1Open a serial device.
ospeed/1return the output speed of a serial device.
ospeed/2
read/2Read from a serial device.
readx/2Read the specified number of bytes from a serial device.
readx/3
setflag/2Returns an Erlang termios record used for setting the attributes of a serial device.
tcgetattr/1Get the terminal attributes of a serial device.
tcsetattr/3Sets the terminal attributes of a serial device.
termios/1
wordalign/1
wordalign/2
write/2Write data to a serial device.

Function Details

baud/1

baud(Speed) -> any()

Return the constant defined for the baud rate for the platform

cfsetispeed/2

cfsetispeed(Termios::termios(), Speed::atom() | integer()) -> binary()

Set the input speed of a serial device

See the warning for tcsetattr/2.

Failure: badarg if Speed is an invalid atom.

cfsetospeed/2

cfsetospeed(Termios::termios(), Speed::atom() | integer()) -> binary()

Set the input speed of the serial device.

See the warning for tcsetattr/2.

Failure: badarg if Speed is an invalid atom.

close/1

close(X1::fd()) -> {ok, fd()} | errno()

Explicitly close a serial device

The device is automatically closed if the process holding open the serial device exits.

constant/0

constant() -> proplists:proplist()

Map of atoms reprsenting terminal attribute constants to integers

Varies across platforms.

constant/1

constant(X1::atom()) -> integer() | undefined

flow/1

flow(Termios::<<_:64, _:_*8>> | #termios{}) -> boolean()

Get/set serial device flow control

flow/1 indicates whether flow control is enabled in a serial device's terminal attributes. flow/2 returns a termios structure that can be used for setting a serial device's flow control.

flow/2

flow(Termios::<<_:64, _:_*8>> | #termios{}, Bool::boolean()) -> #termios{}

getfd/1

getfd(X1::fd()) -> integer()

Returns the file descriptor associated with the NIF resource

The file descriptor can be used with erlang:open_port/2.

getflag/3

getflag(Termios::<<_:64, _:_*8>> | #termios{}, Flag::cflag | iflag | lflag | oflag, Opt::atom()) -> boolean()

Returns whether a flag is enabled

Opt is one of the atoms returned using serctl:constant/0.

init/0

init() -> any()

ioctl/3

ioctl(X1::fd(), X2::integer(), X3::binary()) -> {ok, binary()} | errno()

Perform operations controlling a serial device

The In argument is a binary holding the input parameter to the device request. The Out parameter will hold the result of the request if the ioctl is in/out.

ispeed/1

ispeed(Speed::binary() | #termios{}) -> non_neg_integer()

return the input speed of a serial device

Note the speed returned is the constant defined for the system and may differ between platforms.

ispeed/2 returns an Erlang termios record that can be used for setting the input speed of the serial device.

Failure: badarg if Speed is an invalid atom.

ispeed/2

ispeed(Termios::<<_:64, _:_*8>> | #termios{}, Speed::atom() | integer()) -> <<_:8, _:_*8>> | #termios{}

mode/1

mode(X1) -> any()

Enable raw mode

Returns an Erlang termios record with attributes that can be used to put the serial device into raw mode.

offset/2

offset(Cc, X2) -> any()

open/1

open(Dev::dev()) -> {ok, fd()} | errno()

Open a serial device

A serial device is a character device such as /dev/ttyUSB0.

A previously opened file descriptor can also be used. The fd should be opened with the O_NONBLOCK|O_NOCTTY flags.

ospeed/1

ospeed(Speed::binary() | #termios{}) -> non_neg_integer()

return the output speed of a serial device

Note the speed returned is the constant defined for the system and may differ between platforms.

ospeed/2 returns an Erlang termios record that can be used for setting the output speed of the serial device.

Failure: badarg if Speed is an invalid atom.

ospeed/2

ospeed(Termios::<<_:64, _:_*8>> | #termios{}, Speed::atom() | integer()) -> <<_:8, _:_*8>> | #termios{}

read/2

read(X1::fd(), X2::non_neg_integer()) -> {ok, binary()} | errno()

Read from a serial device

Size is an unsigned long.

readx/2

readx(FD::fd(), N::non_neg_integer()) -> {ok, binary()} | errno()

Read the specified number of bytes from a serial device

readx/2 will block forever.

readx/3 accepts a timeout value. The behaviour of readx/3 when the timeout is reached is to throw away any buffered data and return {error, eintr} to the caller, e.g., the caller will not be returned the contents of a partial read. (The justification for this behaviour: the caller has stated they require a fixed number of bytes so the contents of a partial read represents unspecified behaviour.)

readx/3

readx(FD::fd(), N::non_neg_integer(), Timeout::timeout()) -> {ok, binary()} | errno()

setflag/2

setflag(Termios::binary() | #termios{}, Opt::proplists:proplist()) -> #termios{}

Returns an Erlang termios record used for setting the attributes of a serial device

For example, to create attributes that can be used to enable hardware flow control on a serial device:

 {ok, FD} = serctl:open("/dev/ttyUSB0"),
 {ok, Termios} = serctl:tcgetattr(FD),
 Termios1 = serctl:setflag(Termios, [{cflag, [{crtscts, true}]}]),
 ok = serctl:tcsetattr(FD, tcsanow, Termios1).

tcgetattr/1

tcgetattr(X1::fd()) -> {ok, binary()} | errno()

Get the terminal attributes of a serial device

Returns the contents of the system struct termios as a binary.

tcsetattr/3

tcsetattr(FD::fd(), Action::[atom()] | atom() | integer(), Termios::termios()) -> ok | errno() | {error, unsupported}

Sets the terminal attributes of a serial device

'tcsasoft' is a non-portable, BSD action. tcsetattr/3 will return {error,unsupported} on other platforms. Warning: the contents of Termios are passed directly to tcsettr(3). If the system tcsettr(3) does not perform any validation of the structure, it is possible the Erlang VM may crash.

termios/1

termios(Termios::binary() | #termios{}) -> binary() | #termios{}

wordalign/1

wordalign(Offset) -> any()

wordalign/2

wordalign(Offset, Align) -> any()

write/2

write(FD::fd(), Buf::iodata()) -> ok | {ok, non_neg_integer()} | errno()

Write data to a serial device

Partial writes return the number of bytes written.


Generated by EDoc