prepared for modbus
This commit is contained in:
parent
149b702e05
commit
18b80015a8
6 changed files with 50 additions and 60 deletions
|
|
@ -4,7 +4,6 @@ Created on 15.11.2013
|
|||
@author: Philipp Rauch
|
||||
@version: 0.1
|
||||
'''
|
||||
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
from time import sleep
|
||||
|
|
@ -12,11 +11,10 @@ from config import Config
|
|||
|
||||
#import Module
|
||||
import database
|
||||
import modbus
|
||||
|
||||
MYSQL = 0
|
||||
CSV = 1
|
||||
XML = 2
|
||||
JSON = 3
|
||||
MODBUS = 1
|
||||
|
||||
### LOAD CONFIG ###
|
||||
c = Config()
|
||||
|
|
@ -33,7 +31,10 @@ class Switch(Thread):
|
|||
self.source = source
|
||||
|
||||
def initialisiere(self):
|
||||
self.cursor = database.setup(conf)
|
||||
if self.source == MYSQL:
|
||||
self.cursor = database.setup(conf)
|
||||
elif self.source == MODBUS:
|
||||
self.cursor = modbus.setup(conf)
|
||||
|
||||
### init Query ###
|
||||
self.query = Queue()
|
||||
|
|
@ -55,12 +56,18 @@ class Switch(Thread):
|
|||
# query should be included in the result
|
||||
|
||||
item = 'dc_labor/device/battery'
|
||||
result = database.loop(self.cursor, item)
|
||||
if self.source == MYSQL:
|
||||
result = database.loop(self.cursor, item)
|
||||
elif self.source == MODBUS:
|
||||
result = modbus.loop(self.cursor, item)
|
||||
|
||||
#print 'PUT:\t%s' % result
|
||||
|
||||
self.queue.put(result)
|
||||
sleep(float(conf['mySQL_speed']))
|
||||
if self.source == MYSQL:
|
||||
sleep(float(conf['mySQL_speed']))
|
||||
elif self.source == MODBUS:
|
||||
sleep(0.1)
|
||||
|
||||
def getItem(self, block = False):
|
||||
return self.queue.get(block)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue