4/27/2023 0 Comments Delphi modbus driver![]() ![]() In this article you have seen how to connect a MODBUS RS485 device to your laptop, and interrogate it using python. ![]() The temperature is: 19.7 deg C The humidity is: 53.4 percent import minimalmodbus PORT= '/dev/cu.usbserial-AC00XX39' TEMP_REGISTER = 100 HUM_REGISTER = 102 #Set up instrument instrument = minimalmodbus.Instrument(PORT,1,mode=minimalmodbus.MODE_RTU) #Make the settings explicit = 19200 # Baud = 8 = _EVEN = 1 = 1 # seconds # Good practice instrument.close_port_after_each_call = True instrument.clear_buffers_before_each_transaction = True # Read temperatureas a float # if you need to read a 16 bit register use instrument.read_register() temperature = instrument.read_float(TEMP_REGISTER) # Read the humidity humidity = instrument.read_float(HUM_REGISTER) #Pront the values print( 'The temperature is: %.1f deg C\r' % temperature) print( 'The humidity is: %.1f percent\r' % humidity) Make sure to check the parity and baud rate for your device, for mine it was 19200, E,8,1. ![]() One thing to note is that the instrument read methods set the MODBUS function code (FC) to 3 by default. It provides a friendly interface for quick configuring and communicating with our Modbus slave devices. Below is my test code, you can see the port setup, constants for the registers to query. Modbus Master Tool is a free and portable application developed by ICP DAS USA. TSH300v2 Register list Python MODBUS LibraryĪ good simple python MODBUS library is MinimalModbus. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |