Re: [Minimalmodbus-list] Error with MinimalModbus
Status: Beta
Brought to you by:
pyhys
|
From: Jonas B. <jon...@ho...> - 2012-12-08 15:07:35
|
Hi Paddy, and sorry for the delay in my response. To change the baudrate, you should use: instrument.serial.baudrate = 9600 It is described in more detail on http://minimalmodbus.sourceforge.net/index.html#default-values To see all the settings, you can use: print(instrument) Your code should look something like: #!/usr/bin/env python import minimalmodbus minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True instrument = minimalmodbus.Instrument('com3', 1) # port name, slave address (in decimal) instrument.debug = True instrument.serial.baudrate = 9600 print(instrument) print( instrument.read_register(2822, numberOfDecimals=1, functioncode=3)) The output produced by MinimalModbus seems to be correct: '\x01\x03\x0b\x06\x00\x01f/' Displayed Hex Dec Description \x01 01 1 Slave address (here 1) \x03 03 3 Function code (here 3 = read registers) \x0b 0b 11 Start address MSB \x06 06 6 Start address LSB \x00 00 0 Number of registers MSB \x01 01 1 Number of registers LSB f 66 106 CRC LSB / 2F 47 CRC MSB The register address is 11*256 + 6 = 2822 The CRC seems to be correct: >>> minimalmodbus._calculateCrcString('\x01\x03\x0b\x06\x00\x01') 'f/' Please paste the output from the code above in an e-mail, and I will help you solve the problem. Best regards Jonas <-----Ursprungligt Meddelande-----> From: Paddy Finn [pad...@gm...] Sent: 3/12/2012 6:06:09 PM To: min...@li... Subject: [Minimalmodbus-list] Error with MinimalModbus Hiya, I am trying to use MinimalModbus with Python33 on a Windows 64-bit system. The USB->RS485 device is a PL2303 which sets up a virtual COM port on COM3. The modbus device I'm reading is an energy meter with a baud rate of 9600, byte size of 8 bits, no parity, and 1 stop bit. I know that it is correctly set up as I can use some ModBus polling software querying COM3 with the aforementioned settings. I am using the following python code to attempt to read the device using MinimalModbus: #!/usr/bin/env python import minimalmodbus minimalmodbus.CLOSE_PORT_AFTER_EACH_CALL = True print(minimalmodbus._getDiagnosticString()) print(minimalmodbus.BAUDRATE) instrument = minimalmodbus.Instrument('com3', 1) # port name, slave address (in decimal) instrument.debug = True instrument.CLOSE_PORT_AFTER_EACH_CALL = True instrument.BAUDRATE = 9600 instrument.BYTESIZE = 8 instrument.STOPBITS = 1 print(instrument.BAUDRATE) print( instrument.read_register(2822, numberOfDecimals=1, functioncode=3)) But unfortunately it is returning the following: 19200 9600 MinimalModbus debug mode. Writing to instrument: '\x01\x03\x0b\x06\x00\x01f/' MinimalModbus debug mode. Response from instrument: '' Traceback (most recent call last): File "C:/Python33/Register Python.py", line 16, in <module> print( instrument.read_register(2822, numberOfDecimals=1, functioncode=3)) File "C:\Python33\lib\site-packages\minimalmodbus.py", line 174, in read_register return self._genericCommand(functioncode, registeraddress, numberOfDecimals=numberOfDecimals) File "C:\Python33\lib\site-packages\minimalmodbus.py", line 261, in _genericCommand payloadFromSlave = self._performCommand(functioncode, payloadToSlave) File "C:\Python33\lib\site-packages\minimalmodbus.py", line 317, in _performCommand response = self._communicate(message) File "C:\Python33\lib\site-packages\minimalmodbus.py", line 395, in _communicate raise IOError('No communication with the instrument (no answer)') OSError: No communication with the instrument (no answer) I have no idea where to start to find the problem and I was hoping that you could perhaps shed some light on what it is that I am doing wrong. Thanks a million!! Paddy <P><p><font face="Arial, Helvetica, sans-serif" size="2" style="font-size:13.5px">_______________________________________________________________<BR>Annons: <a href="http://adserver.adtech.de/?adlink|3.0|1297|4132301|1|16|AdId=8371245;BnId=1;link=http://www.vistaprint.se/vp/gateway.aspx?S=7280236673" target="_blank">Grattis! Nu kan du få en unik väggkalender gratis! Ladda upp dina favoritfoton och gör varje månad minnesvärd! Beställ nu och få en fotomugg på köpet!</a></font> |