[Minimalmodbus-list] Cannot communicate through USB-RS485 using minimalmodbus
Status: Beta
Brought to you by:
pyhys
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 |