8000 BinaryPayloadBuilder object has no attribute to_registers() · Issue #148 · pymodbus-dev/pymodbus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

BinaryPayloadBuilder object has no attribute to_registers() #148

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

Closed
milanthakkerptc opened this issue Jan 10, 2017 · 6 comments
Closed

BinaryPayloadBuilder object has no attribute to_registers() #148

milanthakkerptc opened this issue Jan 10, 2017 · 6 comments

Comments

@milanthakkerptc
Copy link

I'm trying to use the binary payload builder to initialize a complex data store, but the issue I constantly am running into is that it has no to_registers attribute. I've tried working around using pack and unpack functions in python but I tend to get a bunch of errors that way.

@jotathebest
Copy link

Have the same issue, could you fix it in some way ?

@milanthakkerptc
Copy link
Author
milanthakkerptc commented Jan 25, 2017

It looks like that function is broken in some way - I got around it by splitting my complex data into two registers (by default initialized as uint_16s) and configuring my client to look at the registers properly.

To split a float into two uint_16s of binary data:
def float_to_uint16(number): i1, i2 = unpack('HH', pack('f', number)) return i1, i2

Assuming you set your values with:
context[slave_id].setValues(register, address, [i1, i2])
your complex data type is now split over two consecutive registers, and on the other end you'll just have to combine the binary data of the two uint16s on the other end and you'll have the binary of your float.

Complicated, and I probably did a bad job explaining that, but I got it to work.

@egarl004
Copy link
egarl004 commented Mar 2, 2017

any progress on this? just ran into this issue today.

@jjchromik
Copy link
jjchromik commented Mar 29, 2017

if your problem was that this function was not existing - it is because in last releases it was not there. I found it e.g. herehttps://github.com/bashwork/pymodbus/blob/master/pymodbus/payload.py :

def to_registers(self):
''' Convert the payload buffer into a register
layout that can be used as a context block.

:returns: The register layout to use as a block
'''
fstring = self._endian + 'H'
payload = self.build()
return [unpack(fstring, value)[0] for value in payload]

I added it back to payload - BinaryPayloadBuilder and tested it with few values and so far - it worked... Did anyone experience problems with that function?

@egarl004
Copy link
egarl004 commented Apr 5, 2017 via email

dhoomakethu added a commit that referenced this issue May 16, 2017
2. addresses issues in #159, #156, #148, #121
@dhoomakethu dhoomakethu mentioned this issue May 16, 2017
Merged
@dhoomakethu
Copy link
Contributor

fixed with version 1.3.0.rc1

dhoomakethu added a commit to bhagn/pymodbus that referenced this issue Oct 10, 2017
dhoomakethu added a commit that referenced this issue Oct 26, 2017
2. addresses issues in #159, #156, #148, #121
@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

No branches or pull requests

5 participants
0