Possible bug in function "write_registers"

132 views
Skip to first unread message

Dennis S

unread,
Aug 13, 2014, 6:36:50 AM8/13/14
to pymo...@googlegroups.com
Hello,

when I use the function "write_registers" (Modbus FC16) to write the value 0x0000
into a register, I get an exception response with "Illegal Data Value". Using Wireshark
I found out, that the Request is 10 C0 01 00 00 00. This means that the count
fields are 0 and the register address is missing.

Does anyone has same experiences with this?

Kind regards,
Dennis S.

Galen Collins

unread,
Aug 13, 2014, 11:58:09 AM8/13/14
to pymo...@googlegroups.com

Can you show me your code?

--
You received this message because you are subscribed to the Google Groups "pymodbus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pymodbus+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dennis S

unread,
Aug 14, 2014, 3:48:22 AM8/14/14
to pymo...@googlegroups.com
Yes, sure!
It is something like this:

#!/usr/bin/env python
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
import time, os

client = ModbusClient('192.168.0.222', 502)

# write parameter
client.write_registers(0xC00A, 0x8000)
client.write_registers(0xC006, 0x0000)
client.write_registers(0xC005, 0x20FF)
client.write_registers(0xC003, 0x7FFF)

client.close()


Greets
Dennis

Galen Collins

unread,
Aug 14, 2014, 11:29:13 AM8/14/14
to pymo...@googlegroups.com

Okay,

So write registers takes an iterable as an argument, but it also takes a single value that it will wrap in an array. However to protect against passing in None, this code is run::

self.values = values or []

Meaning if you pass in 0x00, it will write []. If you mark this as a bug at github I will put a fix out. For now you can do::

client.write_registers(1, [0x0000])

Thanks,
Galen

Dennis S

unread,
Aug 15, 2014, 1:34:14 AM8/15/14
to pymo...@googlegroups.com
Thanks a lot!
This works, but I will try to post this issue too (I have no experience with GIT yet).

Greets
Dennis
Reply all
Reply to author
Forward
0 new messages