baud v0.4.2 Baud.Sock
Server module to export individual serial ports thru a socket.
A single remote socket connection is supported. Each new socket connection closes and replaces the previous one. Native port is open until a connection is made and will be closed when the connection closes. Serial port should be free while there is no connection.
Summary
Functions
Starts the listening socket server
Functions
Starts the listening socket server.
state is a keyword list to be merged with the following defaults:
%{
mode: :text,
ip: {127,0,0,1},
port: 0,
baudrate: "115200",
bitconfig: "8N1",
bufsize: 255,
packto: 0,
}
mode can be :text, :rtu_master, :rtu_slave, :rtu_tcpgw or :raw.
Text mode buffers data from the serial port and forwards complete lines
terminated in \n. RTU modes buffer data, adds or removes CRC, and
forwards complete packets. TCP gateway translates bidirectionally from
Modbus TCP to Modbus RTU. Raw mode forwards data received within the
packetization timeout.
ip can be any valid IP with {0,0,0,0} and {127,0,0,1} meaning any interface or
local loop interface respectively.
port is the tcp port number where the serial port will be served.
portname is the name of the serial port to be exported.
baudrate can be any of 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200.
bitconfig can be any of 8N1, 7E1, 7O1.
packto is a packetization timeout in milliseconds mainly for the raw mode. Serial ports are slow
and you will be forwarding lots of partial packets if no packetization strategy is used.
Packets are \n and CRC terminated in text and modbus mode respectively.
Raw mode can use a timeout for that effect. Modbus and text modes may benefit as well
on certain scenarios but should work ok without it (zero value).
bufsize is the buffer size. Handling of packets larger that this will crash the native port.
opts is optional and is passed verbatim to GenServer.
Returns {:ok, pid}.
Example
Baud.Sock.start_link([portname: "ttyUSB0", port: 5000], [name: Baud.Sock])