baud v0.2.0 Baud.Rtu
Rtu module.
alias Baud.Rtu
{:ok, pid} = Rtu.start_link([portname: "cu.usbserial-FTVFV143", baudrate: "57600"])
:ok = Rtu.wcoils(pid, 1, 3200, [0,0,0,0,0,0,0,0]);
:ok = Rtu.wcoil(pid, 1, 3200, 1);
{:ok, 1} = Rtu.rcoil(pid, 1, 3200);
:ok = Rtu.wcoil(pid, 1, 3203, 1);
{:ok, [1, 0, 0, 1]} = Rtu.rcoils(pid, 1, 3200, 4);
:ok = Rtu.discard(pid)
:ok = Rtu.echo(pid)
:ok = Rtu.close(pid)
Summary
Functions
Closes the serial port and waits for confirmation
Discards all data in the input and output buffers of the serial port
Tests if the native port has compleated all previous commands
Turns off a coil
Turns on a coil
Gets the value (0 | 1) of a coil
Gets the values (0 | 1) for the required coils
Starts the GenServer
Stops the GenServer with :normal
Turns on or off a coil depending on provided value
Turns on or off a coil depending on provided value list
Functions
Closes the serial port and waits for confirmation.
Stopping the GenServer will close the port stdio pipes the native port will exit upon detection of a closed stdio and the OS will release the serial port. All this happens automatically but also within an undefined time frame.
There are times when releasing the OS resources in a timely manner is required. In unit testing for example, you want the previous test to release the serial port before attemping to open it again in the next test (and fail).
Returns :ok.
Gets the values (0 | 1) for the required coils.
Returns a list of values for the number of requested coils.
Starts the GenServer.
state must contain a keyword list to be merged with the following defaults:
%{
portname: "TTY", #the port name: "COM1", "ttyUSB0", "cu.usbserial-FTYHQD9MA"
baudrate: "115200", #either 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200
bitconfig: "8N1", #either 8N1, 7E1, 7O1
}
opts is optional and is passed verbatim to GenServer.
Returns {:ok, pid}.
Example
Baud.Server.start_link([portname: "COM8"])
Turns on or off a coil depending on provided value.
Returns :ok | :error.