serctl (srly v0.6.2) View Source

Link to this section Summary

Functions

Return the constant defined for the baud rate for the platform

Set the input speed of a serial device

Set the input speed of the serial device.

Explicitly close a serial device

Map of atoms reprsenting terminal attribute constants to integers

Get/set serial device flow control

Returns the file descriptor associated with the NIF resource

Returns whether a flag is enabled

Perform operations controlling a serial device

return the input speed of a serial device

Enable raw mode

Open a serial device

return the output speed of a serial device

Read from a serial device

Read the specified number of bytes from a serial device

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

Get the terminal attributes of a serial device

Sets the terminal attributes of a serial device

Write data to a serial device

Link to this section Types

Specs

dev() :: iodata() | {fd, integer()}.

Specs

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

Specs

fd() :: any().

Specs

termios() :: #termios{} | binary().

Link to this section Functions

Return the constant defined for the baud rate for the platform
Link to this function

cfsetispeed(Termios, Speed)

View Source

Specs

cfsetispeed(termios(), 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.
Link to this function

cfsetospeed(Termios, Speed)

View Source

Specs

cfsetospeed(termios(), 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.

Specs

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

Explicitly close a serial device

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

Specs

constant() -> proplists:proplist().

Map of atoms reprsenting terminal attribute constants to integers

Varies across platforms.

Specs

constant(atom()) -> integer() | undefined.

Specs

flow(<<_: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.

Specs

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

Specs

getfd(fd()) -> integer().

Returns the file descriptor associated with the NIF resource

The file descriptor can be used with erlang:open_port/2.
Link to this function

getflag(Termios, Flag, Opt)

View Source

Specs

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

Returns whether a flag is enabled

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

Specs

ioctl(fd(), integer(), 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.

Specs

ispeed(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.

Specs

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

Enable raw mode

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

Specs

open(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.

Specs

ospeed(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.

Specs

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

Specs

read(fd(), non_neg_integer()) -> {ok, binary()} | errno().

Read from a serial device

Size is an unsigned long.

Specs

readx(fd(), 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.)

Specs

readx(fd(), non_neg_integer(), timeout()) -> {ok, binary()} | errno().

Specs

setflag(binary() | #termios{}, 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).

Specs

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

Get the terminal attributes of a serial device

Returns the contents of the system struct termios as a binary.
Link to this function

tcsetattr(FD, Action, Termios)

View Source

Specs

tcsetattr(fd(), [atom()] | atom() | integer(), 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.

Specs

termios(binary() | #termios{}) -> binary() | #termios{}.
Link to this function

wordalign(Offset, Align)

View Source

Specs

write(fd(), iodata()) -> ok | {ok, non_neg_integer()} | errno().

Write data to a serial device

Partial writes return the number of bytes written.