Skip to main content

Modbus client/server for qToggleServer

Project description

About

This is an addon for qToggleServer.

With this addon you can read and control Modbus-enabled devices (such as energy meters) via qToggleServer. You can also configure a Modbus server so that your qToggleServer behaves like a Modbus device itself.

Install

Install using pip:

pip install qtoggleserver-modbus

Usage

Serial Client

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.ModbusSerialClient"
        method = rtu                    # `ascii` (default), `rtu` or `binary`
        serial_port = "/dev/ttyUSB0"
        serial_baud = 9600              # this is the default
        serial_stopbits = 1             # this is the default
        serial_bytesize = 8             # this is the default
        serial_parity = N               # `N`, `E` or `O` (defaults to `N`)
        handle_local_echo = false       # this is the default
        # see below for common parameters
    }
    ...
]
...

Serial Server

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.ModbusSerialServer"
        method = rtu                    # `ascii` (default), `rtu` or `binary`
        serial_port = "/dev/ttyUSB0"
        serial_baud = 9600              # this is the default
        serial_stopbits = 1             # this is the default
        serial_bytesize = 8             # this is the default
        serial_parity = N               # `N`, `E` or `O` (defaults to `N`)
        # see below for common parameters
    }
    ...
]
...

TCP Client

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.ModbusTcpClient"
        method = socket                 # `socket` (default), `ascii`, `rtu` or `binary`
        tcp_host = "192.168.0.2"        # IP or hostname of the Modbus device
        tcp_port = 502                  # Modbus device TCP port
        # see below for common parameters
    }
    ...
]
...

TCP Server

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.ModbusTcpServer"
        method = socket                 # `socket` (default), `ascii`, `rtu` or `binary`
        tcp_address = "0.0.0.0"         # binds on all interfaces by default
        tcp_port = 502                  # Modbus device TCP port
        # see below for common parameters
    }
    ...
]
...

Passive Serial Client

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.PassiveModbusSerialClient"
        serial_port = "/dev/ttyUSB0"
        serial_baud = 9600              # this is the default
        serial_stopbits = 1             # this is the default
        serial_bytesize = 8             # this is the default
        serial_parity = N               # `N`, `E` or `O` (defaults to `N`)
        # see below for common parameters
    }
    ...
]
...

Passive TCP(dump) Client

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        driver = "qtoggleserver.modbus.PassiveModbusTcpClient"
        port = 5020                     # TCP port to sniff
        iface = "eth0"                  # network interface to sniff (defaults to `any`)
        master_ip = "192.168.1.122"     # IP address of the master Modbus machine (optional) 
        slave_ip = "192.168.1.123"      # IP address of the slave Modbus machine (optional)
        master_port = 5020              # TCP port of the master Modbus machine (optional) 
        slave_port = 5021               # TCP port of the slave Modbus machine (optional)
        tcpdump = "/usr/bin/tcpdump"    # full path to the `tcpdump` binary (optional) 
        # see below for common parameters
    }
    ...
]
...

Common Parameters

The following parameters are common to all types of Modbus clients and servers:

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        ...
        name = "mydevice"  # an optional name of your choice
        timeout = 5        # in seconds, this is the default
        unit_id = 1           # slave unit id, this is the default
        ports = {
            "port_id1" = {
                modbus_type = coil          # `coil`, discrete_input`, `input_register` or `holding_register`
                address = 1234              # Modbus port address (from `0000` to `9999`)
                # number of successive registers mapped to the port, starting at `address` (defaults to `1`)
                length = 2
                writable = false            # defaults to `null`, inferred from `modbus_type`
                # `struct` format to use to group multiple register values into a byte array (defaults to `>` followed
                # by `H` times `length`)
                register_group_fmt = ">HH"
                # `struct` format to use to map register byte array to port value (defaults to `>h`)
                value_fmt = ">i"
            }
            ...
        }
        ...
    }
    ...
]
...

Common Client Parameters

The following parameters are common to all types of Modbus clients:

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        ...
        use_single_functions = false  # set to `true` to use single Modbus access functions instead of multi ones
        initial_delay = 5             # the number of seconds to delay polling after connection (defaults to `0`)
        ...
    }
    ...
]
...

Common Server Parameters

The following parameters are common to all types of Modbus servers:

qtoggleserver.conf:
...
peripherals = [
    ...
    {
        ...
        identity_vendor_name = "My Vendor"
        identity_product_code = "PROD1234"
        identity_major_minor_revision = "3.14.15"
        identity_vendor_url = "https://example.com"
        identity_product_name = "My Product"
        identity_model_name = "My Model"
        identity_user_application_name = "My Custom Model"
        ...
    }
    ...
]
...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtoggleserver_modbus-1.4.2.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qtoggleserver_modbus-1.4.2-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file qtoggleserver_modbus-1.4.2.tar.gz.

File metadata

  • Download URL: qtoggleserver_modbus-1.4.2.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for qtoggleserver_modbus-1.4.2.tar.gz
Algorithm Hash digest
SHA256 d1d5007ea326925485e469cd1f14cf0586f5d87f844fb9cdeffffeffdb001533
MD5 10ca1eb5bd721b57ecda1b79cb804106
BLAKE2b-256 39efb56b87b78aa7957d8aaaffcca986198c3138745ee3f0171627a34136e3fd

See more details on using hashes here.

File details

Details for the file qtoggleserver_modbus-1.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for qtoggleserver_modbus-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1ddfb76a41980882c5642066782474ac0e0840d31e0c184e4555386cc426999e
MD5 0435e8ddc087597b30705bb83003b49f
BLAKE2b-256 4236cffce74d798e0e342e72c5ab82177a154ed8d4d1ce1f227bfa06d4c8af30

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page