umstrukturierung

This commit is contained in:
Philipp Rauch 2014-01-30 18:42:36 +01:00
parent 25e406ed8c
commit 98451284d7
14 changed files with 138 additions and 139 deletions

0
API/__init__.py Normal file
View file

View file

@ -5,7 +5,7 @@ Created on 29.01.2014
'''
from sys import stderr
from socket import gethostname
from config import Config
from Config.config import Config
from datetime import datetime
from flask import abort

View file

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Before After
Before After

View file

@ -8,7 +8,7 @@ Created on 24.10.2013
from datetime import datetime
from flask import Flask, jsonify, make_response, request
from socket import gethostname
from config import Config
from Config.config import Config
from ems import ems
from buffer import Buffer
@ -29,14 +29,14 @@ class Request(object):
self.id = req_id
def API_start():
api = API()
print 'API-Thread:\t%s\n' % api
def REST_start():
api = REST()
print 'REST-Thread:\t%s\n' % api
api.app.run(host = conf['flask_server'],
port = int(conf['flask_port']))
#debug = conf['flask_debug']
class API(object):
class REST(object):
def __init__(self):
self.app = Flask(__name__)

0
Config/__init__.py Normal file
View file

0
Swich/__init__.py Normal file
View file

View file

@ -1,41 +1,41 @@
'''
Created on 05.12.2013
@author: Philipp Rauch
'''
from pymodbus.client.sync import ModbusTcpClient
PAC01, PAC02, PAC03, PAC04 = None, None, None, None
def setup(conf):
### INITIALIZE ###
PAC01 = ModbusTcpClient('10.2.6.5')
PAC02 = ModbusTcpClient('10.2.6.6')
PAC03 = ModbusTcpClient('10.2.6.7')
PAC04 = ModbusTcpClient('10.2.6.8')
### CONNECT ###
PAC01.connect()
PAC02.connect()
PAC03.connect()
PAC04.connect()
def loop(cursor, item):
# PAC01.write_coil(213, 100,2)
# result = PAC01.read_coils(213,1,unit=2)
ans = PAC01.write_registers(213,(1,0),unit=2)
print "Antwort: %s" % ans
res = PAC01.read_holding_registers(213,4,unit=2)
print "Werte: %s" % res.registers
# print result.bits[0]
def close():
### CLOSE ###
PAC01.close()
PAC02.close()
PAC03.close()
PAC04.close()
'''
Created on 05.12.2013
@author: Philipp Rauch
'''
from pymodbus.client.sync import ModbusTcpClient
PAC01, PAC02, PAC03, PAC04 = None, None, None, None
def setup(conf):
### INITIALIZE ###
PAC01 = ModbusTcpClient('10.2.6.5')
PAC02 = ModbusTcpClient('10.2.6.6')
PAC03 = ModbusTcpClient('10.2.6.7')
PAC04 = ModbusTcpClient('10.2.6.8')
### CONNECT ###
PAC01.connect()
PAC02.connect()
PAC03.connect()
PAC04.connect()
def loop(cursor, item):
# PAC01.write_coil(213, 100,2)
# result = PAC01.read_coils(213,1,unit=2)
ans = PAC01.write_registers(213,(1,0),unit=2)
print "Antwort: %s" % ans
res = PAC01.read_holding_registers(213,4,unit=2)
print "Werte: %s" % res.registers
# print result.bits[0]
def close():
### CLOSE ###
PAC01.close()
PAC02.close()
PAC03.close()
PAC04.close()

View file

@ -1,82 +1,82 @@
'''
Created on 15.11.2013
@author: Philipp Rauch
@version: 0.1
'''
from threading import Thread
from Queue import Queue
from time import sleep
from config import Config
#import Module
import database
import modbus
MYSQL = 0
MODBUS = 1
### LOAD CONFIG ###
c = Config()
conf = c.readConf()
'''
TODO: comment :)
'''
class Switch(Thread):
def __init__(self, source = MYSQL):
Thread.__init__(self)
self.source = source
def initialisiere(self):
'''
initialize the swich with the given source and creates a queue and a query
it calls the setup method from the source module
@return: queue and query
'''
if self.source == MYSQL:
self.cursor = database.setup(conf)
elif self.source == MODBUS:
self.cursor = modbus.setup(conf)
### init Query ###
self.query = Queue()
if conf['config_debug']:
print '\tSWITCH-QUERY:\t', self.query
### init Queue ###
self.queue = Queue()
if conf['config_debug']:
print '\tSWITCH-QUEUE:\t', self.queue
return self.queue, self.query
def run(self):
'''
The loop method of the source module is called with a parameter from the query.
Its output is written to the queue.
'''
while True:
# Queue implementaion
# Queue contains the tablename for query
# item = query.get() #block = True
# query should be included in the result
item = self.query.get(block = True)
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)
self.query.task_done()
if self.source == MYSQL:
sleep(float(conf['mySQL_speed']))
elif self.source == MODBUS:
sleep(0.1)
'''
Created on 15.11.2013
@author: Philipp Rauch
@version: 0.1
'''
from threading import Thread
from Queue import Queue
from time import sleep
from Config.config import Config
#import Module
import database
import modbus
MYSQL = 0
MODBUS = 1
### LOAD CONFIG ###
c = Config()
conf = c.readConf()
'''
TODO: comment :)
'''
class Switch(Thread):
def __init__(self, source = MYSQL):
Thread.__init__(self)
self.source = source
def initialisiere(self):
'''
initialize the swich with the given source and creates a queue and a query
it calls the setup method from the source module
@return: queue and query
'''
if self.source == MYSQL:
self.cursor = database.setup(conf)
elif self.source == MODBUS:
self.cursor = modbus.setup(conf)
### init Query ###
self.query = Queue()
if conf['config_debug']:
print '\tSWITCH-QUERY:\t', self.query
### init Queue ###
self.queue = Queue()
if conf['config_debug']:
print '\tSWITCH-QUEUE:\t', self.queue
return self.queue, self.query
def run(self):
'''
The loop method of the source module is called with a parameter from the query.
Its output is written to the queue.
'''
while True:
# Queue implementaion
# Queue contains the tablename for query
# item = query.get() #block = True
# query should be included in the result
item = self.query.get(block = True)
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)
self.query.task_done()
if self.source == MYSQL:
sleep(float(conf['mySQL_speed']))
elif self.source == MODBUS:
sleep(0.1)

View file

@ -4,11 +4,10 @@ Created on 15.11.2013
@author: Philipp Rauch
@version: 0.02
'''
from threading import Thread
from switch import Switch, MYSQL
from config import Config
from time import sleep
#from API import Request
from threading import Thread
from Swich.switch import Switch, MYSQL
from Config.config import Config
#from API.service import Request
### LOAD CONFIG ###
c = Config()

View file

@ -3,13 +3,13 @@ Created on 29.01.2014
@author: Philipp Rauch
'''
from config import Config
from API import API_start
from CANFilter import CAN_start
from Config.config import Config
from API.service import REST_start
from CAN.Filter import CAN_start
### LOAD CONFIG ###
c = Config()
conf = c.readConf()
CAN_start(conf)
API_start()
REST_start()

View file

@ -5,7 +5,7 @@ Created on 21.11.2013
'''
# import CANFilter
# import Sym2Lib
from config import Config
from Config.config import Config
### LOAD CONFIG ###
c = Config()