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
|
@author: Philipp Rauch
|
||||||
'''
|
'''
|
||||||
from pymodbus.client.sync import ModbusTcpClient
|
from pymodbus.client.sync import ModbusTcpClient
|
||||||
|
from datetime import datetime
|
||||||
|
import struct
|
||||||
|
|
||||||
def setup(conf):
|
def setup(conf):
|
||||||
PACS = []
|
PACS = []
|
||||||
|
|
@ -28,9 +30,25 @@ def loop(PACS, item):
|
||||||
# ans = PAC[0].write_registers(213,(1,0),unit=2)
|
# ans = PAC[0].write_registers(213,(1,0),unit=2)
|
||||||
# print "Antwort: %s" % ans
|
# print "Antwort: %s" % ans
|
||||||
|
|
||||||
res = PACS[0].read_holding_registers(213,4,unit=2)
|
res = PACS[1].read_holding_registers(797,2,unit=2)
|
||||||
print "Werte: %s" % res.registers
|
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):
|
def close(PACS):
|
||||||
### CLOSE ###
|
### CLOSE ###
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class Switch(Thread):
|
||||||
# item = query.get() #block = True
|
# item = query.get() #block = True
|
||||||
# query should be included in the result
|
# query should be included in the result
|
||||||
|
|
||||||
item = self.query.get(block = True)
|
item = None #self.query.get(block = True)
|
||||||
|
|
||||||
if self.source == MYSQL:
|
if self.source == MYSQL:
|
||||||
result = database.loop(self.cursor, item)
|
result = database.loop(self.cursor, item)
|
||||||
|
|
@ -74,8 +74,8 @@ class Switch(Thread):
|
||||||
|
|
||||||
#print 'PUT:\t%s' % result
|
#print 'PUT:\t%s' % result
|
||||||
|
|
||||||
self.queue.put(result)
|
#self.queue.put(result)
|
||||||
self.query.task_done()
|
#self.query.task_done()
|
||||||
if self.source == MYSQL:
|
if self.source == MYSQL:
|
||||||
sleep(float(conf['mySQL_speed']))
|
sleep(float(conf['mySQL_speed']))
|
||||||
elif self.source == MODBUS:
|
elif self.source == MODBUS:
|
||||||
|
|
|
||||||
11
src/test.py
11
src/test.py
|
|
@ -6,11 +6,22 @@ Created on 21.11.2013
|
||||||
# import CANFilter
|
# import CANFilter
|
||||||
# import Sym2Lib
|
# import Sym2Lib
|
||||||
from Config.parser import config
|
from Config.parser import config
|
||||||
|
from Connector.switch import Switch, MODBUS
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
c = config()
|
c = config()
|
||||||
conf = c.readConf()
|
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 ###
|
### Sym2Lib test ###
|
||||||
# sym = "%s/%s" % (conf["config_dictionary"], conf["symfile"])
|
# sym = "%s/%s" % (conf["config_dictionary"], conf["symfile"])
|
||||||
# print Sym2Lib.get_DataFrameDict(sym)
|
# print Sym2Lib.get_DataFrameDict(sym)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue