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
|
|
@ -2,26 +2,28 @@
|
|||
Created on 13.11.2013
|
||||
|
||||
@author: Philipp Rauch
|
||||
@version: 0.02
|
||||
@version: 0.1
|
||||
'''
|
||||
|
||||
from CanMessage import CanMessage
|
||||
from CanSignal import CanSignal
|
||||
from PCan import PcanAdapter
|
||||
import datetime
|
||||
import time
|
||||
import threading
|
||||
#import MySQLdb
|
||||
from CanSignal import CanSignal
|
||||
from PCan import PcanAdapter
|
||||
from datetime import datetime
|
||||
from time import sleep
|
||||
from threading import Thread
|
||||
from Queue import Queue
|
||||
#from MySQLdb import connect
|
||||
|
||||
debug = False
|
||||
|
||||
class CANFilter(threading.Thread):
|
||||
class CANFilter(Thread):
|
||||
|
||||
battery_current, battery_voltage, battery_capacity, battery_timestamp, test = [], [], [], [], []
|
||||
battery_current, battery_voltage, battery_capacity, battery_timestamp, test = [], [], [], [], [] #create tmp lists
|
||||
|
||||
def __init__(self):
|
||||
print "INIT"
|
||||
threading.Thread.__init__(self)
|
||||
Thread.__init__(self)
|
||||
|
||||
self.queue = Queue()
|
||||
|
||||
self.pcan = PcanAdapter(PcanAdapter.Baudrate['250k'])
|
||||
self.pcan.initialize()
|
||||
|
|
@ -62,6 +64,8 @@ class CANFilter(threading.Thread):
|
|||
self.pcan.Messages['dc_charging'].addSignal( current )
|
||||
self.pcan.Messages['dc_charging'].addSignal( voltage )
|
||||
|
||||
return self.queue
|
||||
|
||||
#connection = MySQLdb.connect("url", "user", "passwort", "datenbankname")
|
||||
#cursor = connection.cursor()
|
||||
|
||||
|
|
@ -76,7 +80,7 @@ class CANFilter(threading.Thread):
|
|||
self.battery_current.append(self.pcan.Messages['dc_battery'].Signals['current'].GetData())
|
||||
self.battery_voltage.append(self.pcan.Messages['dc_battery'].Signals['voltage'].GetData())
|
||||
self.battery_capacity.append(self.pcan.Messages['dc_battery'].Signals['capacity'].GetData())
|
||||
self.battery_timestamp.append(datetime.datetime.now())
|
||||
self.battery_timestamp.append(datetime.now())
|
||||
|
||||
if len(self.battery_timestamp) == 100:
|
||||
if debug:
|
||||
|
|
@ -89,9 +93,11 @@ class CANFilter(threading.Thread):
|
|||
daten = [(tabelle, str(self.battery_timestamp[i]), str(self.battery_current[i]), str(self.battery_voltage[i]), str(self.battery_capacity[i])) for i in range(100)]
|
||||
sql = 'INSERT INTO %s VALUES(%s, %s, %s, %s)'
|
||||
|
||||
for i in daten:
|
||||
print sql % i
|
||||
self.queue.put(daten[0])
|
||||
|
||||
# for i in daten:
|
||||
# print sql % i
|
||||
# cursor.executemany(sql, daten)
|
||||
|
||||
del self.battery_current[:], self.battery_voltage[:], self.battery_capacity[:], self.battery_timestamp[:]
|
||||
time.sleep(0.01)
|
||||
del self.battery_current[:], self.battery_voltage[:], self.battery_capacity[:], self.battery_timestamp[:] #clear tmp lists
|
||||
sleep(0.01)
|
||||
Loading…
Add table
Add a link
Reference in a new issue