Ejemplo n.º 1
0
class BatMonTh(Thread):
    
    def __init__(self):
        Thread.__init__(self)
        self.count = 0
        self.voltage = 0
        self.state = "idle"
        self.batNb = int(input("Entrez le numéro de la batterie :"))
        self.fileName = ""
        self.com = BatMon()
        self.com.setPort('COM12')
        self.verrou = Lock()
        self.gui = Gui(self.verrou)
        self.start()
        self.gui.mainloop()

    def run(self):
        appRunning = True
        while (appRunning):
            self.voltage = 0
            if (self.state == "idle"):
                if (self.com.connect()):
                    if (self.com.getId()):
                        self.count = 0
                        self.state = "connected"
                        self.file = self.createFile()
                    else:
                        time.sleep(0.5)
                else:
                    time.sleep(0.5)
            else:
                data = self.com.getData()
                self.voltage = data[0]
                self.state = data[1]
                self.count += 1
                if (self.count > 32767):
                    self.count = -32768
                if (self.state == "idle"):
                    try:
                        self.file.close()
                    except:
                        self.fileName = ''
                elif ((self.state == "discharging") and (self.count%60==0)):
                    if (self.verrou.acquire(False)):
                        self.gui.addData(self.count, self.voltage)
                        self.verrrou.release()
                    else:
                        appRunning = False
                    pickle.dump(self.count, self.file)
                    pickle.dump(self.voltage, self.file)
            if (self.verrou.acquire(False)):
                self.gui.changeVoltage(self.voltage)
                self.gui.changeState(self.state)
                self.verrou.release()
            else:
                appRunning = False
        try:
            self.file.close()
        except:
            self.fileName = ''

    def createFile(self):
        fileNb = 0
        success = False
        while(not(success)):
            try:
                self.fileName = "Bat%02i-%03i.BDi" % (self.batNb, fileNb)
                open(self.fileName,'rb')
                fileNb += 1
            except:
                success = True
        newFile = open(self.fileName, 'wb')
        return newFile    
Ejemplo n.º 2
0
# -*- coding: ISO-8859-1 -*-
import numpy
from matplotlib import pyplot
from batteryMonitor import BatMon

batMon = BatMon()
batMon.setPort('COM12')
if (not (batMon.connect())):
    print('Impossible de se connecter au dispositif')
elif (not (batMon.getId())):
    print('Connecté au port, mais le dispositif ne répond pas')
else:
    print("Connecté au dispositif")
    tmp = batMon.getData()
    while (tmp[1] != 2):
        tmp = batMon.getData()
        print(tmp)
    print("Batterie détectée, la décharge commence")
    # crée le dictionnaire pour stocker les données
    data = {}
    count = 0
    data[count] = tmp
    voltage = [tmp[0]]
    while (tmp[1] != 1):
        tmp = batMon.getData()
        data[count] = tmp
        voltage.append(tmp[0])
        count = count + 1
        print(tmp)

    time = numpy.linspace(0, count, count + 1)
Ejemplo n.º 3
0
# -*- coding: ISO-8859-1 -*-
import numpy
from matplotlib import pyplot
from batteryMonitor import BatMon

batMon = BatMon()
batMon.setPort('COM12')
if (not(batMon.connect())):
    print('Impossible de se connecter au dispositif')
elif (not(batMon.getId())):
    print('Connecté au port, mais le dispositif ne répond pas')
else:
    print("Connecté au dispositif")
    tmp = batMon.getData()
    while (tmp[1] != 2):
        tmp = batMon.getData()
        print(tmp)
    print("Batterie détectée, la décharge commence")
    # crée le dictionnaire pour stocker les données
    data = {}
    count = 0
    data[count] = tmp
    voltage = [tmp[0]]
    while (tmp[1] != 1):
        tmp = batMon.getData()
        data[count] = tmp
        voltage.append(tmp[0])
        count = count+1
        print(tmp)

    time = numpy.linspace(0,count,count+1)
Ejemplo n.º 4
0
class BatMonTh(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.count = 0
        self.voltage = 0
        self.state = "idle"
        self.batNb = int(input("Entrez le numéro de la batterie :"))
        self.fileName = ""
        self.com = BatMon()
        self.com.setPort('COM12')
        self.verrou = Lock()
        self.gui = Gui(self.verrou)
        self.start()
        self.gui.mainloop()

    def run(self):
        appRunning = True
        while (appRunning):
            self.voltage = 0
            if (self.state == "idle"):
                if (self.com.connect()):
                    if (self.com.getId()):
                        self.count = 0
                        self.state = "connected"
                        self.file = self.createFile()
                    else:
                        time.sleep(0.5)
                else:
                    time.sleep(0.5)
            else:
                data = self.com.getData()
                self.voltage = data[0]
                self.state = data[1]
                self.count += 1
                if (self.count > 32767):
                    self.count = -32768
                if (self.state == "idle"):
                    try:
                        self.file.close()
                    except:
                        self.fileName = ''
                elif ((self.state == "discharging")
                      and (self.count % 60 == 0)):
                    if (self.verrou.acquire(False)):
                        self.gui.addData(self.count, self.voltage)
                        self.verrrou.release()
                    else:
                        appRunning = False
                    pickle.dump(self.count, self.file)
                    pickle.dump(self.voltage, self.file)
            if (self.verrou.acquire(False)):
                self.gui.changeVoltage(self.voltage)
                self.gui.changeState(self.state)
                self.verrou.release()
            else:
                appRunning = False
        try:
            self.file.close()
        except:
            self.fileName = ''

    def createFile(self):
        fileNb = 0
        success = False
        while (not (success)):
            try:
                self.fileName = "Bat%02i-%03i.BDi" % (self.batNb, fileNb)
                open(self.fileName, 'rb')
                fileNb += 1
            except:
                success = True
        newFile = open(self.fileName, 'wb')
        return newFile