Module laufen als Thread
*Thread für swich implementiert *Thread für API implementiert (noch nicht lauffähig) *Swich startet CANFilter
This commit is contained in:
parent
704e02385f
commit
f0686090ec
5 changed files with 120 additions and 107 deletions
44
scr/swich.py
44
scr/swich.py
|
|
@ -2,23 +2,26 @@
|
|||
Created on 15.11.2013
|
||||
|
||||
@author: Philipp Rauch
|
||||
@version: 0.01
|
||||
@version: 0.1
|
||||
'''
|
||||
|
||||
import MySQLdb
|
||||
import threading
|
||||
import Queue
|
||||
from CANFilter import CANFilter
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
from CANFilter import CANFilter
|
||||
from time import sleep
|
||||
#from MySQLdb import connect
|
||||
|
||||
MYSQL = 0
|
||||
CSV = 1
|
||||
XML = 2
|
||||
JSON = 3
|
||||
|
||||
class Swich(threading.Thread):
|
||||
class Swich(Thread):
|
||||
|
||||
_isInit = False
|
||||
|
||||
def __init__(self, source = MYSQL):
|
||||
threading.Thread.__init__(self)
|
||||
Thread.__init__(self)
|
||||
self.source = source
|
||||
|
||||
def __del__(self):
|
||||
|
|
@ -27,12 +30,19 @@ class Swich(threading.Thread):
|
|||
|
||||
def initialisiere(self):
|
||||
if self.source == MYSQL:
|
||||
_isInit = True
|
||||
|
||||
### start CAN ###
|
||||
self.CAN = CANFilter()
|
||||
self.CAN.start()
|
||||
|
||||
self.connection = MySQLdb.connect("url", "user", "password", "database_name")
|
||||
self.cursor = self.connection.cursor()
|
||||
self.queue = Queue.Queue()
|
||||
### connect to DB ###
|
||||
# self.connection = MySQLdb.connect("url", "user", "password", "database_name")
|
||||
# self.cursor = self.connection.cursor()
|
||||
|
||||
### init Queue ###
|
||||
self.queue = Queue()
|
||||
print 'SWICH:\t', self.queue
|
||||
return self.queue, self.CAN
|
||||
|
||||
elif self.source == CSV:
|
||||
|
|
@ -46,13 +56,19 @@ class Swich(threading.Thread):
|
|||
|
||||
else:
|
||||
return
|
||||
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
sql = 'SELECT * FROM %s ORDER BY timestamp DESC LIMIT 1'
|
||||
item = Swich.queue.get(block = True) #item is a string which names the table that will be returned (newest values)
|
||||
# item = Swich.queue.get(block = True)
|
||||
item = 'EMS-TEST'
|
||||
|
||||
print self.cursor.execute(sql % item)
|
||||
# data = self.cursor.execute(sql % item)
|
||||
self.setQueue(item)
|
||||
sleep(0.5)
|
||||
|
||||
def setQueue(self, item):
|
||||
self.queue.put(item)
|
||||
self.queue.put(item)
|
||||
|
||||
def getItem(self, block = False):
|
||||
return self.queue.get(block)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue