def btStop_clicked(self): server.playmp3(self.linkFile) server.serverMain.sentStop2AllClient() self.ctimer.stop() print("form waiting : Dung khan cap") self.form.close()
def retranslateUi(self, welcomeForm): _translate = QtCore.QCoreApplication.translate welcomeForm.setWindowTitle(_translate("welcomeForm", "Form")) self.frame.clicked.connect(self.frame_click) self.btExit.clicked.connect(self.btnExit_click) linkFile = server.folderMP3 + "001.mp3" server.playmp3(linkFile) self.ctimer = QTimer(self.frame) self.ctimer.timeout.connect(self.getdataFromClient) self.ctimer.start(300)
def setEvent(self): self.tbInput.clicked.connect(self.tbInput_click) self.linkFile = server.folderMP3 + "002.mp3" server.playmp3(self.linkFile) #lock de dong bo thread self.threadLock = threading.Lock() self.isRun = True self.isRunRFID = True self.ctimer = QTimer(self.frame) self.ctimer.timeout.connect(self.checkScanOK) self.ctimer.start(10) t1 = threading.Thread(target=self.runThreadSensor) t1.start() """
def btNext_click(self): linkFileMP3 = server.folderMP3 + "007.mp3" server.playmp3(linkFileMP3) #cho luong thuc hien cong viec dong tu lan dau self.window = QtWidgets.QMainWindow() self.ui = Ui_SV_mainDisplay() self.ui.setupUi(self.window) self.window.show() if server.isFullSceen: self.window.showFullScreen() #dong form này lại---dong tu lan dau dong ca 2 ban server.tuTraiPhai = 'A' # dong ca 2 ben tu server.dongMoTuFunction(0, 0) self.SVChonClient.close()
def setEvent(self): server.statusVanHanh = 41 # da bat form bao duong linkFile = server.folderMP3 + "017.mp3" server.playmp3(linkFile) print("close tu left start") #lb tu dong: 1-7 self.listlb = [] self.listlb.append(self.lbTempIn) self.listlb.append(self.lbTempOut) self.listlb.append(self.lbCoichip) self.listlb.append(self.lbQuatGio) self.listlb.append(self.lbDenThap) self.listlb.append(self.lbCBChayTrong) self.listlb.append(self.lbCBChayNgoai) self.listSoundServer = [ "030", "031", "035", "036", "037", "038", "039" ] self.listSound = [ "030", "031", "032", "033", "034", "035", "038", "039", "040", "040", "040", "041", "042", "043" ] self.listdata2Ar = [ b'\x01', b'\x02', b'\x06', b'\x07', b'\x08', b'\x09', b'\x0a' ] self.caseBD = 0 server.caseBD = 0 self.flagFirst = True #dong tat ca cac tu truoc khi bao duong server.tuTraiPhai = 'A' server.dongMoTuFunction(0, 1) for lb in self.listlb: lb.hide() self.btThoat.clicked.connect(self.btExit_click) self.ctimer = QTimer(self.frame) self.ctimer.timeout.connect(self.checkTimer) self.ctimer.start(400) self.Tu = server.numClientLeft self.statusTu = 2 # 2 ben trai 1 ben phai 0 master if self.Tu == 0: #ko co tu ben trai self.Tu = server.numClientRight self.statusTu = 1 # 2 ben trai 1 ben phai 0 master
def checkTimer(self): if self.flagFirst: if server.serverMain.checkAllTuIsClosed() == False: return self.flagFirst = False for i in range(1, server.numClientLeft + 1): nameTu = "Left_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd\x00') self.btTiepTuc.clicked.connect(self.btTiepTuc_click) try: #timer này để check xem các client có bấm tiếp tục hay ko if server.caseBD > self.caseBD: self.btTiepTuc_click() if self.caseBD == 1 or self.caseBD == 2 or ( self.caseBD >= 6 and self.Tu == 0 and self.statusTu == 0): #bao duong tren master if uart.caseBDIsACK == 0: self.lbValue.setText("Waiting") elif uart.caseBDIsACK == 1: self.lbValue.setText("ERROR") self.listlb[self.caseBD - 1].setStyleSheet("color:#FF0000") elif uart.caseBDIsACK == 2: self.lbValue.setText("PASS") self.listlb[self.caseBD - 1].setStyleSheet("color:#00FF00") #check hoan thanh hay chua neu hoan thanh roi thi bao loa if server.checkBDok and self.caseBD >= 5: #thong bao kiem tra hoan tat linkFile = server.folderMP3 + "049.mp3" server.playmp3(linkFile) server.checkBDok = False except Exception as e: print("ERROR in BaoDuong checkTimer", str(e)) self.btExit_click() if server.statusVanHanh == 42: # ket thuc frm bao duong self.btExit_click() print("Ket thuc qua trinh bao duong PC sent to client")
def btExit_click(self): self.ctimer.stop() #Kết thúc quá trình bảo dưỡng hệ thống. linkFile = server.folderMP3 + "050.mp3" server.playmp3(linkFile) server.caseBD = 0 for i in range(1, server.numClientLeft + 1): nameTu = "Left_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd\xff') for i in range(1, server.numClientRight + 1): nameTu = "Right_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd\xff') uart.sentDataRandom(b'\xbd\xbd', b'\x1f\x00\x00\x00\x00\x00\x00\x00') time.sleep(0.5) uart.sentDataRandom(b'\xbd\xbd', b'\xff\x00\x00\x00\x00\x00\x00\x00') uart.caseBDIsACK = 0 server.statusVanHanh = 0 self.BaoDuongServer.close()
def checkDone(self): #print("check Done -- timeout--",server.isWaiting) self.NumWaiting += 1 if self.NumWaiting > (5000 / self.Gaptimer ): self.frameWaiting.setStyleSheet("#frameWaiting{background-image: url(:/images/waiting3.jpg);}") elif self.NumWaiting > (3000 / self.Gaptimer): self.frameWaiting.setStyleSheet("#frameWaiting{background-image: url(:/images/waiting2.jpg);}") elif self.NumWaiting > (1000 / self.Gaptimer): self.frameWaiting.setStyleSheet("#frameWaiting{background-image: url(:/images/waiting1.jpg);}") else: self.frameWaiting.setStyleSheet("#frameWaiting{background-image: url(:/images/waiting0.jpg);}") if server.isFlag2906 == False or self.NumWaiting < (2000 / self.Gaptimer ) : #time out toi da 2s return time.sleep(0.01) #phat hien qua dong he thong dung khan cap if server.serverMain.checkQuaDong() : self.linkFile = server.folderMP3 + "018.mp3" print("form waiting : Bao ve chong ket") self.btStop_clicked() return if server.isWaiting == 0 : linkFile = server.folderMP3 + "003.mp3" server.playmp3(linkFile) print("check Done isWaiting ",server.isWaiting , server.haveSucoClient) self.ctimer.stop() self.form.close() return elif server.isWaiting == 2: print(" timer check dung khan cap ",server.isWaiting) if server.statusSuCo == 1: self.linkFile = server.folderMP3 + "007_1.mp3" elif server.statusSuCo == 4: self.linkFile = server.folderMP3 + "007_2.mp3" self.btStop_clicked() return if server.haveSucoClient == True: print("form waiting : co su co") self.btStop_clicked() return #trong che do thong gio if server.numThongGio == -3 : flagDoneThongGio = True for tu in server.dataReceivedSer: if server.dataReceivedSer[tu].statusMotor != 7 :# check cac tu co deu dong khong flagDoneThongGio = False break if flagDoneThongGio : server.threadLock.acquire() if server.isWaiting == 1:# thoat do mo thanh cong ko co dung khan cap server.isWaiting = 0 server.serverMain.sentWaiting2AllClient() server.threadLock.release() self.ctimer.stop() self.form.close()
def showTemp(self): #try: _date = strftime("%H:%M:%S %A,%d/%m/%Y") minitue = int(strftime("%M")) sec = int(strftime("%S")) if minitue % 10 == 0: if self.saveLog: self.saveLog = False server.saveNhietDoDoAm() else: self.saveLog = True if sec % 1 == 0: server.serverMain.sendTempOut() #neu dang trong che do bao duong ko lam gi luon return luon #Kiem tra den thap sent to Arduino to status of server if server.isWaiting == 2 or server.isWaiting == 3 or server.isWaiting == 1: #Dung khan cap bao den vang uart.DataCamBien[4] = 0x32 uart.sentCambien() elif server.isWaiting == 0: # hoat dong binh thuong bao den xanh uart.DataCamBien[4] = 0x31 uart.sentCambien() if server.caseBD > 0: return self.lbHumiInValue.setText(str(uart.dataReceved.humiIn)) self.lbTempInValue.setText(str(uart.dataReceved.tempIn)) self.lbTempOutValue.setText(str(uart.dataReceved.tempOut)) self.lbHumiOutValue.setText(str(uart.dataReceved.humiOut)) tuActive = server.tuActive if tuActive[0] == 'L' or tuActive[ 0] == 'R': #hien thi tu nao dang mo va thong bao nguoi vao ra if server.dataReceivedSer[tuActive].statusMotor == 2: self.lbstatusMotor.setText('Giá ' + str(server.converNameTu(tuActive)) + " Mở") self.lbSoNguoi.setText( str(server.dataReceivedSer[tuActive].numPersonIn)) elif server.dataReceivedSer[tuActive].statusMotor == 4: self.lbstatusMotor.setText("Đóng") self.lbSoNguoi.setText("") self.lbKhoangCach.setText( str(server.dataReceivedSer[tuActive].distanceSen_1)) else: #neu ko co tu nao dang mo thi setText bang Dong or Dung self.lbKhoangCach.setText("") self.lbSoNguoi.setText("") self.lbWarning.setText("") self.lbstatusMotor.setText("Đóng") if server.isWaiting == 2: # dung khan cap self.lbstatusMotor.setText("Dừng") #thong bao co nguoi vao tu tuHumen, isHumenIn, numHumen = server.serverMain.checkHumen() if isHumenIn: #co nguoi vao tu self.linkFile = server.folderMP3 + "009.mp3" server.playmp3(self.linkFile) self.lbSoNguoi.setText(str(numHumen)) self.lbstatusMotor.setText(tuHumen) #check su co xem có sự cố cháy ko nếu có sự cố cháy thì chỉ hiện sự cố cháy thôi rồi return server.serverMain.checkSuCo(False) if server.statusSuCo == 0: # khong co su co thi reset form self.isShowSuCoForm = False if server.arraySuCo[1] != '0' or server.arraySuCo[ 2] != '0': # su co co chay if self.isShowSuCoForm == False: if server.arraySuCo[1] != '0': #phat hien chay trong tu --> mo tu bi chay self.linkFile = server.folderMP3 + "010.mp3" server.playmp3(self.linkFile) if server.arraySuCo[1][ 0] == 'M': # mo 2 tu gan master nhat Left_1 Right_1 server.tuTraiPhai = 'A' server.dongMoTuFunction(4, 'All_1') elif server.arraySuCo[1][0] == 'L' or server.arraySuCo[1][ 0] == 'R': server.tuTraiPhai = server.arraySuCo[1][0] server.dongMoTuFunction(3, server.arraySuCo[1]) else: #phat hien chay ngoai tu -> dong tat ca cac tu self.linkFile = server.folderMP3 + "011.mp3" server.playmp3(self.linkFile) server.tuTraiPhai = 'A' server.dongMoTuFunction(0, 1) self.isShowSuCoForm = True self.callSuCoForm() return #dang van hanh ma co vat can thi hien form su co canh bao vat can if server.isWaiting == 3 and (server.statusSuCo == 1 or server.statusSuCo == 4): if self.isShowSuCoForm == False: self.isShowSuCoForm = True self.callSuCoForm() return if server.isWaiting != 3 or server.statusSuCo != 5: self.isShowFormKhoaDC = False if server.isWaiting == 3 and server.statusSuCo == 5: if self.isShowFormKhoaDC == False: self.isShowFormKhoaDC = True self.callFormKhoaDC() return #yeu cau dong mo tu va khong co nguoi trong tu if server.isWaiting == 0 or server.isWaiting == 2: self.isShowWaitForm = False elif server.isWaiting == 1: if self.isShowWaitForm == False: self.isShowWaitForm = True self.callWaitingForm() '''phan nay kiem tra thong gio timer thuc thi thong gio''' #check thong gio co bat hay khong if server.numThongGio >= 1: server.numThongGio = -2 self.btThongGio_click() if server.executeThongGio == 0: # thong gio dang khong thuc thi dateH = int(strftime("%H")) dateM = int(strftime("%M")) timeThongGio = uart.dataAllJsonConfig["timeThongGio"] timeSplit = timeThongGio.split(':') if dateH == int(timeSplit[0]) and dateM == int( timeSplit[1] ) and timeSplit[3] == '1': # co kich hoat ham autoThongGio print("Mo thong gio tu dong") self.isPressThongGio = False #thuc hien tu dong self.btThongGio_click() # thuc hien chuc nang mo thong gio server.countThongGio = int(timeSplit[2]) * 60 elif server.executeThongGio == 1: #che do thong gio dang mo server.countThongGio -= 1 #tang so giay thong gio dang mo len 1 if server.countThongGio <= 0 and self.isPressThongGio == False: #chi tu dong tat khi tu dong bat, khi bat bang tay ko tu tat thong gio self.btThongGio_click( ) # neu het thoi gian thong gio tat che do thong gio if server.numThongGio == -3: self.btThongGio.setText("Tắt\nThông gió") elif server.numThongGio == 0: self.isPressThongGio = True self.btThongGio.setText("Thông gió") '''phan kiem tra PC --> master bat tat dieu hoa''' if server.statusVanHanh == 0x34: #DieuKhienDieuHoa self.callDieuHoaForm() elif server.statusVanHanh == 40: # bat che do bao duong self.callBaoDuongForm()
def btSave_click(self): if (self.btClickTimer): return else: self.buttonTimer() server.threadLock.acquire() if server.numClientLeft < self.numLeft: "tang so client ben trai len" for i in range(server.numClientLeft + 1, self.numLeft + 1): tu = "Left_" + str(i) server.arrIPArrdressLeft[tu] = uart.dataAllJsonConfig[ "IPLeft"][tu] server.dataReceivedSer[tu] = uart.DataInforSer() server.dataSent2Client[tu] = server.DataSent2Client() server.playmp3(server.folderMP3 + "045.mp3") print('them tu ben trai') elif server.numClientLeft > self.numLeft: "giam so client di" for i in range(self.numLeft + 1, server.numClientLeft + 1): tu = "Left_" + str(i) server.allConnection[tu].send(b'NG') server.allConnection[tu].close() del server.allConnection[tu] del server.arrIPArrdressLeft[tu] del server.dataReceivedSer[tu] del server.dataSent2Client[tu] server.playmp3(server.folderMP3 + "044.mp3") print('xoa tu ben trai') if server.numClientRight < self.numRight: "tang so client ben phai len" for i in range(server.numClientRight + 1, self.numRight + 1): tu = "Right_" + str(i) server.arrIPArrdressRight[tu] = uart.dataAllJsonConfig[ "IPRight"][tu] server.dataReceivedSer[tu] = uart.DataInforSer() server.dataSent2Client[tu] = server.DataSent2Client() print('Them tu ben phai') server.playmp3(server.folderMP3 + "047.mp3") elif server.numClientRight > self.numRight: "giam so client ben phai" for i in range(self.numRight + 1, server.numClientRight + 1): tu = "Right_" + str(i) server.allConnection[tu].send(b'NG') server.allConnection[tu].close() del server.allConnection[tu] del server.arrIPArrdressLeft[tu] del server.dataReceivedSer[tu] del server.dataSent2Client[tu] print('Xoa tu ben phai') server.playmp3(server.folderMP3 + "046.mp3") server.numClientLeft = self.numLeft uart.dataAllJsonConfig["IPLeft"]["numLeftActive"] = self.numLeft server.numClientRight = self.numRight uart.dataAllJsonConfig["IPRight"]["numRightActive"] = self.numRight uart.saveConfig() server.tuOpenedLeft = "0" server.tuOpenedRight = '0' server.tuActive = '0' server.threadLock.release() dialog = MSG_Dialog() dialog.exec_()
def btTiepTuc_click(self): #khi kiem tra xong het 1 tu if self.caseBD == 14 and self.Tu > 0: self.caseBD = 4 server.caseBD = 4 self.Tu -= 1 if self.Tu == 0: if self.statusTu == 2: self.statusTu -= 1 self.Tu = server.numClientRight #kiem tra xong tu ben trai chuyen sang tu ben phai elif self.statusTu == 1: self.statusTu -= 1 self.caseBD = 2 server.caseBD = 2 self.caseBD += 1 server.caseBD = self.caseBD if self.Tu == 0 and self.caseBD >= 8: linkFile = server.folderMP3 + "050.mp3" server.playmp3(linkFile) return linkFile = server.folderMP3 + self.listSound[self.caseBD - 1] + ".mp3" #truong hop kiem tra tự động if self.caseBD == 1 or self.caseBD == 2: # 2 case kiem tra tự động cho cac client va sever self.listlb[self.caseBD - 1].show() data = struct.pack('B', self.caseBD) for i in range(1, server.numClientLeft + 1): nameTu = "Left_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) for i in range(1, server.numClientRight + 1): nameTu = "Right_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) uart.caseBDIsACK = 0 uart.sentDataRandom(b'\xbd\xbd', b'\x1f\x00\x00\x00\x00\x00\x00\x00') time.sleep(0.5) uart.sentDataRandom(b'\xbd\xbd', data + b'\x00\x00\x00\x00\x00\x00\x00') if self.caseBD == 3 or self.caseBD == 4 and self.Tu > 0: data = struct.pack('B', self.caseBD) for i in range(1, server.numClientLeft + 1): nameTu = "Left_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) for i in range(1, server.numClientRight + 1): nameTu = "Right_" + str(i) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) if self.caseBD == 5 and self.Tu > 0: #sent mo tu ngoai cung if self.statusTu == 2: firstNameTu = "Left_" else: firstNameTu = "Right_" nameTu = firstNameTu + str(self.Tu) server.tuTraiPhai = nameTu[0] server.dongMoTuFunction(3, nameTu) numInLoop = 0 while server.dataReceivedSer[nameTu].statusMotor != 2: numInLoop += 1 time.sleep(0.1) if numInLoop > 100: print("Tu eo biet da duoc mo hay chua time out mo tu") break pass print(" tu da mo xong") server.playmp3(linkFile) time.sleep(2) data = struct.pack('B', self.caseBD) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) return if self.caseBD >= 5 and self.Tu > 0: data = struct.pack('B', self.caseBD) if self.statusTu == 2: firstNameTu = "Left_" else: firstNameTu = "Right_" nameTu = firstNameTu + str(self.Tu) server.serverMain.sendMes2Client(nameTu, b'\xbd\xbd' + data) if self.Tu == 0: #check cac test khac co pass hay ko if self.caseBD == 2 or self.caseBD == 3 or self.caseBD == 7 and uart.caseBDIsACK == 1: self.listlb[self.caseBD - 2].setStyleSheet("color:#FF0000") linkFile = server.folderMP3 + self.listSoundServer[self.caseBD - 1] + ".mp3" if self.listSoundServer[self.caseBD - 1] == '037': server.playmp3(linkFile) time.sleep(2) self.listlb[self.caseBD - 1].show() uart.caseBDIsACK = 0 uart.sentDataRandom(b'\xbd\xbd', b'\x1f\x00\x00\x00\x00\x00\x00\x00') time.sleep(0.5) uart.sentDataRandom( b'\xbd\xbd', self.listdata2Ar[self.caseBD - 1] + b'\x00\x00\x00\x00\x00\x00\x00') server.playmp3(linkFile)