

Overview — srly v0.6.5

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/msantos/srly/blob/v0.6.5/README.md#L1 "View Source")

Overview

===========================================================================================================

srly is a native interface to serial devices for Erlang, known to work

on Mac OS X, FreeBSD and Linux.

The C component of srly simply provides a wrapper to the system serial

interface. Data structures used as arguments to the native C functions

(such as struct termios) are provided as Erlang binaries, allowing

low level control of the serial device.

[compiling](#compiling)

 COMPILING

-----------------------------------

```

rebar3 compile

```

[usage](#usage)

 USAGE

-----------------------

*serctl* is the interface to the native system C libraries and follows

the system C interface.

```

serctl:open(Path) -> {ok, FD} | {error, posix()}

 Types Path = iodata() | {fd, FD}

 FD = resource()

 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.

serctl:close(FD) -> ok | {error, posix()}

 Types FD = resource()

 Explicitly close a serial device.

 The device is automatically closed if the process holding open

 the serial device exits.

serctl:read(FD, Size) -> {ok, Data} | {error, posix()}

 Types FD = resource()

 Size = integer()

 Data = binary()

 Read from a serial device.

 Size is an unsigned long.

serctl:readx(FD, Size) -> {ok, Data} | {error, posix()}

serctl:readx(FD, Size, Timeout) -> {ok, Data} | {error, posix()}

 Types FD = resource()

 Size = integer()

 Data = binary()

 Timeout = infinity | integer()

 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.)

serctl:write(FD, Data) -> ok | {ok, NBytes} | {error, posix()}

 Types FD = resource()

 Data = binary()

 NBytes = long()

 Write data to a serial device.

 Partial writes return the number of bytes written.

serctl:ioctl(FD, Request, In) -> {ok, Out} | {error, posix()}

 Types FD = resource()

 Request = ulong()

 In = binary()

 Out = binary()

 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.

```

The low level interface follows the C library (see tcgetattr(3),

tcsetattr(3), cfsetispeed(3) and cfsetospeed(3) for details). For

convenience, atoms may be used in places where C has defined macros for

integers and Erlang records can be used as arguments instead of binaries.

To use Erlang records to represent the C struct termios (e.g., when

converting binaries using serctl:termios/1) include their definition:

```

-include("serctl.hrl").

serctl:tcgetattr(FD) -> {ok, Termios} | {error, posix()}

 Types FD = resource()

 Termios = binary()

 Get the terminal attributes of a serial device.

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

serctl:tcsetattr(FD, Action, Termios) -> ok | {error, posix() | unsupported}

 Types FD = resource()

 Action = integer() | Option | Options

 Options = [Option]

 Option = tcsanow | tcsadrain | tcsaflush | tcsasoft

 Termios = binary() | #termios{}

 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.

serctl:cfsetispeed(Termios, Speed) -> Termios1

 Types Termios = binary() | #termios{}

 Speed = integer() | atom()

 Termios1 = binary()

 Set the input speed of a serial device.

 See the warning for tcsetattr/2.

 Failure: badarg if Speed is an invalid atom.

serctl:cfsetospeed(Termios, Speed) -> Termios1

 Types Termios = binary() | #termios{}

 Speed = integer() | atom()

 Termios1 = binary()

 Set the input speed of the serial device.

 See the warning for tcsetattr/2.

 Failure: badarg if Speed is an invalid atom.

serctl:getfd(FD) -> integer()

 Types FD = resource()

 Returns the file descriptor associated with the NIF resource.

 The file descriptor can be used with erlang:open\_port/2.

serctl:constant() -> Constants

serctl:constant(Attr) -> integer() | undefined

 Types Constants = [{Attr, integer()}]

 Attr = tiocm\_rts | tiocm\_dtr | tiocmset | tiocmget | tiocmbis

 | tiocmbic | tcsaflush | tcsadrain | tcsanow | tcioflush

 | tcoflush | tciflush | tcion | tcioff | tcoon | tcooff

 | iexten | tostop | noflsh | echonl | echoke | echok | echoe

 | echo | icanon | isig | crtscts | b1152000 | b1000000

 | b921600 | b576000 | b500000 | b460800 | b230400 | b115200

 | b57600 | clocal | hupcl | parodd | parenb | cread | cstopb

 | cs8 | cs7 | cs6 | cs5 | csize | b38400 | b19200 | b9600

 | b4800 | b2400 | b1800 | b1200 | b600 | b300 | b200 | b150

 | b134 | b110 | b75 | b50 | b0 | ofdel | ofill | onlret

 | onocr | ocrnl | onlcr | olcuc | opost | iutf8 | imaxbel

 | ixoff | ixany | ixon | iuclc | icrnl | igncr | inlcr

 | istrip | inpck | parmrk | ignpar | brkint | ignbrk | veol2

 | vlnext | vwerase | vdiscard | vreprint | veol | vsusp | vstop

 | vstart | vswtc | vmin | vtime | veof | vkill | verase | vquit

 | vintr | nccs

 Map of atoms representing terminal attribute constants to

 integers. Varies across platforms.

```

serctl has a higher level interface for manipulating the C data structures

that takes care of portability. The structures are represented as Erlang

records. These functions only retrieve or modify values within the termios

structure and do not have side effects when used with the record format

(when binaries are used as arguments, they are first converted to record

format based on a runtime platform check).

To modify the serial device, the attributes must be written out using

serctl:tcsetattr/3.

```

serctl:flow(Termios) -> true | false

serctl:flow(Termios, Bool) -> #termios{}

 Types Termios = binary() | #termios{}

 Bool = true | false

 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.

serctl:mode(Mode) -> #termios{}

 Types Mode = raw

 Returns an Erlang termios record with attributes that can be

 used to put the serial device into raw mode.

serctl:getflag(Termios, Flag, Opt) -> true | false

 Types Termios = binary() | #termios{}

 Flag = cflag | lflag | iflag | oflag

 Opt = atom()

 Returns whether a flag is enabled. Opt is one of the atoms

 returned using serctl:constant/0.

serctl:setflag(Termios, Opt) -> #termios{}

 Types Termios = #termios{}

 Opt = [Param]

 Param = {Flag, [Val]}

 Flag = cflag | lflag | iflag | oflag

 Val = {atom(), Bool}

 Bool = true | false

 Returns an Erlang termios record which can be 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).

serctl:ispeed(Termios) -> integer()

serctl:ispeed(Termios, Speed) -> #termios{} | binary()

serctl:ospeed(Termios) -> integer()

serctl:ospeed(Termios, Speed) -> #termios{} | binary()

 Types Termios = #termios{}

 Speed = integer() | atom()

 ispeed/1 and ospeed/1 return the input and output speed of the

 serial device. Note the speed returned is the constant defined

 for the system and may differ between platforms.

 ispeed/2 and ospeed/2 return an Erlang termios record that can be

 used for setting the input and output speed of the serial device.

 Failure: badarg if Speed is an invalid atom.

serctl:baud(Speed) -> integer()

 Types Speed = 115200 | 19200 | 9600 | ...

 Return the constant defined for the baud rate for the platform.

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

 Types Termios = #termios{} | binary()

 Convert between a C struct termios and an Erlang record.

```

[examples](#examples)

 EXAMPLES

--------------------------------

* Connect to an Arduino at 9600

```

 % Open the serial device

 {ok, FD} = serctl:open("/dev/ttyUSB0"),

 % Set the terminal attributes to:

 % raw, no hardware flow control, 9600

 Termios = lists:foldl(

 fun(Fun, Acc) -> Fun(Acc) end,

 serctl:mode(raw),

 [

 fun(N) -> serctl:flow(N, false) end,

 fun(N) -> serctl:ispeed(N, b9600) end,

 fun(N) -> serctl:ospeed(N, b9600) end

 ]

 ),

 ok = serctl:tcsetattr(FD, tcsanow, Termios),

 % Write 1 byte to the arduino

 ok = serctl:write(FD, <<1:8>>),

 % Read 2 bytes from the arduino (little-endian integer)

 {ok, <<Data:2/little-integer-unit:8>>} = serctl:read(FD, 2).

```

* Resetting DTR/RTS

```

 TIOCMGET = serctl:constant(tiocmget),

 TIOCMSET = serctl:constant(tiocmset),

 TIOCM\_DTR = serctl:constant(tiocm\_dtr),

 TIOCM\_RTS = serctl:constant(tiocm\_rts),

 % Get the current device settings

 {ok, <<Ctl:4/native-unsigned-integer-unit:8>>} = serctl:ioctl(

 FD,

 TIOCMGET,

 <<0:32>>

 ),

 Off = Ctl band bnot ( TIOCM\_DTR bor TIOCM\_RTS ),

 {ok, <<Ctl1:4/native-unsigned-integer-unit:8>>} = serctl:ioctl(

 FD,

 TIOCMSET,

 <<Off:4/native-unsigned-integer-unit:8>>

 ),

 On = Ctl1 bor ( TIOCM\_DTR bor TIOCM\_RTS ),

 serctl:ioctl(

 FD,

 TIOCMSET,

 <<On:4/native-unsigned-integer-unit:8>>

 ).

```

* See the examples directory. The code here is adapted from:

<http://blog.listincomprehension.com/2010/04/accessing-arduino-from-erlang.html>

	+ examples/strobe

	

	Serially turn on/off a row of LEDs.

	+ examples/ldr

	

	Read values from an LDR.

[todo](#todo)

 TODO

--------------------

* document srly

* test if the system C interface can actually be crashed!

* srly should be a well behaved OTP application that can deal with the

addition and removal of USB serial ports

[← Previous Page

 

API Reference](api-reference.html)

[Next Page →

 

LICENSE](license.html)





serctl — srly v0.6.5

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L31 "View Source")

serctl

(srly v0.6.5)

=============================================================================================================================

[Link to this section](#summary)

 Summary

==========================================

[Types](#types)

----------------

[dev/0](#t:dev/0)

[errno/0](#t:errno/0)

[fd/0](#t:fd/0)

[termios/0](#t:termios/0)

[Functions](#functions)

------------------------

[baud(Speed)](#baud/1)

Return the constant defined for the baud rate for the platform

[cfsetispeed(Termios, Speed)](#cfsetispeed/2)

Set the input speed of a serial device

[cfsetospeed(Termios, Speed)](#cfsetospeed/2)

Set the input speed of the serial device.

[close(\_)](#close/1)

Explicitly close a serial device

[constant()](#constant/0)

Map of atoms representing terminal attribute constants to integers

[constant(\_)](#constant/1)

[flow(Termios)](#flow/1)

Get/set serial device flow control

[flow(Termios, Bool)](#flow/2)

[getfd(\_)](#getfd/1)

Returns the file descriptor associated with the NIF resource

[getflag(Termios, Flag, Opt)](#getflag/3)

Returns whether a flag is enabled

[init()](#init/0)

[ioctl(\_, \_, \_)](#ioctl/3)

Perform operations controlling a serial device

[ispeed(Speed)](#ispeed/1)

return the input speed of a serial device

[ispeed(Termios, Speed)](#ispeed/2)

[mode(\_)](#mode/1)

Enable raw mode

[offset(Cc, \_)](#offset/2)

[open(Dev)](#open/1)

Open a serial device

[ospeed(Speed)](#ospeed/1)

return the output speed of a serial device

[ospeed(Termios, Speed)](#ospeed/2)

[read(\_, \_)](#read/2)

Read from a serial device

[readx(FD, N)](#readx/2)

Read the specified number of bytes from a serial device

[readx(FD, N, Timeout)](#readx/3)

[setflag(Termios, Opt)](#setflag/2)

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

[tcflush(FD, Discard)](#tcflush/2)

discards data written but not transmitted or received but not read

[tcgetattr(\_)](#tcgetattr/1)

Get the terminal attributes of a serial device

[tcsetattr(FD, Action, Termios)](#tcsetattr/3)

Sets the terminal attributes of a serial device

[termios(Termios)](#termios/1)

[wordalign(Offset)](#wordalign/1)

[wordalign(Offset, Align)](#wordalign/2)

[write(FD, Buf)](#write/2)

Write data to a serial device

[Link to this section](#types)

Types

=====================================

[Link to this type](#t:dev/0 "Link to this type")

dev/0

=====

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L74 "View Source")

```

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

```

[Link to this type](#t:errno/0 "Link to this type")

errno/0

=======

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L75 "View Source")

```

-type errno() :: {error, [file:posix](https://www.erlang.org/doc/man/file.html#type-posix)()}.

```

[Link to this type](#t:fd/0 "Link to this type")

fd/0

====

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L73 "View Source")

```

-type fd() :: any().

```

[Link to this type](#t:termios/0 "Link to this type")

termios/0

=========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L76 "View Source")

```

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

```

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#baud/1 "Link to this function")

baud(Speed)

===========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L499 "View Source")

Return the constant defined for the baud rate for the platform

 

[Link to this function](#cfsetispeed/2 "Link to this function")

cfsetispeed(Termios, Speed)

===========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L212 "View Source")

```

-spec cfsetispeed([termios](#t:termios/0)(), 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/2 "Link to this function")

cfsetospeed(Termios, Speed)

===========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L233 "View Source")

```

-spec cfsetospeed([termios](#t:termios/0)(), 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.

 

[Link to this function](#close/1 "Link to this function")

close(\_)

=========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L114 "View Source")

```

-spec close([fd](#t:fd/0)()) -> {ok, [fd](#t:fd/0)()} | [errno](#t:errno/0)().

```

Explicitly close a serial device

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

 

[Link to this function](#constant/0 "Link to this function")

constant()

==========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L280 "View Source")

```

-spec constant() -> [proplists:proplist](https://www.erlang.org/doc/man/proplists.html#type-proplist)().

```

Map of atoms representing terminal attribute constants to integers

Varies across platforms.

 

[Link to this function](#constant/1 "Link to this function")

constant(\_)

============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L284 "View Source")

```

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

```

[Link to this function](#flow/1 "Link to this function")

flow(Termios)

=============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L405 "View Source")

```

-spec 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.

 

[Link to this function](#flow/2 "Link to this function")

flow(Termios, Bool)

===================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L409 "View Source")

```

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

```

[Link to this function](#getfd/1 "Link to this function")

getfd(\_)

=========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L291 "View Source")

```

-spec getfd([fd](#t:fd/0)()) -> 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/3 "Link to this function")

getflag(Termios, Flag, Opt)

===========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L379 "View Source")

```

-spec 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.

 

[Link to this function](#init/0 "Link to this function")

init()

======

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L85 "View Source")

[Link to this function](#ioctl/3 "Link to this function")

ioctl(\_, \_, \_)

=================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L273 "View Source")

```

-spec ioctl([fd](#t:fd/0)(), integer(), binary()) -> {ok, binary()} | [errno](#t:errno/0)().

```

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.

ioctl/3 can be used for implementing most serial operations.

### 

[examples](#ioctl/3-examples)

Examples

```

 -define(TCXONC, 16#540A).

 tcflow(FD, Action) when is\_atom(Action) ->

 case serctl:constant(Action) of

 undefined ->

 {error, unsupported};

 N ->

 serctl:ioctl(

 fd,

 ?TCFLSH,

 <<N:4/native-unsigned-integer-unit:8>>

 )

 end.

```

[Link to this function](#ispeed/1 "Link to this function")

ispeed(Speed)

=============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L452 "View Source")

```

-spec 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.

 

[Link to this function](#ispeed/2 "Link to this function")

ispeed(Termios, Speed)

======================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L458 "View Source")

```

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

```

[Link to this function](#mode/1 "Link to this function")

mode(\_)

========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L416 "View Source")

Enable raw mode

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

 

[Link to this function](#offset/2 "Link to this function")

offset(Cc, \_)

==============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L872 "View Source")

[Link to this function](#open/1 "Link to this function")

open(Dev)

=========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L98 "View Source")

```

-spec open([dev](#t:dev/0)()) -> {ok, [fd](#t:fd/0)()} | [errno](#t:errno/0)().

```

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.

 

[Link to this function](#ospeed/1 "Link to this function")

ospeed(Speed)

=============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L480 "View Source")

```

-spec 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.

 

[Link to this function](#ospeed/2 "Link to this function")

ospeed(Termios, Speed)

======================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L486 "View Source")

```

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

```

[Link to this function](#read/2 "Link to this function")

read(\_, \_)

============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L121 "View Source")

```

-spec read([fd](#t:fd/0)(), non_neg_integer()) -> {ok, binary()} | [errno](#t:errno/0)().

```

Read from a serial device

Size is an unsigned long.

 

[Link to this function](#readx/2 "Link to this function")

readx(FD, N)

============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L308 "View Source")

```

-spec readx([fd](#t:fd/0)(), non_neg_integer()) -> {ok, binary()} | [errno](#t:errno/0)().

```

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.)

 

[Link to this function](#readx/3 "Link to this function")

readx(FD, N, Timeout)

=====================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L312 "View Source")

```

-spec readx([fd](#t:fd/0)(), non_neg_integer(), timeout()) -> {ok, binary()} | [errno](#t:errno/0)().

```

[Link to this function](#setflag/2 "Link to this function")

setflag(Termios, Opt)

=====================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L336 "View Source")

```

-spec setflag(binary() | #termios{}, [proplists:proplist](https://www.erlang.org/doc/man/proplists.html#type-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).

```

[Link to this function](#tcflush/2 "Link to this function")

tcflush(FD, Discard)

====================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L195 "View Source")

```

-spec tcflush([fd](#t:fd/0)(), atom()) -> ok | [errno](#t:errno/0)() | {error, unsupported}.

```

discards data written but not transmitted or received but not read

The second argument determines whether to flush input, output, or both

 

[Link to this function](#tcgetattr/1 "Link to this function")

tcgetattr(\_)

=============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L144 "View Source")

```

-spec tcgetattr([fd](#t:fd/0)()) -> {ok, binary()} | [errno](#t:errno/0)().

```

Get the terminal attributes of a serial device

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

 

[Link to this function](#tcsetattr/3 "Link to this function")

tcsetattr(FD, Action, Termios)

==============================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L156 "View Source")

```

-spec tcsetattr([fd](#t:fd/0)(), [atom()] | atom() | integer(), [termios](#t:termios/0)()) -> ok | [errno](#t:errno/0)() | {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.

 

[Link to this function](#termios/1 "Link to this function")

termios(Termios)

================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L571 "View Source")

```

-spec termios(binary() | #termios{}) -> binary() | #termios{}.

```

[Link to this function](#wordalign/1 "Link to this function")

wordalign(Offset)

=================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L867 "View Source")

[Link to this function](#wordalign/2 "Link to this function")

wordalign(Offset, Align)

========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L869 "View Source")

[Link to this function](#write/2 "Link to this function")

write(FD, Buf)

==============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/serctl.erl#L128 "View Source")

```

-spec write([fd](#t:fd/0)(), iodata()) -> ok | {ok, non_neg_integer()} | [errno](#t:errno/0)().

```

Write data to a serial device

Partial writes return the number of bytes written.

 





srly — srly v0.6.5

 try {

 var settings = JSON.parse(localStorage.getItem('ex\_doc:settings') || '{}');

 if (settings.theme === 'dark' ||

 ((settings.theme === 'system' || settings.theme == null) &&

 window.matchMedia('(prefers-color-scheme: dark)').matches)

 ) {

 document.body.classList.add('dark')

 }

 } catch (error) { }

 

Settings

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L30 "View Source")

srly

(srly v0.6.5)

=========================================================================================================================

[Link to this section](#summary)

 Summary

==========================================

[Functions](#functions)

------------------------

[close(Ref)](#close/1)

[code\_change(OldVsn, State, Extra)](#code_change/3)

[controlling\_process(Ref, Pid)](#controlling_process/2)

[getfd(Ref)](#getfd/1)

[handle\_call(\_, From, State)](#handle_call/3)

[handle\_cast(Msg, State)](#handle_cast/2)

[handle\_info(Info, State)](#handle_info/2)

[init(\_)](#init/1)

[open(Dev)](#open/1)

[open(Dev, Opt)](#open/2)

[read(FD, Len)](#read/2)

[send(Ref, Data)](#send/2)

[start\_link(Dev, Opt)](#start_link/2)

[terminate(Reason, State)](#terminate/2)

[write(FD, Data)](#write/2)

[Link to this section](#functions)

Functions

=============================================

[Link to this function](#close/1 "Link to this function")

close(Ref)

==========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L77 "View Source")

[Link to this function](#code_change/3 "Link to this function")

code\_change(OldVsn, State, Extra)

==================================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L187 "View Source")

[Link to this function](#controlling_process/2 "Link to this function")

controlling\_process(Ref, Pid)

==============================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L94 "View Source")

[Link to this function](#getfd/1 "Link to this function")

getfd(Ref)

==========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L81 "View Source")

[Link to this function](#handle_call/3 "Link to this function")

handle\_call(\_, From, State)

=============================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L145 "View Source")

[Link to this function](#handle_cast/2 "Link to this function")

handle\_cast(Msg, State)

========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L164 "View Source")

[Link to this function](#handle_info/2 "Link to this function")

handle\_info(Info, State)

=========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L170 "View Source")

[Link to this function](#init/1 "Link to this function")

init(\_)

========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L105 "View Source")

[Link to this function](#open/1 "Link to this function")

open(Dev)

=========

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L71 "View Source")

[Link to this function](#open/2 "Link to this function")

open(Dev, Opt)

==============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L74 "View Source")

[Link to this function](#read/2 "Link to this function")

read(FD, Len)

=============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L84 "View Source")

[Link to this function](#send/2 "Link to this function")

send(Ref, Data)

===============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L90 "View Source")

[Link to this function](#start_link/2 "Link to this function")

start\_link(Dev, Opt)

=====================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L98 "View Source")

[Link to this function](#terminate/2 "Link to this function")

terminate(Reason, State)

========================

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L181 "View Source")

[Link to this function](#write/2 "Link to this function")

write(FD, Data)

===============

[View Source](https://github.com/msantos/srly/blob/v0.6.5/src/srly.erl#L87 "View Source")

