Yet another MODBUS library, supporting both TCP and RTU, providing gateway functionality.
Modbuzz.start_tcp_client/3
starts a TCP client instance.
Modbuzz.request/3
requests synchronously.
The 2nd argument, unit_id
, can be omitted. If omitted, its value defaults to 0.
:ok = Modbuzz.start_tcp_client(:your_tcp_client, {192, 168, 0, 10}, 502)
alias Modbuzz.PDU.WriteSingleCoil
req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
{:ok, _res} = Modbuzz.request(:your_tcp_client, req)
Modbuzz.start_rtu_client/3
starts a RTU client instance.
Modbuzz.request/3
requests synchronously.
The 2nd argument, unit_id
, can be omitted. If omitted, its value defaults to 0.
:ok = Modbuzz.start_rtu_client(:your_rtu_client, "ttyUSB0", [speed: 9600])
alias Modbuzz.PDU.WriteSingleCoil
req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
{:ok, _res} = Modbuzz.request(:your_rtu_client, 1, req)
Modbuzz.start_data_server/1
starts a Data server instance.
Data server can be used as data source of TCP/RTU server.
:ok = Modbuzz.start_data_server(:your_data_server)
alias Modbuzz.PDU.WriteSingleCoil
req = %WriteSingleCoil.Req{output_address: 0 , output_value: true}
res = %WriteSingleCoil.Res{output_address: 0 , output_value: true}
:ok = Modbuzz.create_unit(:your_data_server, 1)
:ok = Modbuzz.upsert(:your_data_server, 1, req, res)
Modbuzz.start_tcp_server/4
starts a TCP server instance.
The 4th argument, data_source
, can be Data server
/ TCP client / RTU client.
:ok = Modbuzz.start_tcp_server(:your_tcp_server, {192, 168, 1, 10}, 502, :your_data_source)
Modbuzz.start_rtu_server/4
starts a RTU server instance.
The 4th argument, data_source
, can be Data server
/ TCP client / RTU client.
:ok = Modbuzz.start_tcp_server(:your_rtu_server, "ttyUSB1", [speed: 19200], :your_data_source)
TCP server receives a request and pass through it to RTU client.
:ok = Modbuzz.start_rtu_client(:your_rtu_client, "ttyUSB0", [speed: 9600])
:ok = Modbuzz.start_tcp_server(:your_tcp_server, {192, 168, 1, 10}, 502, :your_rtu_client)
RTU server receives a request and pass through it to TCP client.
:ok = Modbuzz.start_tcp_client(:your_tcp_client, {192, 168, 0, 10}, 502)
:ok = Modbuzz.start_rtu_server(:your_rtu_server, "ttyUSB1", [speed: 19200], :your_tcp_client)
TCP server receives a request and pass through it to TCP client.
:ok = Modbuzz.start_tcp_client(:your_tcp_client, {192, 168, 0, 10}, 502)
:ok = Modbuzz.start_tcp_server(:your_tcp_server, {192, 168, 1, 10}, 502, :your_tcp_client)
RTU server receives a request and pass through it to RTU client.
:ok = Modbuzz.start_rtu_client(:your_rtu_client, "ttyUSB0", [speed: 9600])
:ok = Modbuzz.start_rtu_server(:your_rtu_server, "ttyUSB1", [speed: 19200], :your_rtu_client)
If available in Hex, the package can be installed
by adding modbuzz
to your list of dependencies in mix.exs
:
def deps do
[
{:modbuzz, "~> 0.2.0"}
]
end
Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/modbuzz.
This project is licensed under the Apache-2.0 license.
And this project follows the REUSE compliance. For more details, see the REUSE SOFTWARE.