-
Notifications
You must be signed in to change notification settings - Fork 1k
* register_write_message.py: Observe skip_encode option when encoding a single register request. #173
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
Conversation
| return struct.pack('>HH', self.address, self.value) | ||
| packet += self.value | ||
| else: | ||
| packet += struct.pack('>H', self.value) |
There was a problem hiding this comment.
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]
|
please add a relevant test for your change for encode method . |
single and multiple registers.
|
Sorry wrong PR :P |
… 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.
… 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.
No description provided.