deathwish88 / modbus-tk

Automatically exported from code.google.com/p/modbus-tk
Other
0 stars 0 forks source link

write negative value to register using the execute method #26

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
RtuMaster.execute(slave_number, WRITE_SINGLE_REGISTER, 
                  address, output_value=-123)

What is the expected output? What do you see instead?
Exception : struct.error: integer out of range for 'H' format code
line 254, module modbus.py

What version of the product are you using? On what operating system?
0.4.1

Please provide any additional information below.
It is not a real bug. But it would be nice to have an 'output data format' as 
there is the 'data_format' parameter for input data.
I'm using an Eurotherm 2404 regulator driving a thermal chamber that can set 
negative temperatures. Negative temperatures are coded in two's complement so 
the output value could be packed with the 'h' data format of the struct.pack 
function. 

Original issue reported on code.google.com by cocostyl...@gmail.com on 24 Jan 2012 at 3:23

GoogleCodeExporter commented 8 years ago

Original comment by luc.jean@gmail.com on 1 Feb 2012 at 6:59

GoogleCodeExporter commented 8 years ago
I've pushed a new version in the mercurial repository. It is now possible to 
provide an additional output_format.
Please look at testWriteSingleRegisterNegativeValue and 
testWriteMultipleRegistersNegativeValue in modbus_functest.py

Please let me know if it is ok for you. I will publish a new release.

Best
luc

Original comment by luc.jean@gmail.com on 1 Feb 2012 at 7:30

GoogleCodeExporter commented 8 years ago
In fact, there is no need of this output_format. It can be guessed from the 
value H if >=0 and h if <0.
I've pushed a new version

Original comment by luc.jean@gmail.com on 1 Feb 2012 at 8:34

GoogleCodeExporter commented 8 years ago
Of course it can be guessed but the 'h' format is OK for this slave, not sure 
there's no modbus instruments that will need another format. I'm not used with 
modbus instruments. My company work in test & measurement world and we drive 
measurement instrument using GPIB, USB, LAN ... and even most of all nowadays 
instruments work the same, it is often that we have to use old or specific 
instruments that need special binary format or anything else. 
So, considering your experience on modbus, I let you do the right choice. 

The test I've done with the output format is OK for me.

Comme vous l'avez certainement compris à la lecture de mon anglais 
approximatif, je suis français et même implanté pas très loin de chez vous 
en Ardèche.

Bonne journée et merci de votre réactivité.

Original comment by cocostyl...@gmail.com on 1 Feb 2012 at 9:19