Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repl enhancements 2 #1141

Merged
merged 8 commits into from
Nov 2, 2022
Merged

Repl enhancements 2 #1141

merged 8 commits into from
Nov 2, 2022

Conversation

dhoomakethu
Copy link
Contributor

@dhoomakethu dhoomakethu commented Oct 25, 2022

  • Fix --random in pymodbus.server to randomize values read for discrete inputs and input registers

image

Example invocation

pymodbus.server --verbose run  --modbus-server tcp --modbus-framer socket --modbus-port 5020 --unit-id 1 --unit-id 2 -u 4 -r 1 --timeout 2

The values for simulation can also be passed as a json file to --modbus-config param , for e.g to limit the max and min values a register should have. Refer data_block_settings in the below json file.

{
  "tcp": {
        "handler": "ModbusConnectedRequestHandler",
        "allow_reuse_address": true,
        "allow_reuse_port": true,
        "backlog": 20,
        "ignore_missing_slaves": false
    },
    "serial": {
        "handler": "ModbusSingleRequestHandler",
        "stopbits": 1,
        "bytesize": 8,
        "parity": "N",
        "baudrate": 9600,
        "timeout": 3,
        "auto_reconnect": false,
        "reconnect_delay": 2
    },
    "tls": {
        "handler": "ModbusConnectedRequestHandler",
        "certfile": null,
        "keyfile": null,
        "allow_reuse_address": true,
        "allow_reuse_port": true,
        "backlog": 20,
        "ignore_missing_slaves": false
    },
    "udp": {
        "handler": "ModbusDisonnectedRequestHandler",
        "ignore_missing_slaves": false
    },
    "data_block_settings": {
        "min_binary_value": 0,
        "max_binary_value": 1,
        "min_register_value": 0,
        "max_register_value": 100,
        "data_block": {
            "discrete_inputs": {
                "block_start": 0,
                "block_size": 100,
                "default": 0,
                "sparse": false
            },
            "coils": {
                "block_start": 0,
                "block_size": 100,
                "default": 0,
                "sparse": false
            },
            "holding_registers": {
                "block_start": 0,
                "block_size": 100,
                "default": 0,
                "sparse": false
            },
            "input_registers": {
                "block_start": 0,
                "block_size": 100,
                "default": 0,
                "sparse": false
            }

        }


    }
}

TODO

  • Update unit tests
  • Update documentation

@dhoomakethu
Copy link
Contributor Author

@janiversen
Copy link
Collaborator

I am hoping to make 3.0.1 around November 5, does that give you enough time to merge this ?

If not I will pospone the release a bit.

@janiversen
Copy link
Collaborator

The CI error might be mine, will look at it Monday.

@dhoomakethu
Copy link
Contributor Author

Ok, I will poke around a bit tomorrow to see if I can fix it.

@janiversen
Copy link
Collaborator

Don’t’t worry as you can see it is a temporary error, restarting the job cures the problem.

* `data_len`: Length of the stray_data (`int`)
* `clear_after`: Clears the error responses after <n> requests (`int`)

**EXAMPLES**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot for adding this example section. Super useful

self._min_register_value = min_register_value
self._max_register_value = max_register_value

def getValues(self, fc_as_hex, address, count=1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this functionality work for single bit object types? I was thinking about coils.
Not sure if is really much value, but for my own tests that would be nice, although the complexity of randomise booleans is much less.

Anyhow, just wondering about your thoughts about those objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding registers and coils can be overridden and hence they are excluded from simulation. Bit fields should be straight forward (0 or 1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right that makes sense

@dhoomakethu dhoomakethu mentioned this pull request Nov 2, 2022
@dhoomakethu
Copy link
Contributor Author

@janiversen I may not be able to finish writing the test cases for this PR by first week of November, Please feel free to drop this from the next release if you think having tests are a must. You can merge otherwise and I will add tests in future.

@janiversen
Copy link
Collaborator

Thanks for the heads up. I still have a couple of days work on the new datastore (adding tests), once done I will merge this one and make the release.

As you say test can come later.

@janiversen
Copy link
Collaborator

I will merge this now, because I am testing/pre-building doc and sources to see what more we need, please make the tests in a new PR.

@janiversen janiversen merged commit 30f7166 into dev Nov 2, 2022
@janiversen janiversen deleted the repl-enhancements-2 branch November 5, 2022 07:45
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants