modbus datentypen convertierungen hinzugefügt
This commit is contained in:
parent
3533b5164c
commit
2412589ef8
3 changed files with 34 additions and 5 deletions
|
|
@ -4,6 +4,8 @@ Created on 05.12.2013
|
|||
@author: Philipp Rauch
|
||||
'''
|
||||
from pymodbus.client.sync import ModbusTcpClient
|
||||
from datetime import datetime
|
||||
import struct
|
||||
|
||||
def setup(conf):
|
||||
PACS = []
|
||||
|
|
@ -28,9 +30,25 @@ def loop(PACS, item):
|
|||
# ans = PAC[0].write_registers(213,(1,0),unit=2)
|
||||
# print "Antwort: %s" % ans
|
||||
|
||||
res = PACS[0].read_holding_registers(213,4,unit=2)
|
||||
print "Werte: %s" % res.registers
|
||||
res = PACS[1].read_holding_registers(797,2,unit=2)
|
||||
print "Werte: %s" % _to_time(res.registers)
|
||||
|
||||
def _to_time_abs(reg):
|
||||
correction = (6*60*60 - 6*60 - 9) #21231 / 5h 53m 51s
|
||||
timestamp = _to_ulong(reg) + correction
|
||||
date = datetime.fromtimestamp(timestamp)
|
||||
return date
|
||||
|
||||
def _to_time_rel(reg):
|
||||
return _to_ulong(reg)/3600.0
|
||||
|
||||
def _to_ulong(reg):
|
||||
return (reg[0]*int(0xFFFF) + reg[1])
|
||||
|
||||
def _to_float(reg):
|
||||
tmp = int(reg[0]) << 16 | int(reg[1])
|
||||
s = struct.pack('=i', tmp)
|
||||
return struct.unpack('=f', s)
|
||||
|
||||
def close(PACS):
|
||||
### CLOSE ###
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ class Switch(Thread):
|
|||
# item = query.get() #block = True
|
||||
# query should be included in the result
|
||||
|
||||
item = self.query.get(block = True)
|
||||
item = None #self.query.get(block = True)
|
||||
|
||||
if self.source == MYSQL:
|
||||
result = database.loop(self.cursor, item)
|
||||
|
|
@ -74,8 +74,8 @@ class Switch(Thread):
|
|||
|
||||
#print 'PUT:\t%s' % result
|
||||
|
||||
self.queue.put(result)
|
||||
self.query.task_done()
|
||||
#self.queue.put(result)
|
||||
#self.query.task_done()
|
||||
if self.source == MYSQL:
|
||||
sleep(float(conf['mySQL_speed']))
|
||||
elif self.source == MODBUS:
|
||||
|
|
|
|||
11
src/test.py
11
src/test.py
|
|
@ -6,11 +6,22 @@ Created on 21.11.2013
|
|||
# import CANFilter
|
||||
# import Sym2Lib
|
||||
from Config.parser import config
|
||||
from Connector.switch import Switch, MODBUS
|
||||
from time import sleep
|
||||
|
||||
### LOAD CONFIG ###
|
||||
c = config()
|
||||
conf = c.readConf()
|
||||
|
||||
### Modbus ###
|
||||
sw = Switch(MODBUS)
|
||||
queue, query = sw.initialisiere()
|
||||
sw.run()
|
||||
print 'run'
|
||||
while True:
|
||||
query.put(1)
|
||||
sleep(0.5)
|
||||
|
||||
### Sym2Lib test ###
|
||||
# sym = "%s/%s" % (conf["config_dictionary"], conf["symfile"])
|
||||
# print Sym2Lib.get_DataFrameDict(sym)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue