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

Question: how to use the write_single_coil() to write on the different positions? #15

Closed
beyonlo opened this issue Sep 1, 2022 · 3 comments · Fixed by #53
Closed

Question: how to use the write_single_coil() to write on the different positions? #15

beyonlo opened this issue Sep 1, 2022 · 3 comments · Fixed by #53
Labels
client Client implementation specific issue documentation Improvements or additions to documentation
Milestone

Comments

@beyonlo
Copy link

beyonlo commented Sep 1, 2022

Hello @brainelectronics

I'm using the #10 for tests.

How is possible to use the write_single_coil() to write in position 3, for example? In this example below the ouput_value is setting always to the first position:

>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
[False, True, True, False, False, False, False, False]
>>> host.write_single_coil(slave_addr=10, output_address=123, output_value=1)
False
>>> host.read_coils(slave_addr=10, starting_addr=123, coil_qty=1)
[True, False, False, False, False, False, False, False]
>>> 

Using this register_definitions:
{'ISTS': {'EXAMPLE_ISTS': {'register': 67, 'len': 1, 'val': 0}}, 'IREGS': {'EXAMPLE_IREG': {'register': 10, 'len': 2, 'val': 60001}}, 'HREGS': {'EXAMPLE_HREG': {'register': 93, 'len': 1, 'val': 19}}, 'COILS': {'EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [0, 1, 1]}}}

@beyonlo
Copy link
Author

beyonlo commented Nov 11, 2022

Very importat: I suppose that when use output_value without a list, I mean, just 1/0/True/False like as example above, it will be write on the first position, (position 0), is that right? That is a bit confuse. In my opinion is more clear always to use a list when need to write COILS. So even that you need to write just one COIL, in the first position, need to use always output_value=[1], What do you think? That will prevents confusion. So in this case the register definitions need always to use list as well: EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [0,1,1] or if has all 0/False, can use empty list: EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [ ] . Anyway, always is need to be documented: as each register is by definition 2 bytes (16 bits), so coils that are not defined, is by default 0/False. So EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [0,1,1] is the same thing that to do EXAMPLE_COIL': {'register': 123, 'len': 3, 'val': [0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0]. Is that make sense for you?

Edit: maybe is a good idea to have a simple doc (with examples) about how to use.

@brainelectronics
Copy link
Owner

Relates to #26

@brainelectronics brainelectronics added this to the Documentation milestone Dec 8, 2022
@brainelectronics brainelectronics added the documentation Improvements or additions to documentation label Dec 16, 2022
@brainelectronics
Copy link
Owner

Relates to #35, same root cause for this issue. Access to the elements of a list of a register value is missing/not yet possible

Registers are defined as specified by the register element, see

self._set_reg_in_dict(reg_type='COILS',
address=address,
value=value)
for a coil. The provided value is added as value to the dictionary at the key register, here 93. Thereby no element/key 94 exists in the Modbus _register_dict

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Client implementation specific issue documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants