SHARE
TWEET

Untitled

a guest May 19th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. from pymodbus.client.sync import ModbusSerialClient as ModbusClient
  4. from pymodbus.constants import Endian
  5. from pymodbus.payload import BinaryPayloadDecoder
  6. from pymodbus.payload import BinaryPayloadBuilder
  7. from pymodbus.client.sync import ModbusTcpClient
  8.  
  9.  
  10. #client = ModbusClient(method='rtu', port='31.133.10.68', timeout=1, stopbits = 1, bytesize = 8,  parity='E', baudrate= 9600)
  11. client = ModbusTcpClient('31.133.10.68')
  12. connection = client.connect()
  13.  
  14. print connection
  15.  
  16. data = {}
  17.  
  18. response = client.read_holding_registers(0x2020,4,unit=0x001)
  19. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  20.  
  21. data['Freq'] = "%0.2f" % decoder.decode_32bit_float()
  22.  
  23. print "Grid Freq: %0.2f" % decoder.decode_32bit_float()
  24.  
  25. response = client.read_holding_registers(0x2008,2,unit=0x001)
  26. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  27. print "L1 V: %0.2f" % decoder.decode_32bit_float()
  28.  
  29. response = client.read_holding_registers(0x2068,4,unit=0x001)
  30. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  31. print "L1 A: %0.2f" % decoder.decode_32bit_float()
  32.  
  33. response = client.read_holding_registers(0x2070,4,unit=0x001)
  34. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  35. print "L2 A: %0.2f" % decoder.decode_32bit_float()
  36.  
  37. response = client.read_holding_registers(0x206C,4,unit=0x001)
  38. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  39. print "L3 A: %0.2f" % decoder.decode_32bit_float()
  40.  
  41. response = client.read_holding_registers(0x2080,4,unit=0x001)
  42. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  43. print "Power: %0.2f" % decoder.decode_32bit_float()
  44.  
  45. response = client.read_holding_registers(0x20E0,4,unit=0x001)
  46. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  47. print "Cos fi: %0.2f" % decoder.decode_32bit_float()
  48.  
  49.  
  50. response = client.read_holding_registers(0x3000,4,unit=0x001)
  51. decoder = BinaryPayloadDecoder.fromRegisters(response.registers, Endian.Big, wordorder=Endian.Big)
  52. print "Total: %0.2f" % decoder.decode_32bit_float()
  53.  
  54.  
  55. print data
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top