Skip to content

Yet another MODBUS library, supporting both TCP and RTU, providing gateway functionality.

Notifications You must be signed in to change notification settings

tombo-works/modbuzz

Repository files navigation

Modbuzz

hex CI license REUSE

Yet another MODBUS library, supporting both TCP and RTU, providing gateway functionality.

Index

Usage

TCP client

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)

RTU client

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)

Data server

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)

TCP server

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)

RTU server

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/RTU gateway

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/TCP gateway

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/TCP gateway

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/RTU gateway

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)

Installation

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.

License

This project is licensed under the Apache-2.0 license.

And this project follows the REUSE compliance. For more details, see the REUSE SOFTWARE.

MODBUS References

About

Yet another MODBUS library, supporting both TCP and RTU, providing gateway functionality.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published