minimalmodbus-list Mailing List for minimalmodbus
Status: Beta
Brought to you by:
pyhys
This list is closed, nobody may subscribe to it.
2011 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2012 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
(1) |
Jun
(1) |
Jul
(6) |
Aug
(1) |
Sep
(2) |
Oct
(3) |
Nov
(1) |
Dec
(4) |
2013 |
Jan
(7) |
Feb
(1) |
Mar
|
Apr
(1) |
May
(2) |
Jun
(2) |
Jul
|
Aug
(9) |
Sep
|
Oct
|
Nov
(5) |
Dec
(3) |
2014 |
Jan
(11) |
Feb
(2) |
Mar
(1) |
Apr
(3) |
May
(6) |
Jun
(1) |
Jul
|
Aug
(2) |
Sep
(2) |
Oct
(7) |
Nov
(3) |
Dec
|
2015 |
Jan
(2) |
Feb
(6) |
Mar
|
Apr
(2) |
May
(5) |
Jun
|
Jul
(2) |
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
(3) |
2016 |
Jan
|
Feb
|
Mar
(1) |
Apr
(5) |
May
|
Jun
|
Jul
(1) |
Aug
(11) |
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(2) |
2017 |
Jan
|
Feb
(4) |
Mar
(5) |
Apr
(2) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: Michelle N. <to...@gm...> - 2017-05-02 20:19:13
|
To whom may concern, Thank you for your attention on my issue. I tried to use minimalmodbus to communicate modbus device through USB-RS485 cable. Device number is 66, baud rate = 192000, Parity = Even, Stop bit = 1, bytesize = 8 My code is: import minimalmodbus import serial instrument = minimalmodbus.Instrument('COM12', 66) instrument.serial.parity = serial.PARITY_EVEN print(instrument) > minimalmodbus.Instrument<id=0x4f0b780, address=66, mode=rtu, > close_port_after_each_call=False, precalculate_read_size=True, debug=False, > serial=Serial<id=0x51860b8, open=True>(port='COM12', baudrate=19200, > bytesize=8, parity='E', stopbits=1, timeout=0.05, xonxoff=False, > rtscts=False, dsrdtr=False)> My device modebus objects like: [image: Inline image 1] When I tried to read the vale of Room Humidity Display, I used: instrument.read_register(10, 0) It replied: > --------------------------------------------------------------------------- > OSError Traceback (most recent call last) > <ipython-input-6-ae322845b016> in <module>() > ----> 1 instrument.read_register(10, 0) > C:\ProgramData\Anaconda3\lib\site-packages\minimalmodbus-0.7-py3.6.egg\minimalmodbus.py > in read_register(self, registeraddress, numberOfDecimals, functioncode, > signed) > 256 _checkInt(numberOfDecimals, minvalue=0, maxvalue=10, > description='number of decimals') > 257 _checkBool(signed, description='signed') > --> 258 return self._genericCommand(functioncode, registeraddress, > numberOfDecimals=numberOfDecimals, signed=signed) > 259 > 260 > C:\ProgramData\Anaconda3\lib\site-packages\minimalmodbus-0.7-py3.6.egg\minimalmodbus.py > in _genericCommand(self, functioncode, registeraddress, value, > numberOfDecimals, numberOfRegisters, signed, payloadformat) > 695 > 696 ## Communicate ## > --> 697 payloadFromSlave = self._performCommand(functioncode, > payloadToSlave) > 698 > 699 ## Check the contents in the response payload ## > C:\ProgramData\Anaconda3\lib\site-packages\minimalmodbus-0.7-py3.6.egg\minimalmodbus.py > in _performCommand(self, functioncode, payloadToSlave) > 793 > 794 # Communicate > --> 795 response = self._communicate(request, > number_of_bytes_to_read) > 796 > 797 # Extract payload > C:\ProgramData\Anaconda3\lib\site-packages\minimalmodbus-0.7-py3.6.egg\minimalmodbus.py > in _communicate(self, request, number_of_bytes_to_read) > 928 > 929 if len(answer) == 0: > --> 930 raise IOError('No communication with the instrument > (no answer)') > 931 > 932 return answer > OSError: No communication with the instrument (no answer) I also tried: * instrument.read_register(10, 0, 3) * instrument.read_register(10, 1, 3) * instrument.read_register(40010, 1, 3) All the above commands had the same error message. How could I communicate with modbus device using minimalmodbus. Thank you so much! Best regards, Michelle |
From: sanjay s. <san...@gm...> - 2017-04-04 11:27:02
|
sir i have respberypi set up with ftdichip usb connector. while i have 2 nos instruments connected. one temp reader delta electronics.db44. Able to read sv pv. next one connected is flow meter from broiltech.(broiltech.com) that gives registers 40000 for total flow; 40002 for flow rate;40004 for flow unit. when i run code to read 14 length long integers it gives readings as follow. code ----------------------------------------------------------------------- temp4=repr(instrument.read_registers(0x0000,14)) print str(temp4) MinimalModbus debug mode. Response from instrument: "\x02\x03\x1cWD\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\xe3`\x00\x16\x03\xe8\x00\x00\x00\x00\x00\x00'\x0f\x00\x009\xbe" (02 03 1C 57 44 00 01 00 00 00 00 00 00 00 00 E3 60 00 16 03 E8 00 00 00 00 00 00 27 0F 00 00 39 BE) (33 bytes), roundtrip time: 154.4 ms. Timeout setting: 300.0 ms. ---------------------------------------------------------- response: [22340, 1, 0, 0, 0, 0, 58208, 22, 1000, 0, 0, 0, 9999, 0] since first out put should takes 8 binary together as [57 44 00 01] and give out put 87876 as hex (15744) insted of 22340 as hex(5744). similarly need output binary [E3 60 00 16] as hex (16E360) reading 1500000 instead of [58202,22] .unable to read 8 binary to gather. please help .how to code for getting correct reading. please note when tried with modbustester from www.modbus.pl with input as device address=2 data type =4 ,holding registers, start address=1,length=14.scan rate=1000ms,data format= long integers it gives reading as 40001=87876 40003=0 40005=0 40007=1500000 40009=1000 4001=0 40013=9999 for above connection. Thanks sanjay |
From: sanjay s. <san...@gm...> - 2017-04-04 07:19:49
|
sir i have respberypi set up with ftdichip usb connector. while i have 2 nos instruments connected. one temp reader delta electronics.db44. Able to read sv pv. next one connected is flow meter from broiltech.(broiltech.com) that gives registers 40000 for total flow; 40002 for flow rate;40004 for flow unit. when i run code to read 14 length long integers it gives readings as follow. code ----------------------------------------------------------------------- temp4=repr(instrument.read_registers(0x0000,14)) print str(temp4) MinimalModbus debug mode. Response from instrument: "\x02\x03\x1cWD\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\xe3`\x00\x16\x03\xe8\x00\x00\x00\x00\x00\x00'\x0f\x00\x009\xbe" (02 03 1C 57 44 00 01 00 00 00 00 00 00 00 00 E3 60 00 16 03 E8 00 00 00 00 00 00 27 0F 00 00 39 BE) (33 bytes), roundtrip time: 154.4 ms. Timeout setting: 300.0 ms. ---------------------------------------------------------- response: [22340, 1, 0, 0, 0, 0, 58208, 22, 1000, 0, 0, 0, 9999, 0] since first out put takes 8 binary to gather as [57 44 00 01] and give out put 87876 as hex (15744) insted of 22340 as hex(5744). similarly need output binary [E3 60 00 16] as hex (16E360) reading 1500000 instead of [58202,22] .unable to read 8 binary to gather. please help .how to code for getting correct reading. Thanks sanjay |
From: Chris B. <chr...@gm...> - 2017-03-28 19:49:34
|
Hello, I am relatively new to programming and the Raspberry PI so I am hoping this is a relatively simple fix. I am getting a checksum error. I was originally trying to read a temperature (INT16). Then tried a simple digital value* which is not changing* but the response from the device is changing. Two consecutive examples of running the program are in error.txt. The program is modbus_t1.py Please help. -- Chris Beuglet, P.Eng. Vortex Source Systems in...@vo... www.vortexsource.com p. 888-781-8151 ext.101 f. 888-670-2544 |
From: Dora L. B. <dor...@gm...> - 2017-03-22 09:17:39
|
Dear Sir/Madam, When using the performcommand() function in minimalmodbus, can the message structure be different than the standard: - Slave address [1 Byte] - Function code [1 Byte]. Allowed range is 1 to 127 (in decimal). - Payload data [0 to 252 Bytes] - CRC [2 Bytes]. It is a Cyclic Redundancy Check code, for error checking of the message I am trying to communicate with a device using ModbusRTU but it uses an additional 2 bytes and a special function code in its message. Can I use _performcommand() to communicate with it? Thanks in advance for your assistance. Regards, Dora |
From: Benjamin V. <ben...@un...> - 2017-03-22 09:09:21
|
Hello Jonas, I come back because I have make some progress but I'm still stuck on a point. Here it is a screen (attached) of a free windows soft to retrieve modbus RTU value from X registers. As you can see, on the 4 registers, there are 2 values. The float32bit values are coherents because it's a battery voltage value. My python program now : /// //#!/usr/bin/env python// //import minimalmodbus as mmbus// //mmbus.CLOSE_PORT_AFTER_EACH_CALL = True// // //import serial// //import time// // //ins = mmbus.Instrument('/dev/ttyUSB0', 1, mode='rtu') # port name, slave address (in decimal)// //ins.debug = True// //ins.serial.baudrate = 9600// //ins.serial.bytesize = 8// //ins.serial.parity = serial.PARITY_NONE// //ins.serial.stopbits = 1// //ins.serial.timeout = 0.5// // //time.sleep(0.5)// // //print(ins.read_float(0,3,2))// //time.sleep(1)/ And what I retrieve in my terminal : /MinimalModbus debug mode. Writing to instrument (expecting 9 bytes back): '\x01\x03\x00\x00\x00\x02\xc4\x0b' (01 03 00 00 00 02 C4 0B) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1490173493604.0 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x01\x03\x04\x8d\xf1AAp\xcc' (01 03 04 8D F1 41 41 70 CC) (9 bytes), roundtrip time: 24.0 ms. Timeout setting: 500.0 ms. *-1.48684810376e-30*/ The value is totally different. What do you think ? Thank you, bye. Le 01/03/2017 à 15:33, Benjamin VIAL a écrit : > > Hello Jonas, > > thank you for your answer. Indeed, when I'm using address 1 instead of > 10001, or 40001/ 30001 I have somes values. But, two points let me > think this is probably the right addresses : > > - The values are incomprehensibles, a number which change without > logic (it's supposed to be a voltage value, so not so much changes in > a minute), it can bu 12345 and a minute later 1234567. > > - In the documentation > <https://s.campbellsci.com/documents/us/manuals/cr200.pdf> (p 139, > section 15) of my datalogger (the advice i'm trying to read) we can > clearly read that the variable values is readable in range of > addresses 30001 to 30041 or 40001 to 40041. > > Or maybe I do not have understand the manual ... > > Bye > > > On 26/02/2017 12:11, Jonas Berg wrote: >> Hi Benjamin! >> I guess you use the wrong address. Use address 1 instead of 10001. >> Please see the section "Coil, discrete input, input register, holding >> register numbers and addresses" on this page: >> https://en.wikipedia.org/wiki/Modbus >> <http://https://en.wikipedia.org/wiki/Modbus> >> >> Best regards >> Jonas >> >> >> <-----Ursprungligt Meddelande-----> >> *From: Benjamin VIAL [ben...@un...]* >> Sent: 20/2/2017 12:56:02 PM >> To: min...@li... >> Subject: [Minimalmodbus-list] problem with some register address ? >> >> Hello, >> >> context : I'm trying to read register on a datalogger (Campbell >> CR200X) that is supposed to have modbus slave protocol (RTU only). >> >> As it is write in documentation >> <https://s.campbellsci.com/documents/us/manuals/cr200.pdf>, CR200X >> (link on specific modbus programmation >> <https://s.campbellsci.com/documents/us/technical-papers/dataloggers-as-modbus-slave-devices.pdf>) >> have a precise registers table. In my python code, I can read >> register 1, 2, etc, but not more than6 when I want read 10 register >> () and no more regiter 7 when I try to read 6 registers (), that's >> strange. >> >> Here it is my test program : >> >> #!/usr/bin/env python >> import minimalmodbus as mmbus >> mmbus.CLOSE_PORT_AFTER_EACH_CALL = True >> import serial >> import datetime >> import time >> ins = mmbus.Instrument('/dev/ttyUSB0', 1, mode='rtu') # port name, slave address (in decimal) >> ins.debug = True >> ins.serial.baudrate = 9600 >> ins.serial.bytesize = 8 >> ins.serial.parity = serial.PARITY_NONE >> ins.serial.stopbits = 1 >> ins.serial.timeout = 0.5 >> #time.sleep(0.5) >> print(ins.read_registers(10001,4,3)) >> >> And that the response of instrument : >> >> MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): "\x01\x03'\x11\x00\x04\x1e\xb8" (01 03 27 11 00 04 1E B8) >> MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591509730.0 ms, minimum silent period: 4.01 ms. >> MinimalModbus debug mode. Response from instrument: '\x01\x83\x02\xc0\xf1' (01 83 02 C0 F1) (5 bytes), roundtrip time: 500.6 ms. Timeout setting: 500.0 ms. >> Traceback (most recent call last): >> File "./MODBUS_CR200.py", line 27, in <module> >> print(ins.read_registers(10001,4,3)) >> File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 498, in read_registers >> numberOfRegisters=numberOfRegisters, payloadformat='registers') >> File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 697, in _genericCommand >> payloadFromSlave = self._performCommand(functioncode, payloadToSlave) >> File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 798, in _performCommand >> payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode) >> File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 1088, in _extractPayload >> raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response)) >> ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1' >> >> Note that it is working when I try to print register like "1" and >> same parameters, I have this: >> >> MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): '\x01\x03\x00\x01\x00\x04\x15\xc9' (01 03 00 01 00 04 15 C9) >> MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591490909.2 ms, minimum silent period: 4.01 ms. >> MinimalModbus debug mode. Response from instrument: '\x01\x03\x08\x91aAA\x97\xb6DQ!\xc1' (01 03 08 91 61 41 41 97 B6 44 51 21 C1) (13 bytes), roundtrip time: 74.6 ms. Timeout setting: 500.0 ms. >> [37217, 16705, 38838, 17489] >> >> So there are values. >> I had contact severals technician of Campbell Scientific but they can >> explain why I have this error (in the other hand, they don't support >> python program). >> >> Have you an idea ? >> >> Thank you, >> bye. >> >> >> PS : careful, documentation about specific modbus progs are for >> another datalogger named 'CR1000', there are some differences between >> CR200X and CR1000. And there is the diagnostic in attached. >> >> -- >> Benjamin VIAL >> Institut des Sciences de la Terre - Grenoble >> tel : (+33)4.76.63.52.16 >> mob : (+33)6.14.83.25.42 >> > > -- > Benjamin VIAL > Institut des Sciences de la Terre - Grenoble > tel : (+33)4.76.63.52.16 > mob : (+33)6.14.83.25.42 -- Benjamin VIAL Institut des Sciences de la Terre - Grenoble tel : (+33)4.76.63.52.16 mob : (+33)6.14.83.25.42 |
From: saurabh d. <sau...@ho...> - 2017-03-21 11:26:56
|
Dear Sir, I am trying to get Holding register value from a energy meter (schneider EM6433) using minimal modbus. The holding registers address is 43961 and it holds Wh value. It woks fine with Modscan32. my code is: ################################################################ import minimalmodbus import serial instrument = minimalmodbus.Instrument('/dev/ttyUSB0', 1) # port name, slave address (in decimal) instrument.serial.port # this is the serial port name instrument.serial.baudrate = 9600 # Baud instrument.serial.bytesize = 8 instrument.serial.parity = serial.PARITY_NONE instrument.serial.stopbits = 1 instrument.serial.timeout = 0.05 # seconds instrument.address # this is the slave address number instrument.mode = minimalmodbus.MODE_RTU # rtu or ascii mode print(instrument) try: print(instrument.read_register(43961)) except IOError: print("Failed to read from instrument") #################################################### Output is: ******************************************************************************************************************** saurabh@saurabh-pc:~$ sudo python modexp.py minimalmodbus.Instrument<id=0x7f91a032fbd8, address=1, mode=rtu, close_port_after_each_call=False, precalculate_read_size=True, debug=False, serial=Serial<id=0x7f91a034bad0, open=True>(port='/dev/ttyUSB0', baudrate=9600, bytesize=8, parity='N', stopbits=1, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)> Traceback (most recent call last): File "modexp.py", line 17, in <module> print(instrument.read_register(43961)) File "/home/saurabh/.local/lib/python2.7/site-packages/minimalmodbus.py", line 258, in read_register return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed) File "/home/saurabh/.local/lib/python2.7/site-packages/minimalmodbus.py", line 697, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "/home/saurabh/.local/lib/python2.7/site-packages/minimalmodbus.py", line 798, in _performCommand payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode) File "/home/saurabh/.local/lib/python2.7/site-packages/minimalmodbus.py", line 1088, in _extractPayload raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response)) ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1' ************************************************************************************************************************* Please help. Thanks In advance Regards Saurabh Dwivedi +91- 8451060036 |
From: Benjamin V. <ben...@un...> - 2017-03-01 14:34:37
|
Hello Jonas, thank you for your answer. Indeed, when I'm using address 1 instead of 10001, or 40001/ 30001 I have somes values. But, two points let me think this is probably the right addresses : - The values are incomprehensibles, a number which change without logic (it's supposed to be a voltage value, so not so much changes in a minute), it can bu 12345 and a minute later 1234567. - In the documentation <https://s.campbellsci.com/documents/us/manuals/cr200.pdf> (p 139, section 15) of my datalogger (the advice i'm trying to read) we can clearly read that the variable values is readable in range of addresses 30001 to 30041 or 40001 to 40041. Or maybe I do not have understand the manual ... Bye On 26/02/2017 12:11, Jonas Berg wrote: > Hi Benjamin! > I guess you use the wrong address. Use address 1 instead of 10001. > Please see the section "Coil, discrete input, input register, holding > register numbers and addresses" on this page: > https://en.wikipedia.org/wiki/Modbus > <http://https://en.wikipedia.org/wiki/Modbus> > > Best regards > Jonas > > > <-----Ursprungligt Meddelande-----> > *From: Benjamin VIAL [ben...@un...]* > Sent: 20/2/2017 12:56:02 PM > To: min...@li... > Subject: [Minimalmodbus-list] problem with some register address ? > > Hello, > > context : I'm trying to read register on a datalogger (Campbell > CR200X) that is supposed to have modbus slave protocol (RTU only). > > As it is write in documentation > <https://s.campbellsci.com/documents/us/manuals/cr200.pdf>, CR200X > (link on specific modbus programmation > <https://s.campbellsci.com/documents/us/technical-papers/dataloggers-as-modbus-slave-devices.pdf>) > have a precise registers table. In my python code, I can read register > 1, 2, etc, but not more than6 when I want read 10 register () and no > more regiter 7 when I try to read 6 registers (), that's strange. > > Here it is my test program : > > #!/usr/bin/env python > import minimalmodbus as mmbus > mmbus.CLOSE_PORT_AFTER_EACH_CALL = True > import serial > import datetime > import time > ins = mmbus.Instrument('/dev/ttyUSB0', 1, mode='rtu') # port name, slave address (in decimal) > ins.debug = True > ins.serial.baudrate = 9600 > ins.serial.bytesize = 8 > ins.serial.parity = serial.PARITY_NONE > ins.serial.stopbits = 1 > ins.serial.timeout = 0.5 > #time.sleep(0.5) > print(ins.read_registers(10001,4,3)) > > And that the response of instrument : > > MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): "\x01\x03'\x11\x00\x04\x1e\xb8" (01 03 27 11 00 04 1E B8) > MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591509730.0 ms, minimum silent period: 4.01 ms. > MinimalModbus debug mode. Response from instrument: '\x01\x83\x02\xc0\xf1' (01 83 02 C0 F1) (5 bytes), roundtrip time: 500.6 ms. Timeout setting: 500.0 ms. > Traceback (most recent call last): > File "./MODBUS_CR200.py", line 27, in <module> > print(ins.read_registers(10001,4,3)) > File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 498, in read_registers > numberOfRegisters=numberOfRegisters, payloadformat='registers') > File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 697, in _genericCommand > payloadFromSlave = self._performCommand(functioncode, payloadToSlave) > File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 798, in _performCommand > payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode) > File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 1088, in _extractPayload > raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response)) > ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1' > > Note that it is working when I try to print register like "1" and same > parameters, I have this: > > MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): '\x01\x03\x00\x01\x00\x04\x15\xc9' (01 03 00 01 00 04 15 C9) > MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591490909.2 ms, minimum silent period: 4.01 ms. > MinimalModbus debug mode. Response from instrument: '\x01\x03\x08\x91aAA\x97\xb6DQ!\xc1' (01 03 08 91 61 41 41 97 B6 44 51 21 C1) (13 bytes), roundtrip time: 74.6 ms. Timeout setting: 500.0 ms. > [37217, 16705, 38838, 17489] > > So there are values. > I had contact severals technician of Campbell Scientific but they can > explain why I have this error (in the other hand, they don't support > python program). > > Have you an idea ? > > Thank you, > bye. > > > PS : careful, documentation about specific modbus progs are for > another datalogger named 'CR1000', there are some differences between > CR200X and CR1000. And there is the diagnostic in attached. > > -- > Benjamin VIAL > Institut des Sciences de la Terre - Grenoble > tel : (+33)4.76.63.52.16 > mob : (+33)6.14.83.25.42 > -- Benjamin VIAL Institut des Sciences de la Terre - Grenoble tel : (+33)4.76.63.52.16 mob : (+33)6.14.83.25.42 |
From: Jonas B. <jon...@ho...> - 2017-02-26 11:27:42
|
Hi Benjamin! I guess you use the wrong address. Use address 1 instead of 10001. Please see the section "Coil, discrete input, input register, holding register numbers and addresses" on this page: https://en.wikipedia.org/wiki/Modbus <http://https://en.wikipedia.org/wiki/Modbus> Best regards Jonas <-----Ursprungligt Meddelande-----> From: Benjamin VIAL [ben...@un...] Sent: 20/2/2017 12:56:02 PM To: min...@li... Subject: [Minimalmodbus-list] problem with some register address ? Hello, context : I'm trying to read register on a datalogger (Campbell CR200X) that is supposed to have modbus slave protocol (RTU only). As it is write in documentation <https://s.campbellsci.com/documents/us/manuals/cr200.pdf> , CR200X ( link on specific modbus programmation <https://s.campbellsci.com/documents/us/technical-papers/dataloggers-as- modbus-slave-devices.pdf> ) have a precise registers table. In my python code, I can read register 1, 2, etc, but not more than6 when I want read 10 register () and no more regiter 7 when I try to read 6 registers (), that's strange. Here it is my test program : #!/usr/bin/env python import minimalmodbus as mmbus mmbus.CLOSE_PORT_AFTER_EACH_CALL = True import serial import datetime import time ins = mmbus.Instrument('/dev/ttyUSB0', 1, mode='rtu') # port name, slave address (in decimal) ins.debug = True ins.serial.baudrate = 9600 ins.serial.bytesize = 8 ins.serial.parity = serial.PARITY_NONE ins.serial.stopbits = 1 ins.serial.timeout = 0.5 #time.sleep(0.5) print(ins.read_registers(10001,4,3)) And that the response of instrument : MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): "\x01\x03'\x11\x00\x04\x1e\xb8" (01 03 27 11 00 04 1E B8) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591509730.0 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x01\x83\x02\xc0\xf1' (01 83 02 C0 F1) (5 bytes), roundtrip time: 500.6 ms. Timeout setting: 500.0 ms. Traceback (most recent call last): File "./MODBUS_CR200.py", line 27, in <module> print(ins.read_registers(10001,4,3)) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 498, in read_registers numberOfRegisters=numberOfRegisters, payloadformat='registers') File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 697, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 798, in _performCommand payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 1088, in _extractPayload raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response)) ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1' Note that it is working when I try to print register like "1" and same parameters, I have this: MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): '\x01\x03\x00\x01\x00\x04\x15\xc9' (01 03 00 01 00 04 15 C9) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591490909.2 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x01\x03\x08\x91aAA\x97\xb6DQ!\xc1' (01 03 08 91 61 41 41 97 B6 44 51 21 C1) (13 bytes), roundtrip time: 74.6 ms. Timeout setting: 500.0 ms. [37217, 16705, 38838, 17489] So there are values. I had contact severals technician of Campbell Scientific but they can explain why I have this error (in the other hand, they don't support python program). Have you an idea ? Thank you, bye. PS : careful, documentation about specific modbus progs are for another datalogger named 'CR1000', there are some differences between CR200X and CR1000. And there is the diagnostic in attached. -- Benjamin VIAL Institut des Sciences de la Terre - Grenoble tel : (+33)4.76.63.52.16 mob : (+33)6.14.83.25.42 |
From: Jonas B. <jon...@ho...> - 2017-02-26 11:27:40
|
Hi Ben! By default read_register does not do any conversion (that is numberOfDecimals=0 and signed=False). It will give you the exact contents of the register, so you can do any conversion yourself. The twos complement calculation is only done if you use signed=True. Please see the documentation details on https://minimalmodbus.readthedocs.io/en/master/apiminimalmodbus.html#min imalmodbus.Instrument.read_register <http://https://minimalmodbus.readthedocs.io/en/master/apiminimalmodbus. html#minimalmodbus.Instrument.read_register> Best regards Jonas <-----Ursprungligt Meddelande-----> From: Benjamin Bramhall Sinnett [Ben...@co...] Sent: 24/2/2017 5:51:45 PM To: min...@li... Subject: [Minimalmodbus-list] Two's Complement Hello, I am using MinimalModbus to get temperature reads off a K type thermocouple sensor and am having trouble getting negative temperature readings. The range of the sensor is -5.891mV to 54.886mV which makes me think that the problem is in the way read_register interprets negative values, specifically using Two's Complement. Is there any way to turn this off to get a direct read out? I looked into converting, but I think, if possible, it would be better not to mess with that. Thank you for your time, ~ Ben |
From: Benjamin B. S. <Ben...@co...> - 2017-02-24 17:25:18
|
Hello, I am using MinimalModbus to get temperature reads off a K type thermocouple sensor and am having trouble getting negative temperature readings. The range of the sensor is -5.891mV to 54.886mV which makes me think that the problem is in the way read_register interprets negative values, specifically using Two's Complement. Is there any way to turn this off to get a direct read out? I looked into converting, but I think, if possible, it would be better not to mess with that. Thank you for your time, ~ Ben |
From: Benjamin V. <ben...@un...> - 2017-02-20 11:58:16
|
Hello, context : I'm trying to read register on a datalogger (Campbell CR200X) that is supposed to have modbus slave protocol (RTU only). As it is write in documentation <https://s.campbellsci.com/documents/us/manuals/cr200.pdf>, CR200X (link on specific modbus programmation <https://s.campbellsci.com/documents/us/technical-papers/dataloggers-as-modbus-slave-devices.pdf>) have a precise registers table. In my python code, I can read register 1, 2, etc, but not more than6 when I want read 10 register () and no more regiter 7 when I try to read 6 registers (), that's strange. Here it is my test program : #!/usr/bin/env python import minimalmodbus as mmbus mmbus.CLOSE_PORT_AFTER_EACH_CALL = True import serial import datetime import time ins = mmbus.Instrument('/dev/ttyUSB0', 1, mode='rtu') # port name, slave address (in decimal) ins.debug = True ins.serial.baudrate = 9600 ins.serial.bytesize = 8 ins.serial.parity = serial.PARITY_NONE ins.serial.stopbits = 1 ins.serial.timeout = 0.5 #time.sleep(0.5) print(ins.read_registers(10001,4,3)) And that the response of instrument : MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): "\x01\x03'\x11\x00\x04\x1e\xb8" (01 03 27 11 00 04 1E B8) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591509730.0 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x01\x83\x02\xc0\xf1' (01 83 02 C0 F1) (5 bytes), roundtrip time: 500.6 ms. Timeout setting: 500.0 ms. Traceback (most recent call last): File "./MODBUS_CR200.py", line 27, in <module> print(ins.read_registers(10001,4,3)) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 498, in read_registers numberOfRegisters=numberOfRegisters, payloadformat='registers') File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 697, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 798, in _performCommand payloadFromSlave = _extractPayload(response, self.address, self.mode, functioncode) File "/usr/local/lib/python2.7/dist-packages/minimalmodbus.py", line 1088, in _extractPayload raise ValueError('The slave is indicating an error. The response is: {!r}'.format(response)) ValueError: The slave is indicating an error. The response is: '\x01\x83\x02\xc0\xf1' Note that it is working when I try to print register like "1" and same parameters, I have this: MinimalModbus debug mode. Writing to instrument (expecting 13 bytes back): '\x01\x03\x00\x01\x00\x04\x15\xc9' (01 03 00 01 00 04 15 C9) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1487591490909.2 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x01\x03\x08\x91aAA\x97\xb6DQ!\xc1' (01 03 08 91 61 41 41 97 B6 44 51 21 C1) (13 bytes), roundtrip time: 74.6 ms. Timeout setting: 500.0 ms. [37217, 16705, 38838, 17489] So there are values. I had contact severals technician of Campbell Scientific but they can explain why I have this error (in the other hand, they don't support python program). Have you an idea ? Thank you, bye. PS : careful, documentation about specific modbus progs are for another datalogger named 'CR1000', there are some differences between CR200X and CR1000. And there is the diagnostic in attached. -- Benjamin VIAL Institut des Sciences de la Terre - Grenoble tel : (+33)4.76.63.52.16 mob : (+33)6.14.83.25.42 |
From: Jonas B. <jon...@ho...> - 2016-12-19 20:15:15
|
Hi Benjamin! First of all, use the Windows program from the supplier homepage, so you can learn to use the instrument. You should only use one instrument instance in MinimalModbus with this equipment. Use different registers to read the different channels. The factory default slave address for your instrument is 1, so you should probably use that value. Make sure that everything works perfectly before starting to use any GUI code, as that makes everything much more complicated. Best regards Jonas <-----Ursprungligt Meddelande-----> From: Benjamin Bramhall Sinnett [Ben...@co...] Sent: 13/12/2016 8:44:14 PM To: min...@li... Subject: [Minimalmodbus-list] Trouble Reading Sensor and Looping Hello, I am working on a GUI in python that will automate sampling of N2O flasks. Part of this GUI is continuously reading a pressure sensor and thermocouple that are hooked up to a seven channel, DGH D6400 - RTU Protocol, RS-485 Serial Interface modbus. I have been able to get the pressure sensor to read in using PreshReading.set(Pirani.read_register(3,6)). I have this in a while loop that updates the GUI, but it does not seem to be continuously updating (Attached is a basic version of the code so you can get a better idea). I am just wondering if there is something I have to change to get a continuously reading. I have tried changing the timeout to 0, but I get an IOError: No communication with instrument( no answer). The second issue I am encountering is trying to get temperature readings from a Thermocouple. I have yet to get a reading from as I keep getting the IOError: No communication with instrument (no answer). I am using the same method as the pressure gauge, (Thermo.read_register(3,6)), but with no results. Since the thermocouple is just a wire and doesn't have an instrument attached, I am wondering if it needs some special treatment? I have read the readthedoc several times and still can't figure it out. Maybe I missed something? Thank you for your help and let me know if you need anything more from me. ~ Ben |
From: Benjamin B. S. <Ben...@co...> - 2016-12-13 20:08:20
|
Hello, I am working on a GUI in python that will automate sampling of N2O flasks. Part of this GUI is continuously reading a pressure sensor and thermocouple that are hooked up to a seven channel, DGH D6400 - RTU Protocol, RS-485 Serial Interface modbus. I have been able to get the pressure sensor to read in using PreshReading.set(Pirani.read_register(3,6)). I have this in a while loop that updates the GUI, but it does not seem to be continuously updating (Attached is a basic version of the code so you can get a better idea). I am just wondering if there is something I have to change to get a continuously reading. I have tried changing the timeout to 0, but I get an IOError: No communication with instrument( no answer). The second issue I am encountering is trying to get temperature readings from a Thermocouple. I have yet to get a reading from as I keep getting the IOError: No communication with instrument (no answer). I am using the same method as the pressure gauge, (Thermo.read_register(3,6)), but with no results. Since the thermocouple is just a wire and doesn't have an instrument attached, I am wondering if it needs some special treatment? I have read the readthedoc several times and still can't figure it out. Maybe I missed something? Thank you for your help and let me know if you need anything more from me. ~ Ben |
From: Jonas B. <jon...@ho...> - 2016-11-22 21:25:39
|
Hi David! A value 100 (dec) is written 64 as hex. In Python that is entered as 0x64. So these are equivalent: instrument.read_register(100, 1) instrument.read_register(0x64, 1) Best regards Jonas From: David Sweeney <da...@th...> Sent: Sunday, November 20, 2016 23:14 To: Jonas Berg Subject: Minimalmodbus Jonas: Are you still maintaining minimalmodbus? If so, I have a question. How can I send a series of hexadecimal values to an RTU slave address? Thanks! -- David Sweeney da...@th... <mailto:da...@th...> |
From: Michael T. <mic...@en...> - 2016-11-09 02:35:46
|
I'm trying to communicate to a custom board via Modbus RTU-half duplex RS-485 connection from my windows machine (windows 10). I'm using the MinimalModbus API and have all the dependent libraries installed. I also have the proper RS-422/485 adapter on the correct settings (USOPTL4). I know the baud-rate, COM port, slave address and parity bit are all correct for my configuration. I also know my code is outputting a bit-stream from an O-scope trace I took. For some reason the board wont respond back at all, for a simple IO read from address 11 which should be a 1 bit input coil. I’ve changed all the settings that are commented out I also have tried to read as register instead of bit and I still get one of two errors. Any help would be MUCH appreciated. Code: import minimalmodbus import serial minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True minimalmodbus.PARITY = serial.PARITY_EVEN #minimalmodbus.handle_local_echo=True minimalmodbus.BAUDRATE = 57600 minimalmodbus.TIMEOUT = .1 instrument = minimalmodbus.Instrument('COM4',1) instrument.debug = True print(instrument) print(instrument.read_bit(11,functioncode=2)) Output: minimalmodbus.Instrument<id=0x14b5b10, address=1, mode=rtu, close_port_after_each_call=True, precalculate_read_size=True, debug=True, serial=Serial<id=0x19815d0, open=False>(port='COM4', baudrate=57600, bytesize=8, parity='E', stopbits=1, timeout=0.1, xonxoff=False, rtscts=False, dsrdtr=False)> Traceback (most recent call last): File "RS485.py", line 12, in <module> print(instrument.read_bit(11,functioncode=2)) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 193, in read_bit return self._genericCommand(functioncode, registeraddress) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 697, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 795, in _performCommand response = self._communicate(request, number_of_bytes_to_read) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 854, in _communicate format(number_of_bytes_to_read, request, _hexlify(request))) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 2357, in _print_out sys.stdout.write(inputstring + '\n') File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\encodings\cp437.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_map)[0] UnicodeEncodeError: 'charmap' codec can't encode character '\xc8' in position 101: character maps to <undefined> Output w/ slave address changed to 0 (which I think is wrong): minimalmodbus.Instrument<id=0x1461430, address=0, mode=rtu, close_port_after_each_call=False, precalculate_read_size=True, debug=True, serial=Serial<id=0x14615d0, open=True>(port='COM4', baudrate=57600, bytesize=8, parity='E', stopbits=1, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)> MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x00\x03\x00\x0b\x00\x01ô\x19' (00 03 00 0B 00 01 F4 19) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1478645250699.0 ms, minimum silent period: 0.67 ms. MinimalModbus debug mode. Response from instrument: '' () (0 bytes), roundtrip time: 50.0 ms. Timeout setting: 50.0 ms. Traceback (most recent call last): File "RS485.py", line 12, in <module> print(instrument.read_register(11,1)) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 258, in read_register return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 697, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 795, in _performCommand response = self._communicate(request, number_of_bytes_to_read) File "C:\Users\mtangy\AppData\Local\Programs\Python\Python35-32\lib\site-packages\minimalmodbus.py", line 930, in _communicate raise IOError('No communication with the instrument (no answer)') OSError: No communication with the instrument (no answer) Output you requested: >>> minimalmodbus._getDiagnosticString() "\n## Diagnostic output from minimalmodbus ## \n\nMinimalmodbus version: 0.7\nMinimalmodbus status: Beta\nFile name (with relative path): C:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\minimalmodbus.py\nFull file path: C:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\minimalmodbus.py\n\npySerial version: 3.2.1\npySerial full file path: C:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\\serial\\__init__.py\n\nPlatform: win32\nFilesystem encoding: 'mbcs'\nByteorder: little\nPython version: 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)]\nPython version info: sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)\nPython flags: sys.flags(debug=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, verbose=0, bytes_warning=0, quiet=0, hash_randomization=1, isolated=0)\nPython argv: ['']\nPython prefix: 'C:\\\\Users\\\\mtangy\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python35-32'\nPython exec prefix: 'C:\\\\Users\\\\mtangy\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python35-32'\nPython executable: 'C:\\\\Users\\\\mtangy\\\\AppData\\\\Local\\\\Programs\\\\Python\\\\Python35-32\\\\python.exe'\nLong info: (none)\nFloat repr style: 'short'\n\nVariable __name__: minimalmodbus\nCurrent directory: C:\\Users\\mtangy\\Documents\\ASB_Modbus\n\nPython path: \n\nC:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\python35.zip\nC:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\DLLs\nC:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\nC:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\nC:\\Users\\mtangy\\AppData\\Local\\Programs\\Python\\Python35-32\\lib\\site-packages\n\n## End of diagnostic output ## \n" Modbus library imports without any output or errors. Any help or feedback would be MUCH appreciated. Regards, Michael Tangy |
From: Jonas B. <jon...@ho...> - 2016-11-01 21:24:00
|
Hi! Unfortunately does not MinimalModbus support running as a slave (server). I guess pymodbus can do that, but I have never tried myself. See https://pymodbus.readthedocs.io/en/latest/examples/synchronous-server.ht ml <http://https://pymodbus.readthedocs.io/en/latest/examples/synchronous-s erver.html> Good luck! /Jonas <-----Ursprungligt Meddelande-----> From: Phani Kumar [pha...@gm...] Sent: 17/10/2016 11:16:56 AM To: he...@py...;min...@li... Subject: [Minimalmodbus-list] Minimal MODBUS RTU on Hi, I am trying to write a code on Raspberry Pi as slave [Note that the computer (master) actually is a client, and the instruments (slaves) are servers.] to send data on minimal modbus once I receive the command to read particular coil/ register. Are there any example of minimal modbus example on Slave? All the examples I see are for masters (on PC side). Thanks in advance and with best regards, Phani. |
From: Phani K. <pha...@gm...> - 2016-10-17 10:18:03
|
Hi, I am trying to write a code on Raspberry Pi as slave [Note that the computer (master) actually is a client, and the instruments (slaves) are servers.] to send data on minimal modbus once I receive the command to read particular coil/ register. Are there any example of minimal modbus example on Slave? All the examples I see are for masters (on PC side). Thanks in advance and with best regards, Phani. |
From: Holger S. <hol...@s2...> - 2016-10-14 13:43:46
|
Hello support team, recently I started working on my master thesis at Technical University Chemnitz which includes the implementation of a temperature controller via serial communication. I'm using an OMRON E5EN-H with RS232 communication module (manual: http://www.omronkft.hu/pdf_en/e5_n-h_user_man.pdf, details for serial communication in: https://www.fa.omron.com.cn/data_pdf/mnu/h170-e1-01_e5cn-ht_e5an-ht_e5en-ht.pdf?id=3025) The controller offers two types of communication, I decided to use modbus and therefore found your python module MinimalModbus which seems to work so far. The problem now is that I always get an error message that I can't understand. My code for first communcatin tests looks like: ################################################### import minimalmodbus minimalmodbus.BAUDRATE = 9600 minimalmodbus.STOPBITS = 2 minimalmodbus.PARITY = 'E' minimalmodbus.BYTESIZE = 8 minimalmodbus.STOPBITS = 2 minimalmodbus.TIMEOUT = 0.05 minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True instrument = minimalmodbus.Instrument('COM12', 5, mode='rtu') instrument.debug = True print instrument print minimalmodbus._getDiagnosticString() try: print(instrument.read_register(0000, 1, functioncode=3, signed=True)) except IOError: print("Failed to read from instrument") ################################################## with the following output: ################################################## minimalmodbus.Instrument<id=0x21ab850, address=5, mode=rtu, close_port_after_each_call=True, precalculate_read_size=True, debug=True, serial=Serial<id=0x21c84d0, open=False>(port='COM12', baudrate=9600, bytesize=8, parity='E', stopbits=2, timeout=0.05, xonxoff=False, rtscts=False, dsrdtr=False)> ## Diagnostic output from minimalmodbus ## Minimalmodbus version: 0.7 Minimalmodbus status: Beta File name (with relative path): C:\Python27\lib\minimalmodbus.pyc Full file path: C:\Python27\lib\minimalmodbus.pyc pySerial version: 3.0.1 pySerial full file path: C:\Python27\lib\site-packages\serial\__init__.pyc Platform: win32 Filesystem encoding: 'mbcs' Byteorder: little Python version: 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] Python version info: sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0) Python flags: sys.flags(debug=0, py3k_warning=0, division_warning=0, division_new=0, inspect=0, interactive=0, optimize=0, dont_write_bytecode=0, no_user_site=0, no_site=0, ignore_environment=0, tabcheck=0, verbose=0, unicode=0, bytes_warning=0, hash_randomization=0) Python argv: ['C:\\Users\\Holger\\Desktop\\TEG\\Programme\\Python\\PID test.py'] Python prefix: 'C:\\Python27' Python exec prefix: 'C:\\Python27' Python executable: 'C:\\Python27\\python.exe' Long info: sys.long_info(bits_per_digit=15, sizeof_digit=2) Float repr style: 'short' Variable __name__: minimalmodbus Current directory: C:\Users\Holger\Desktop\TEG\Programme\Python Python path: C:\Users\Holger\Desktop\TEG\Programme\Python C:\Python27\lib\site-packages\spyderlib\utils\external C:\Python27\lib\site-packages\pyvisa-1.8-py2.7.egg C:\Python27\lib\site-packages\enum34-1.1.5-py2.7.egg C:\Windows\system32\python27.zip C:\Python27\DLLs C:\Python27\lib C:\Python27\lib\plat-win C:\Python27\lib\lib-tk C:\Python27 C:\Python27\lib\site-packages C:\Python27\lib\site-packages\PIL C:\Python27\lib\site-packages\win32 C:\Python27\lib\site-packages\win32\lib C:\Python27\lib\site-packages\Pythonwin C:\Python27\lib\site-packages\wx-2.8-msw-unicode ## End of diagnostic output ## MinimalModbus debug mode. Writing to instrument (expecting 7 bytes back): '\x05\x03\x00\x00\x00\x01\x85\x8e' (05 03 00 00 00 01 85 8E) MinimalModbus debug mode. No sleep required before write. Time since previous read: 1476449226105.0 ms, minimum silent period: 4.01 ms. MinimalModbus debug mode. Response from instrument: '\x05\x03\x00a1' (05 03 00 61 31) (5 bytes), roundtrip time: 84.0 ms. Timeout setting: 50.0 ms. Traceback (most recent call last): File "C:\Users\Holger\Desktop\TEG\Programme\Python\PID test.py", line 24, in <module> print(instrument.read_register(0000, 1, functioncode=3, signed=True)) File "C:\Python27\lib\minimalmodbus.py", line 258, in read_register return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals, signed=signed) File "C:\Python27\lib\minimalmodbus.py", line 732, in _genericCommand 'Given {0!r} and {1!r}.'.format(len(registerdata), numberOfRegisterBytes)) ValueError: The registerdata length does not match number of register bytes. Given 0 and 2. ##################################################### The settings (like baudrate, parity, bytesize etc.) for host-PC and slave are the same and according to the information from the debug mode it seems there is information send correctly and ther is also some response from the instrument. As I said before we were not able to deal with this error and so I hope for your help in this case. Best regards, Holger Schwarz Technische Universität Chemnitz |
From: <fr...@in...> - 2016-08-15 14:18:16
|
Hello again, so now i got the information that it is ABCD... for me that means that it is real standard float. I tried out, checked the Hex and i got the right values I checked here: http://www.binaryconvert.com/result_float.html?hexadecimal=453E616F A B = 45 3E C D = 61 6F That brings me the right numbers (So i have to multiply 1000 set the comma to the right place). If i have a Value like 3.19078458944e-26 how can i bring that to a decimal number? Sorry for interrupt and maybe i am to dumb to understand but my brain burns an i can not see any solutions. Regards Franz Zitat von Olivier Maily <om...@re...>: > Hi, > > I did this once in python2. > > def float(ip,register,unit,order="ABCD"): > client=ModbusTcpClient(ip) > val=client.read_holding_registers(register,2,unit=unit) > if (order=="CDAB"): > return float_CDAB(val.registers) > elif (order=="BADC"): > return float_BADC(val.registers) > elif (order=="DCBA"): > return float_DCBA(val.registers) > else: #order par defaut ABCD > return float_ABCD(val.registers) > client.close() > > > This is what I used to transform the integer that I read with the pymodbus > import struct > > def data_to_ hex (data): > hexa1="%0.4X" % data[0] > hexa2="%0.4X" % data[1] > return hexa1+hexa2 > > def float_ABCD(data): > hex=data_to_hex(data) > val=struct.unpack('!f' ,hex.decode('hex'))[0] > return val > > def float_CDAB(data): > hex=data_to_ hex (data) > decoup=list(hex) > > new_hex=decoup[4]+decoup[5]+decoup[6]+decoup[7]+decoup[0]+decoup[1]+decoup[2]+decoup[3] > val=struct.unpack('!f' ,new_hex.decode('hex'))[0] > return val > > def float_BADC(data): > hex=data_to_ hex (data) > decoup=list(hex) > > new_hex=decoup[2]+decoup[3]+decoup[0]+decoup[1]+decoup[6]+decoup[7]+decoup[4]+decoup[5] > val=struct.unpack('!f' ,new_hex.decode('hex'))[0] > return val > > def float_DCBA(data): > hex=data_to_ hex (data) > decoup=list(hex) > > new_hex=decoup[6]+decoup[7]+decoup[4]+decoup[5]+decoup[2]+decoup[3]+decoup[0]+decoup[1] > val=struct.unpack('!f' ,new_hex.decode('hex'))[0] > return val > > > Hope this will helping you. > > Regards, > > Olivier Maily > > -----Message d'origine----- > De : fr...@in... [mailto:fr...@in...] > Envoyé : 15 août 2016 03:25 > À : Olivier Maily <om...@re...> > Cc : min...@li... > Objet : Re: [Minimalmodbus-list] read Float of two registers - swapped float? > > Hello Olivier, > > > i have read that but i have no idea how to handle that problem. I am > not the best programmer in python and i thougt there is a option in > minimalmodbus to show swapped float register.A colleage of me told > me that years ago i had a solution but i have forgotten and i have > no backup of that file. I can not believe that there is no option in > minimalmodbus to get the correct value. > > Thanks a lot > > > > > > Zitat von Olivier Maily <om...@re...>: > >> Hi >> >> Did you try this >> http://stackoverflow.com/questions/1592158/convert-hex-to-float >> >> >> -----Message d'origine----- >> De : fr...@in... [mailto:fr...@in...] Envoyé : 12 août >> 2016 03:28 À : min...@li... >> Objet : [Minimalmodbus-list] read Float of two registers - swapped float? >> >> Hello everybody, >> >> i got a problem. I should read a Float Register from a Sensor. >> As result, i got a number with exponent. In the Modbus Tester i have >> to switch to Swapped Float to get the correct Value. >> >> ------------------------------ >> >> float_list[count] = x.read_float(floatregister_list[count], >> functioncode=4, numberOfRegisters=2) >> >> (...) >> >> print '{x}\t{snf}\t{fl}\t{d}\t{t}'.format(snf=snf, x=count, >> fl=float_list[count], d=heute.strftime('%d.%m.%Y'), >> >> t=datetime.datetime.now().strftime("%H:%M:%S")) >> >> Print output : >> 1 VW1 1.52489298888e-41 12.08.2016 07:11:58 >> >> >> >> but it should be that: >> 3045,99438 >> >> >> The single registers: >> Input Register 1= 17726 >> Input Register 2= 24296 >> >> >> >> How can i handle this to get a output as i want? Is there something >> special for swapped float? >> >> >> ---------------------------------------------------------------------- >> -------- What NetFlow Analyzer can do for you? Monitors network >> bandwidth and traffic patterns at an interface-level. Reveals which >> users, apps, and protocols are consuming the most bandwidth. Provides >> multi-vendor support for NetFlow, J-Flow, sFlow and other flows. >> Make informed decisions using capacity planning reports. >> http://sdm.link/zohodev2dev >> _______________________________________________ >> Minimalmodbus-list mailing list >> Min...@li... >> https://lists.sourceforge.net/lists/listinfo/minimalmodbus-list |
From: Olivier M. <om...@re...> - 2016-08-15 12:19:27
|
Hi, I did this once in python2. def float(ip,register,unit,order="ABCD"): client=ModbusTcpClient(ip) val=client.read_holding_registers(register,2,unit=unit) if (order=="CDAB"): return float_CDAB(val.registers) elif (order=="BADC"): return float_BADC(val.registers) elif (order=="DCBA"): return float_DCBA(val.registers) else: #order par defaut ABCD return float_ABCD(val.registers) client.close() This is what I used to transform the integer that I read with the pymodbus import struct def data_to_ hex (data): hexa1="%0.4X" % data[0] hexa2="%0.4X" % data[1] return hexa1+hexa2 def float_ABCD(data): hex=data_to_hex(data) val=struct.unpack('!f' ,hex.decode('hex'))[0] return val def float_CDAB(data): hex=data_to_ hex (data) decoup=list(hex) new_hex=decoup[4]+decoup[5]+decoup[6]+decoup[7]+decoup[0]+decoup[1]+decoup[2]+decoup[3] val=struct.unpack('!f' ,new_hex.decode('hex'))[0] return val def float_BADC(data): hex=data_to_ hex (data) decoup=list(hex) new_hex=decoup[2]+decoup[3]+decoup[0]+decoup[1]+decoup[6]+decoup[7]+decoup[4]+decoup[5] val=struct.unpack('!f' ,new_hex.decode('hex'))[0] return val def float_DCBA(data): hex=data_to_ hex (data) decoup=list(hex) new_hex=decoup[6]+decoup[7]+decoup[4]+decoup[5]+decoup[2]+decoup[3]+decoup[0]+decoup[1] val=struct.unpack('!f' ,new_hex.decode('hex'))[0] return val Hope this will helping you. Regards, Olivier Maily -----Message d'origine----- De : fr...@in... [mailto:fr...@in...] Envoyé : 15 août 2016 03:25 À : Olivier Maily <om...@re...> Cc : min...@li... Objet : Re: [Minimalmodbus-list] read Float of two registers - swapped float? Hello Olivier, i have read that but i have no idea how to handle that problem. I am not the best programmer in python and i thougt there is a option in minimalmodbus to show swapped float register.A colleage of me told me that years ago i had a solution but i have forgotten and i have no backup of that file. I can not believe that there is no option in minimalmodbus to get the correct value. Thanks a lot Zitat von Olivier Maily <om...@re...>: > Hi > > Did you try this > http://stackoverflow.com/questions/1592158/convert-hex-to-float > > > -----Message d'origine----- > De : fr...@in... [mailto:fr...@in...] Envoyé : 12 août > 2016 03:28 À : min...@li... > Objet : [Minimalmodbus-list] read Float of two registers - swapped float? > > Hello everybody, > > i got a problem. I should read a Float Register from a Sensor. > As result, i got a number with exponent. In the Modbus Tester i have > to switch to Swapped Float to get the correct Value. > > ------------------------------ > > float_list[count] = x.read_float(floatregister_list[count], > functioncode=4, numberOfRegisters=2) > > (...) > > print '{x}\t{snf}\t{fl}\t{d}\t{t}'.format(snf=snf, x=count, > fl=float_list[count], d=heute.strftime('%d.%m.%Y'), > > t=datetime.datetime.now().strftime("%H:%M:%S")) > > Print output : > 1 VW1 1.52489298888e-41 12.08.2016 07:11:58 > > > > but it should be that: > 3045,99438 > > > The single registers: > Input Register 1= 17726 > Input Register 2= 24296 > > > > How can i handle this to get a output as i want? Is there something > special for swapped float? > > > ---------------------------------------------------------------------- > -------- What NetFlow Analyzer can do for you? Monitors network > bandwidth and traffic patterns at an interface-level. Reveals which > users, apps, and protocols are consuming the most bandwidth. Provides > multi-vendor support for NetFlow, J-Flow, sFlow and other flows. > Make informed decisions using capacity planning reports. > http://sdm.link/zohodev2dev > _______________________________________________ > Minimalmodbus-list mailing list > Min...@li... > https://lists.sourceforge.net/lists/listinfo/minimalmodbus-list |
From: <fr...@in...> - 2016-08-15 07:25:12
|
Hello Olivier, i have read that but i have no idea how to handle that problem. I am not the best programmer in python and i thougt there is a option in minimalmodbus to show swapped float register.A colleage of me told me that years ago i had a solution but i have forgotten and i have no backup of that file. I can not believe that there is no option in minimalmodbus to get the correct value. Thanks a lot Zitat von Olivier Maily <om...@re...>: > Hi > > Did you try this > http://stackoverflow.com/questions/1592158/convert-hex-to-float > > > -----Message d'origine----- > De : fr...@in... [mailto:fr...@in...] > Envoyé : 12 août 2016 03:28 > À : min...@li... > Objet : [Minimalmodbus-list] read Float of two registers - swapped float? > > Hello everybody, > > i got a problem. I should read a Float Register from a Sensor. > As result, i got a number with exponent. In the Modbus Tester i have > to switch to Swapped Float to get the correct Value. > > ------------------------------ > > float_list[count] = x.read_float(floatregister_list[count], > functioncode=4, numberOfRegisters=2) > > (...) > > print '{x}\t{snf}\t{fl}\t{d}\t{t}'.format(snf=snf, x=count, > fl=float_list[count], d=heute.strftime('%d.%m.%Y'), > > t=datetime.datetime.now().strftime("%H:%M:%S")) > > Print output : > 1 VW1 1.52489298888e-41 12.08.2016 07:11:58 > > > > but it should be that: > 3045,99438 > > > The single registers: > Input Register 1= 17726 > Input Register 2= 24296 > > > > How can i handle this to get a output as i want? Is there something > special for swapped float? > > > ------------------------------------------------------------------------------ > What NetFlow Analyzer can do for you? Monitors network bandwidth and > traffic patterns at an interface-level. Reveals which users, apps, > and protocols are consuming the most bandwidth. Provides > multi-vendor support for NetFlow, J-Flow, sFlow and other flows. > Make informed decisions using capacity planning reports. > http://sdm.link/zohodev2dev > _______________________________________________ > Minimalmodbus-list mailing list > Min...@li... > https://lists.sourceforge.net/lists/listinfo/minimalmodbus-list |
From: Olivier M. <om...@re...> - 2016-08-12 11:59:26
|
Hi Did you try this http://stackoverflow.com/questions/1592158/convert-hex-to-float -----Message d'origine----- De : fr...@in... [mailto:fr...@in...] Envoyé : 12 août 2016 03:28 À : min...@li... Objet : [Minimalmodbus-list] read Float of two registers - swapped float? Hello everybody, i got a problem. I should read a Float Register from a Sensor. As result, i got a number with exponent. In the Modbus Tester i have to switch to Swapped Float to get the correct Value. ------------------------------ float_list[count] = x.read_float(floatregister_list[count], functioncode=4, numberOfRegisters=2) (...) print '{x}\t{snf}\t{fl}\t{d}\t{t}'.format(snf=snf, x=count, fl=float_list[count], d=heute.strftime('%d.%m.%Y'), t=datetime.datetime.now().strftime("%H:%M:%S")) Print output : 1 VW1 1.52489298888e-41 12.08.2016 07:11:58 but it should be that: 3045,99438 The single registers: Input Register 1= 17726 Input Register 2= 24296 How can i handle this to get a output as i want? Is there something special for swapped float? ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports. http://sdm.link/zohodev2dev _______________________________________________ Minimalmodbus-list mailing list Min...@li... https://lists.sourceforge.net/lists/listinfo/minimalmodbus-list |
From: <fr...@in...> - 2016-08-12 07:56:01
|
Hello everybody, i got a problem. I should read a Float Register from a Sensor. As result, i got a number with exponent. In the Modbus Tester i have to switch to Swapped Float to get the correct Value. ------------------------------ float_list[count] = x.read_float(floatregister_list[count], functioncode=4, numberOfRegisters=2) (...) print '{x}\t{snf}\t{fl}\t{d}\t{t}'.format(snf=snf, x=count, fl=float_list[count], d=heute.strftime('%d.%m.%Y'), t=datetime.datetime.now().strftime("%H:%M:%S")) Print output : 1 VW1 1.52489298888e-41 12.08.2016 07:11:58 but it should be that: 3045,99438 The single registers: Input Register 1= 17726 Input Register 2= 24296 How can i handle this to get a output as i want? Is there something special for swapped float? |
From: Fabio S. <fab...@gm...> - 2016-08-09 06:22:46
|
Hi, Yes Olivier you are right, I solved: http://raspberrypi.stackexchange.com/questions/47379/uart-problems-on-my-pi3 in particolar: ////////////////////////////////// You may also need to disable the serial console. The easiest way to do this is via raspi-config under Advanced Options -> Enable/Disable shell and kernel messages on the serial connection. If you don't have raspi-config, it doesn't work, and/or you want to double check, first look in /boot/cmdline.txt. If you see: console=/dev/ttyS0,115200 Or: console=/dev/serial0,115200 Or anything involving console= that isn't console=tty1, remove it. Make sure not to accidentally add a line break to that file, it should remain all one line with spaces between the options, but no spaces around any =. The other aspect is the login started by the init system. On Raspbian jessie, check: ls /etc/systemd/system/getty.target.wants If you see that serial device node (ttyS0) mentioned, disable this service: systemctl disable ser...@tt...rvice You will have to reboot for these things to take effect. ///////////////////////////////////////////////////////////////////////////////////// I don't know what I done, but it work! BR Fabio On 8 August 2016 at 23:53, Olivier Maily <om...@re...> wrote: > Hi > I think that is a problem with pyserial in the new raspbian... > They changed something with the tty console. > > I did a program for raspberry-pi in 2014 and renew it in the lasts few > month and I had a problem like this. > > Regards, > > > > Envoyé de mon appareil Samsung de Bell via le réseau le plus vaste au pays. > > > -------- Message d'origine -------- > De : Jonas Berg <jon...@ho...> > Date : 16-08-08 4:43 PM (GMT-05:00) > À : fab...@gm... > Cc : min...@li... > Objet : Re: [Minimalmodbus-list] problem no communication with > Raspberrywith Jessie > > Hi Fabio, > thanks for your report! > > This is very strange! > Can you please turn on the debug mode, and paste the output in a mail. > See https://minimalmodbus.readthedocs.io/en/master/debugmode.html > > My guess is that it might have something to do with the drivers for your > RS485 adapter. > > Best regards > Jonas > > <-----Ursprungligt Meddelande-----> > *From: Fabio Stranieri [fab...@gm... > <fab...@gm...>]* > Sent: 5/8/2016 6:07:26 PM > To: min...@li... > Subject: Re: [Minimalmodbus-list] problem no communication with > Raspberrywith Jessie > > I want to add this information: > > python version 2.7 > > Raspian 4.4.11 -V7+ #888 minimalmodbus NO work. > Raspian 4.1.19 -V7+ #858 minimalmodbus work perfectly. > BR > > On 5 August 2016 at 15:50, Fabio Stranieri <fab...@gm...> > wrote: > >> Hi, >> >> I have 2 Raspberry Pi 2. On the first there is a Raspbian Jessie 2015 >> version and minimalmodbus work fine without problem. >> >> On the second Raspberry Pi 2 there is the last Raspbian Jessie 2016-05-27 >> kernel version 4.4. >> > I have a clean installation with only minimalmodbus and there is not way > to communicate. > I use same file.py to test the communication. But I have always the same > answer: "No communication with the instrument (no answer). Of course if I > put in the second raspberry pi the sd card of the first raspberry PI, it > work fine. > > What is change in the last Raspbian that prevents to minimalmodbus to > work fine? > Best Regards > > -- > Fabio > > > > -- > Fabio Stranieri > -- Fabio Stranieri |