umstrukturierung
This commit is contained in:
parent
25e406ed8c
commit
98451284d7
14 changed files with 138 additions and 139 deletions
0
API/__init__.py
Normal file
0
API/__init__.py
Normal file
|
|
@ -5,7 +5,7 @@ Created on 29.01.2014
|
||||||
'''
|
'''
|
||||||
from sys import stderr
|
from sys import stderr
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import abort
|
from flask import abort
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
|
@ -8,7 +8,7 @@ Created on 24.10.2013
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from flask import Flask, jsonify, make_response, request
|
from flask import Flask, jsonify, make_response, request
|
||||||
from socket import gethostname
|
from socket import gethostname
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
from ems import ems
|
from ems import ems
|
||||||
from buffer import Buffer
|
from buffer import Buffer
|
||||||
|
|
||||||
|
|
@ -29,14 +29,14 @@ class Request(object):
|
||||||
self.id = req_id
|
self.id = req_id
|
||||||
|
|
||||||
|
|
||||||
def API_start():
|
def REST_start():
|
||||||
api = API()
|
api = REST()
|
||||||
print 'API-Thread:\t%s\n' % api
|
print 'REST-Thread:\t%s\n' % api
|
||||||
api.app.run(host = conf['flask_server'],
|
api.app.run(host = conf['flask_server'],
|
||||||
port = int(conf['flask_port']))
|
port = int(conf['flask_port']))
|
||||||
#debug = conf['flask_debug']
|
#debug = conf['flask_debug']
|
||||||
|
|
||||||
class API(object):
|
class REST(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.app = Flask(__name__)
|
self.app = Flask(__name__)
|
||||||
0
Config/__init__.py
Normal file
0
Config/__init__.py
Normal file
0
Swich/__init__.py
Normal file
0
Swich/__init__.py
Normal file
|
|
@ -1,41 +1,41 @@
|
||||||
'''
|
'''
|
||||||
Created on 05.12.2013
|
Created on 05.12.2013
|
||||||
|
|
||||||
@author: Philipp Rauch
|
@author: Philipp Rauch
|
||||||
'''
|
'''
|
||||||
from pymodbus.client.sync import ModbusTcpClient
|
from pymodbus.client.sync import ModbusTcpClient
|
||||||
|
|
||||||
PAC01, PAC02, PAC03, PAC04 = None, None, None, None
|
PAC01, PAC02, PAC03, PAC04 = None, None, None, None
|
||||||
|
|
||||||
def setup(conf):
|
def setup(conf):
|
||||||
### INITIALIZE ###
|
### INITIALIZE ###
|
||||||
PAC01 = ModbusTcpClient('10.2.6.5')
|
PAC01 = ModbusTcpClient('10.2.6.5')
|
||||||
PAC02 = ModbusTcpClient('10.2.6.6')
|
PAC02 = ModbusTcpClient('10.2.6.6')
|
||||||
PAC03 = ModbusTcpClient('10.2.6.7')
|
PAC03 = ModbusTcpClient('10.2.6.7')
|
||||||
PAC04 = ModbusTcpClient('10.2.6.8')
|
PAC04 = ModbusTcpClient('10.2.6.8')
|
||||||
|
|
||||||
### CONNECT ###
|
### CONNECT ###
|
||||||
PAC01.connect()
|
PAC01.connect()
|
||||||
PAC02.connect()
|
PAC02.connect()
|
||||||
PAC03.connect()
|
PAC03.connect()
|
||||||
PAC04.connect()
|
PAC04.connect()
|
||||||
|
|
||||||
|
|
||||||
def loop(cursor, item):
|
def loop(cursor, item):
|
||||||
# PAC01.write_coil(213, 100,2)
|
# PAC01.write_coil(213, 100,2)
|
||||||
# result = PAC01.read_coils(213,1,unit=2)
|
# result = PAC01.read_coils(213,1,unit=2)
|
||||||
|
|
||||||
ans = PAC01.write_registers(213,(1,0),unit=2)
|
ans = PAC01.write_registers(213,(1,0),unit=2)
|
||||||
print "Antwort: %s" % ans
|
print "Antwort: %s" % ans
|
||||||
|
|
||||||
res = PAC01.read_holding_registers(213,4,unit=2)
|
res = PAC01.read_holding_registers(213,4,unit=2)
|
||||||
print "Werte: %s" % res.registers
|
print "Werte: %s" % res.registers
|
||||||
|
|
||||||
# print result.bits[0]
|
# print result.bits[0]
|
||||||
|
|
||||||
def close():
|
def close():
|
||||||
### CLOSE ###
|
### CLOSE ###
|
||||||
PAC01.close()
|
PAC01.close()
|
||||||
PAC02.close()
|
PAC02.close()
|
||||||
PAC03.close()
|
PAC03.close()
|
||||||
PAC04.close()
|
PAC04.close()
|
||||||
|
|
@ -1,82 +1,82 @@
|
||||||
'''
|
'''
|
||||||
Created on 15.11.2013
|
Created on 15.11.2013
|
||||||
|
|
||||||
@author: Philipp Rauch
|
@author: Philipp Rauch
|
||||||
@version: 0.1
|
@version: 0.1
|
||||||
'''
|
'''
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from Queue import Queue
|
from Queue import Queue
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
|
|
||||||
#import Module
|
#import Module
|
||||||
import database
|
import database
|
||||||
import modbus
|
import modbus
|
||||||
|
|
||||||
MYSQL = 0
|
MYSQL = 0
|
||||||
MODBUS = 1
|
MODBUS = 1
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
c = Config()
|
c = Config()
|
||||||
conf = c.readConf()
|
conf = c.readConf()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
TODO: comment :)
|
TODO: comment :)
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class Switch(Thread):
|
class Switch(Thread):
|
||||||
|
|
||||||
def __init__(self, source = MYSQL):
|
def __init__(self, source = MYSQL):
|
||||||
Thread.__init__(self)
|
Thread.__init__(self)
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
def initialisiere(self):
|
def initialisiere(self):
|
||||||
'''
|
'''
|
||||||
initialize the swich with the given source and creates a queue and a query
|
initialize the swich with the given source and creates a queue and a query
|
||||||
it calls the setup method from the source module
|
it calls the setup method from the source module
|
||||||
|
|
||||||
@return: queue and query
|
@return: queue and query
|
||||||
'''
|
'''
|
||||||
if self.source == MYSQL:
|
if self.source == MYSQL:
|
||||||
self.cursor = database.setup(conf)
|
self.cursor = database.setup(conf)
|
||||||
elif self.source == MODBUS:
|
elif self.source == MODBUS:
|
||||||
self.cursor = modbus.setup(conf)
|
self.cursor = modbus.setup(conf)
|
||||||
|
|
||||||
### init Query ###
|
### init Query ###
|
||||||
self.query = Queue()
|
self.query = Queue()
|
||||||
if conf['config_debug']:
|
if conf['config_debug']:
|
||||||
print '\tSWITCH-QUERY:\t', self.query
|
print '\tSWITCH-QUERY:\t', self.query
|
||||||
|
|
||||||
### init Queue ###
|
### init Queue ###
|
||||||
self.queue = Queue()
|
self.queue = Queue()
|
||||||
if conf['config_debug']:
|
if conf['config_debug']:
|
||||||
print '\tSWITCH-QUEUE:\t', self.queue
|
print '\tSWITCH-QUEUE:\t', self.queue
|
||||||
|
|
||||||
return self.queue, self.query
|
return self.queue, self.query
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
'''
|
'''
|
||||||
The loop method of the source module is called with a parameter from the query.
|
The loop method of the source module is called with a parameter from the query.
|
||||||
Its output is written to the queue.
|
Its output is written to the queue.
|
||||||
'''
|
'''
|
||||||
while True:
|
while True:
|
||||||
# Queue implementaion
|
# Queue implementaion
|
||||||
# Queue contains the tablename for query
|
# Queue contains the tablename for query
|
||||||
# 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 = 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)
|
||||||
elif self.source == MODBUS:
|
elif self.source == MODBUS:
|
||||||
result = modbus.loop(self.cursor, item)
|
result = modbus.loop(self.cursor, item)
|
||||||
|
|
||||||
#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:
|
||||||
sleep(0.1)
|
sleep(0.1)
|
||||||
|
|
@ -4,11 +4,10 @@ Created on 15.11.2013
|
||||||
@author: Philipp Rauch
|
@author: Philipp Rauch
|
||||||
@version: 0.02
|
@version: 0.02
|
||||||
'''
|
'''
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from switch import Switch, MYSQL
|
from Swich.switch import Switch, MYSQL
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
from time import sleep
|
#from API.service import Request
|
||||||
#from API import Request
|
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
c = Config()
|
c = Config()
|
||||||
|
|
|
||||||
|
|
@ -3,13 +3,13 @@ Created on 29.01.2014
|
||||||
|
|
||||||
@author: Philipp Rauch
|
@author: Philipp Rauch
|
||||||
'''
|
'''
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
from API import API_start
|
from API.service import REST_start
|
||||||
from CANFilter import CAN_start
|
from CAN.Filter import CAN_start
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
c = Config()
|
c = Config()
|
||||||
conf = c.readConf()
|
conf = c.readConf()
|
||||||
|
|
||||||
CAN_start(conf)
|
CAN_start(conf)
|
||||||
API_start()
|
REST_start()
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ Created on 21.11.2013
|
||||||
'''
|
'''
|
||||||
# import CANFilter
|
# import CANFilter
|
||||||
# import Sym2Lib
|
# import Sym2Lib
|
||||||
from config import Config
|
from Config.config import Config
|
||||||
|
|
||||||
### LOAD CONFIG ###
|
### LOAD CONFIG ###
|
||||||
c = Config()
|
c = Config()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue