AdvancedClimateSystems / uModbus

Python implementation of the Modbus protocol.
Mozilla Public License 2.0
211 stars 82 forks source link

WIP server: allow discriminating responses upon requests's starting address #74

Open piertoni opened 5 years ago

piertoni commented 5 years ago

First working code to address #73

It adds an optional argument to server that allows to discriminate between requests.

Example of server:

@app.route(slave_ids=[1], function_codes=[1, 2, 3, 4], addresses=list(range(0, 10)), starting_address=1)
def read_data_store(slave_id, function_code, address):
    """" Return value of address. """
    print(f"read data FC{function_code} slave id {slave_id} address {address} value {data_store[address]}")
    return 0

@app.route(slave_ids=[1], function_codes=[1, 2, 3, 4], addresses=list(range(0, 10)), starting_address=2)
def read_data_store(slave_id, function_code, address):
    """" Return value of address. """
    print(f"read data FC{function_code} slave id {slave_id} address {address} value {data_store[address]}")
    return 1

Result on client

Request starting_address=1 quantity=4 -> [0, 0, 0, 0]
Request starting_address=2 quantity=4 -> [1, 1, 1, 1]
Request starting_address=1 quantity=5 -> [0, 0, 0, 0, 0]
Request starting_address=2 quantity=5 -> [1, 1, 1, 1, 1]

If you are ok with the proposal I can go on finishing with a automatic test and documentation.

As you did before, please give me a quick advice to where put my hand for implement the tests.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.08%) to 96.382% when pulling 9b2e9df8f6b1949b5d09d79899297c47a053cca1 on piertoni:master into d173ab5805c6a35a9555e7642a0b9d708ada0337 on AdvancedClimateSystems:master.

piertoni commented 5 years ago

PR that it adds support for starting_address and quantity in a backwards compatible way

Where exactly is not compatible? The tests are all passing (except for python3.3 but this is due to some other Continous Integration problem, did you check that?). My intent is to be fully compatible and this PR in fact is still WIP (as we miss tests and docs). Please let me know and I will do my best to add this functionality. Just need some some advice from a project maintainer :smile: Thanks

piertoni commented 5 years ago

I made a workaround to allow passing partial kwargs to app.route decorated functions. This is to allow full compatibility with previous code. Tell me what do you think about this.

Still to do:

piertoni commented 4 years ago

Just to know if you can check my WIP and if you agree with the idea so I can go on... There is also to fix the pipeline for python 3.3

dequis commented 4 years ago

re: failing pipeline, I think 3.3 and 3.4 support should be dropped as they are EOL https://devguide.python.org/devcycle/#end-of-life-branches