Skip to content

Conversation

@bje-
Copy link
Contributor

@bje- bje- commented May 27, 2017

No description provided.

return struct.pack('>HH', self.address, self.value)
packet += self.value
else:
packet += struct.pack('>H', self.value)
Copy link
Contributor

@dhoomakethu dhoomakethu May 29, 2017

Choose a reason for hiding this comment

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

This line would throw TypeError: cannot concatenate 'str' and 'int' objects on python2 and TypeError: can't concat bytes to int on python 3.

Sorry , I used the wrong example. The code works perfectly. Updating the test code just in case .
The sample code to test this feature is below

from pymodbus.client.sync import ModbusTcpClient as ModbusClient
client = ModbusClient('127.0.0.1', port=5020)
client.connect()
address = 0x00
#client.write_register(address, 25, unit=1, skip_encode=True)
builder = BinaryPayloadBuilder(endian=Endian.Big)
builder.add_16bit_uint(0x1234)
payload = builder.build()
result  = client.write_register(address, payload[0], unit=1, skip_encode=True)
result  = client.read_holding_registers(address, 1,  unit=1)
assert result.registers == [0x1234]

@dhoomakethu
Copy link
Contributor

please add a relevant test for your change for encode method .

@dhoomakethu dhoomakethu merged commit 6f5f482 into pymodbus-dev:master May 29, 2017
@bje- bje- deleted the fixes branch May 30, 2017 12:12
@dhoomakethu
Copy link
Contributor

dhoomakethu commented Jun 5, 2017

Sorry wrong PR :P

dhoomakethu pushed a commit that referenced this pull request Nov 28, 2017
… a single register request. (#173)

* * register_write_message.py: Observe skip_encode option when encoding
  a single register request.

* Remove trailing semicolons. This isn't C.  :-)

* * sync.py (ModbusTcpClient.connect): `address' variable is unused.

* Fix typo: controll -> control.

* * test/test_register_write_messages.py: Test skip_encode when writing
  single and multiple registers.
ccatterina pushed a commit to ccatterina/pymodbus that referenced this pull request Apr 17, 2018
… a single register request. (pymodbus-dev#173)

* * register_write_message.py: Observe skip_encode option when encoding
  a single register request.

* Remove trailing semicolons. This isn't C.  :-)

* * sync.py (ModbusTcpClient.connect): `address' variable is unused.

* Fix typo: controll -> control.

* * test/test_register_write_messages.py: Test skip_encode when writing
  single and multiple registers.
@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.

2 participants