SHARE
TWEET

Untitled

a guest Jun 19th, 2017 44 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Import des librairies
  2. from modbusReader import CacheModBus
  3.  
  4. #On etablie une connexion, voir avec le buffer_size a renseiger peut etre ...
  5. cx = CacheModBus(host="ip", port="port", buffer_size=None)
  6.  
  7. #On lit une valeur
  8. cx.read("adresse")
  9.  
  10. #On peut tester en forcant le buffer
  11. cx.read("adress", user_buffer=False)
  12.  
  13. ##############################Modif Richard##########################################################
  14.  
  15.  
  16. #!/usr/bin/env python
  17. # -*- coding: utf-8 -*-
  18. # (c)2010 Ph.E Conseil
  19. import time
  20. import stomp
  21. import sys, glob
  22. from modbusReader import CacheModBus
  23.  
  24. print("Modbus Collector is starting ...")
  25.  
  26. #host = sys.argv[2] if len(sys.argv) > 2 else 'localhost'
  27. #port = sys.argv[3] if len(sys.argv) > 3 else 61613
  28.  
  29. #conn = stomp.Connection(host_and_ports=[(host, port)])
  30.  
  31. #conn.start()
  32. #conn.connect()
  33.  
  34. #cx = CacheModBus('192.168.1.210')
  35. cx = CacheModBus(host = '192.168.1.210', port = 502, buffer_size=None)
  36.  
  37. #lastPubDate = time.time()
  38. try:
  39.     while True:
  40.         print time.time(), 'modbus query ...'
  41.        
  42.         v = cx.read('%MW10')
  43.         print v
  44.         '''for var in ('%MW10'):
  45.        #for var in ('%MW400001'):
  46.            v = cx.read(var)
  47.            print time.time(), v, var
  48.            dest = '/var/inject/V%i'
  49.            #print '%s = %s' % (var, v)
  50.            if (time.time() - lastPubDate) > 0:
  51.                conn.send(v, destination=dest)
  52.                conn.send('V%i=%s' % (ctrl, v), destination='/var/inject')
  53.                #conn.send('V%i=%s' % (i, strVal), destination='/var/inject')
  54.                #conn.send(strVal, destination='/var/inject/V%i' % i)
  55.                lastPubDate = time.time()
  56.        time.sleep(0.5)
  57.        '''
  58. except KeyboardInterrupt:
  59.     print 'quitting ...'
  60.     cx.close()
  61. #    conn.disconnect()
RAW Paste Data
Top