コード例 #1
0
 def on_cmdIniciar2_clicked(self):
     print("Iniciar")
     if self.check1.checkState == QtCore.Qt.Checked:
         print("hola")
         #BCmb.runClient('raspberrypi.local', 1)
     if self.check2.checkState == QtCore.Qt.Checked:
         BCmb.runClient('raspberrypi.local', 2)
コード例 #2
0
ファイル: windowch2.1.py プロジェクト: fmbi1984/DitsaNetApp
    def on_bttnDoneClicked(self):
        self.uncheck_check()

        for j in range(2, len(self.newlist), 4):
            if self.newlist[j] == self.data1:
                self.index1 = j - 2
                print("indx1:", j - 2)
            elif self.newlist[j] == self.data2:
                self.index2 = j + 2
                print("indx2:", j + 2)
                break

        self.addrs.clear()
        self.loadProg = self.newlist[self.index1:self.index2]
        for i in range(3, len(self.loadProg), 4):
            addr = self.loadProg[i].split('A=')
            self.addrs.append(addr[1])

        print("loadProg:", self.loadProg)
        print("addr:", self.addrs)
        self.loadProg.clear()
        #for i in range(2,len(self.newlist[self.index1:self.index2]),4):

        print("check:", len(self.check))
        print("espera que se carguen todos los programas...")
        ##realizar un len de cuantos dispositivos seran ejecutados y sacar addrs

        for i in range(len(self.check)):
            print("valueAddr:", self.addrs[i])

            BCmb.writeProgramClient(useHostname, self.addrs[i],
                                    self.programJson)
コード例 #3
0
ファイル: runmodule.py プロジェクト: fmbi1984/DitsaNetApp
    def btnOk(self):
        print("btnOkRun")
        #----------------------------- Detiene thread -----------------------------#
        #time.sleep(0.5)
        #self.parent.threadData(False)
        #---------------------------- Extrae valor Addr ---------------------------#
        self.uncheck_check()
        self.addrs.clear()

        if len(self.loadProg) != 0:
            for i in range(3, len(self.loadProg), 4):
                addr = self.loadProg[i].split('A=')
                self.addrs.append(addr[1])

            self.loadProg.clear()
            self.textEdit.clear()
            #---------------------------- Envia comando run ---------------------------#
            self.chtext("msg", "None")
            for j in range(len(useHostname)):
                section = self.parent.tempAddr[j]
                for i in range(len(section)):
                    for k in range(len(self.addrs)):
                        if section[i] == self.addrs[k]:

                            if int(section[i]) > 16:
                                print("section:", section[i])
                                print("i:", i + 1)
                                x = BCmb.runClient(useHostname[j], usePort[j],
                                                   i + 1)

                            else:
                                x = BCmb.runClient(useHostname[j], usePort[j],
                                                   int(self.addrs[k]))
                                #time.sleep(0.3)#sujeto a cambios

                            print("x:", x)
                            if x != None:
                                if x == 'PASS,RUN':
                                    self.chtext(x, self.addrs[k])

                                else:
                                    self.chtext(x, self.addrs[k])
                                    self.flagFail = True

                            else:
                                self.chtext('None', self.addrs[k])
                                self.flagFail = True

            if self.flagFail != True:
                time.sleep(3)
                self.close()
            #solo falta realizar pruebas con comunicacion
        else:
            if self.flagFail != True:
                time.sleep(3)
                self.close()
コード例 #4
0
	def valueData(self):
		print("VALUEDATA")
		shared.lock_client.acquire()

		for j in range(len(useHostname)):
			memoryData = BCmb.memoryDataClient(useHostname[j],usePort[j])
			#time.sleep(0.3)
			if memoryData!= None:  #Tiene comm con server
				addr_list = self.tempAddr[j]
				for i in range(len(addr_list)):
					address = int(addr_list[i])
	
					TempData = memoryData[i].split(',')
					#print("TempData:",TempData)
					dat1 = str(TempData[0]).replace('{','')
					#print("data1:",dat1)
				
					if dat1 == 'True' and len(TempData) == 13:
						TempData[12] = str(TempData[12]).replace('}','')
						TempData[0] = True

						shared.DEV[address][0] = TempData[0]
						#we store current
						shared.DEV[address][1] = str(TempData[1].replace('I',''))
						#we store voltage
						shared.DEV[address][2] = str(TempData[2].replace('V',''))
						#we store temperature
						shared.DEV[address][3] = str(TempData[3].replace('T',''))
						#we store step number and type
						shared.DEV[address][4] = str(TempData[4].replace('AH',''))
						#we store amper accumulate
						shared.DEV[address][5] = str(TempData[5].replace('AC',''))
						#we store step number 
						shared.DEV[address][6] = str(TempData[6].replace('P',''))
						#we store time of current status
						shared.DEV[address][7] = str(TempData[7].replace('S',''))
						#we store current time program
						shared.DEV[address][8] = str(TempData[8].replace('t',''))
						#we store the total time program
						shared.DEV[address][9] = str(TempData[9].replace('Tt',''))
						#we store the total time program
						shared.DEV[address][10] = str(TempData[10].replace('TT',''))
						#we store the name program
						shared.DEV[address][11] = str(TempData[11].replace('N',''))
						#we store the total time program
						shared.DEV[address][12] = str(TempData[12].replace('',''))

					elif dat1 == 'False}':
						TempData[0] = str(TempData[0]).replace('}','')
						shared.DEV[address][0] = False
					
					#print("TempData2:",TempData)

		if self.flagClose != True:
			self.threadTimer(True)
		else:
			self.threadTimer(False)

		shared.lock_client.release()
コード例 #5
0
    def run(self):

        #try:
        print(self._name + " started")

        self.pingForDevicesPresent()

        while not self._stop_event.is_set():

            # we do ping to the devices

            for i in range(shared.devStart, shared.devStop + 1):
                address = i

                if shared.DEV[address][0] == True:
                    print("Doing asking data to device No." + str(address))
                    readData = BCmb.readDataClient('raspberrypi.local',
                                                   address)
                    print("VALUE:")
                    print(readData)
                    if readData != None:
                        #we store current
                        shared.DEV[address][1] = str(readData[0]).replace(
                            'I', '')
                        #we store voltage
                        shared.DEV[address][2] = str(readData[1]).replace(
                            'V', '')
                        #we store temperature
                        shared.DEV[address][3] = str(readData[2]).replace(
                            'T', '')
                        #we store step number and type
                        shared.DEV[address][4] = str(readData[3]).replace(
                            'P', '')
                        #we store time of current step
                        shared.DEV[address][5] = str(readData[4].replace(
                            't', ''))
                        #we store total time program
                        shared.DEV[address][6] = str(readData[5].replace(
                            't', ''))

                        self.dataStr = str(readData[0])

                    #['VALUE', 'I0.27,V-0.98,T27.21']
                    if readData != None:
                        if self.mySrc != None:
                            self.mySrc.myGUI_signal.emit("DL[" + str(address) +
                                                         "]:DataReady")
            '''
            
            sleep(.1)

            print(self._name+" stopped")
        
            '''
        '''
コード例 #6
0
    def run(self):
        print(self._name + " started")
        #lock_client.acquire()
        while not self._stop_event.is_set():
            for j in range(len(useHostname)):
                memoryPolling = BCmb.startPollingClient(
                    useHostname[j], usePort[j])
                #sleep(.3)
                #print("memory:",memoryPolling)

                #if memoryPolling != None:
                #	if self.mySrc != None:
                #self.mySrc.myGUI_signal.emit("DL["+str(address)+"]:DataReady")
                self.mySrc.myGUI_signal.emit("DL[PASS]:DataReady")
コード例 #7
0
 def pingForDevicesPresent(self,addr):
     # we do ping to the devices, falta agregar 3 timeout si los 3 son falso el quipo esta desconectado
     #print("Doing ping to device No."+str(addr))
     readData = BCmb.ping(addr)
     print("VALUE_PING_PRESENT:",str(readData))
     DEV[addr][0] = False
     if readData!= None:
         if readData == True:
             DEV[addr][0] = True
             print("DEV"+str(addr)+" is Present!")
         else:
             print("DEV"+str(addr)+" is not Present!")
     else:
         print("DEV"+str(addr)+" is not Present!")
コード例 #8
0
    def pingForDevicesPresent(self):
        # we do ping to the devices

        for i in range(shared.devStart, shared.devStop + 1):
            address = i
            print("Doing ping to device No." + str(address))
            readData = BCmb.pingClient('raspberrypi.local', address)
            print("VALUE:")
            print(str(readData))
            shared.DEV[i][0] = False
            if readData != None:
                if readData == True:
                    shared.DEV[i][0] = True
                    print("DEV" + str(address) + " is Present!")
                else:
                    print("DEV" + str(address) + " is not Present!")
            else:
                print("DEV" + str(address) + " is not Present!")
コード例 #9
0
    def run(self):

        #try:
        print(self._name + " started")

        self.pingForDevicesPresent()

        for i in range(1, 2 + 1):
            add = str(i)
            ireport = IndividualReport(add)
            ireport.begin()

        while not self._stop_event.is_set():

            # we do ping to the devices

            for i in range(1, 2 + 1):
                address = i
                add = str(address)

                ireport = IndividualReport(add)
                #ireport.begin()
                print(address)

                if shared.DEV[address][0] == True:
                    print("Doing asking data to device No." + str(address))
                    readData = BCmb.readData(address)
                    print("VALUE:")
                    print(readData)

                    readData = readData.split(",")
                    print(readData)

                    if readData != None:
                        #we store current
                        shared.DEV[address][1] = str(readData[0]).replace(
                            'I', '')
                        #we store voltage
                        shared.DEV[address][2] = str(readData[1]).replace(
                            'V', '')
                        #we store temperature
                        shared.DEV[address][3] = str(readData[2]).replace(
                            'T', '')
                        #we store step number and type
                        shared.DEV[address][4] = str(readData[3]).replace(
                            'P', '')
                        #we store time of current step
                        shared.DEV[address][5] = str(readData[4].replace(
                            't', ''))
                        #we store current time program
                        shared.DEV[address][6] = str(readData[5].replace(
                            'Tt', ''))
                        #we store the total time program
                        shared.DEV[address][7] = str(readData[6].replace(
                            'TT', ''))
                        #we store the total time program
                        shared.DEV[address][8] = str(readData[7].replace(
                            '', ''))

                        print("Current Value:")
                        print(shared.DEV[address][1])
                        print(shared.DEV[address][2])
                        print(shared.DEV[address][3])
                        print(shared.DEV[address][4])
                        print(shared.DEV[address][5])
                        print(shared.DEV[address][6])
                        print(shared.DEV[address][7])
                        print(shared.DEV[address][8])

                        #for i in range (1,9):
                        ireport.appendWithTimeStamp(","+ shared.DEV[address][1] + "," + shared.DEV[address][2] + "," +\
                                                         shared.DEV[address][3] + "," + shared.DEV[address][4] + "," +\
                                                         shared.DEV[address][5] + "," + shared.DEV[address][6] + "," +\
                                                         shared.DEV[address][7] + "," + shared.DEV[address][8])

                        #self.dataStr = str(readData[0])

                    #['VALUE', 'I0.27,V-0.98,T27.21']

            sleep(.1)

            print(self._name + " stopped")
        '''
コード例 #10
0
	def showEvent(self,event):
		print("ShowEvent") 
		if self.flagWmin != True: #Para ubuntu se necesito esta bandera
			self.flagWmin = True
		#if MainWindow.isMinimized(): #Para mac
		#	pass
		#else:
			#----------------------------------- Obtiene hostname, port , addrs / serverConfig.ini ------------------------#
			settaddrs = QtCore.QSettings('/home/ditsa/DitsaNet/Settings/ServerConfig.ini',QtCore.QSettings.NativeFormat)
			if settaddrs.value('/home/ditsa/DitsaNet/Settings/ServerConfig.ini') !='':
				tmpAddr = settaddrs.value("servers")   #nombre de server y port
				
				for i in range(3,len(tmpAddr),4):
					self.tmp_server.clear()
					x = tmpAddr[i].rpartition('-')
					val1 = int(x[0])
					#val2 = int(x[2])
					self.tmp_server.append(str(val1))

					for j in range(15):
						y = val1 + j + 1
						self.tmp_server.append(str(y))

					self.tempAddr.append(self.tmp_server[:])
					self.tmp_total.append(str(self.tmp_server[:]))

				for k in range(0,len(tmpAddr),4): #guarda el hostname, el port y password
					useHostname.append(tmpAddr[k]+".local")
					usePort.append(int(tmpAddr[k+1]))
					usePassw.append(tmpAddr[k+2])
			'''
			settprog = QtCore.QSettings('/home/ditsa/DitsaNet/Settings/fileprograms.ini', QtCore.QSettings.NativeFormat)
			if settprog.value('/home/ditsa/DitsaNet/Settings/fileprograms.ini') !='':
				tmp = settprog.value("saveprograms")

				if tmp != None and len(tmp) != 0:
					self.saveprograms = tmp[:]
					self.flagProg = True
					print("savePR:",self.saveprograms) #esta opcion no puede ser viable por que los gabinetes y addr puede cambiar 
			'''
			#-----------------------------------Obtiene mylist, mylabel, rowcol / archivo.ini -----------------------------#
			settings = QtCore.QSettings('/home/ditsa/DitsaNet/Settings/archivo.ini', QtCore.QSettings.NativeFormat)
			if settings.value('/home/ditsa/DitsaNet/Settings/archivo.ini')!='':
				self.settingsList = settings.value("mylist")
				self.settingsLabel = settings.value("mylabel")
				self.settingsRowCol = settings.value("rowcol")

				if self.settingsRowCol != None and len(self.settingsRowCol) !=0:
					self.rowCol = self.settingsRowCol[:]
				else:
					self.rowCol.append('1%')
					self.rowCol.append('R=10 C=10')

				if self.settingsList != None:
					self.mylist = self.settingsList[:] #para que no correspondan con el mismo objeto
					
					for i in range(2,len(self.mylist),4):
						self.newlist.append(self.mylist[i].replace('N=',''))

					ordName = NameOrdened(self.newlist) #manda a llamar la clase NameOrdened
					x = ordName.cod()					#ordena los elementos de la lista de < a >
					self.newlist.clear()

					#Los valores de neewlist son todas las addr que se muestran en la app DitsaEditor
					for i in range(len(x)): #Extrae address ingresados en DitsaEditor
						for j in range(2,len(self.mylist),4):
							if "N="+str(x[i]) == self.mylist[j]:
								self.newlist.append(self.mylist[j-2])
								self.newlist.append(self.mylist[j-1])
								self.newlist.append(self.mylist[j])
								self.newlist.append(self.mylist[j+1])

				if self.settingsLabel != None:
					self.mylabel = self.settingsLabel[:] #para que no correspondan con el mismo objeto

				if self.settingsList != None or self.settingsLabel != None: # Populate Tables
					self.populateTabs()

					self.paint = Paint(self)
					self.tabWidget.addTab(self.paint, "Page 1")
					tabC = self.tabWidget.count()

					MainWindow.showMaximized()
					self.paint.setSceneRect(0,0,0,0)

					if (self.settingsList != None  and len(self.settingsList)!=0) or (self.settingsLabel != None and len(self.settingsLabel)!=0):
						for i in range(int(self.numTabT)-tabC):
							self.newPage()

					self.onCmbZoom()

					for j in range(len(useHostname)):
						BCmb.pingDataClient(useHostname[j],usePort[j],self.tmp_total[j]) #envia las addr de los modulos 
	
					
					print("Inicia Poleo") #poleo es lo primero en iniciar despues de llenar screen
					self.threadData(True) #Inicia el poleo
			
					time.sleep(0.3)
					self.valueData() #obtiene los valores del poleo del sever
コード例 #11
0
 def on_cmdDetener1_clicked(self):
     print("Detener")
     #if self.check1.checkState == QtCore.Qt.Checked:
     BCmb.stopClient('raspberrypi.local', 1)
     #if self.check2.checkState == QtCore.Qt.Checked:
     BCmb.stopClient('raspberrypi.local', 2)
コード例 #12
0
 def on_cmdPausar1_clicked(self):
     print("Pausar")
     if self.check1.checkState == QtCore.Qt.Checked:
         BCmb.pauseClient('raspberrypi.local', 1)
     if self.check2.checkState == QtCore.Qt.Checked:
         BCmb.pauseClient('raspberrypi.local', 2)
コード例 #13
0
ファイル: windowch.py プロジェクト: fmbi1984/DitsaNetApp
    def on_bttnDoneClicked(self):
        print("clickDone")
        #----------------------------- Detiene thread -----------------------------#
        time.sleep(0.5)
        self.parent.threadTimer(False)
        self.parent.threadData(False)
        #---------------------------- Extrae valor Addr ---------------------------#
        self.uncheck_check()
        self.addrs.clear()
        for i in range(3, len(self.loadProg), 4):
            addr = self.loadProg[i].split('A=')
            self.addrs.append(addr[1])
        self.loadProg.clear()
        self.textEdit.clear()
        #---------------------------- Envia json a xmegas -------------------------#
        self.chtext("msg", "None")

        #for j in range(len(self.parent.saveprograms)):
        if self.textPrograms.currentText() != '':

            for j in range(len(useHostname)):
                section = self.parent.tempAddr[j]
                for i in range(len(section)):
                    for k in range(len(self.addrs)):
                        if section[i] == self.addrs[k]:

                            #for i in range(len(self.addrs)):
                            if int(section[i]) > 16:
                                self.flagSect = True
                                #print("section:",section[i])
                                #print("i:",i+1)
                                x = BCmb.writeProgramClient(
                                    useHostname[j], usePort[j], i + 1,
                                    self.nameFile + self.programJson)

                            else:
                                x = BCmb.writeProgramClient(
                                    useHostname[j], usePort[j],
                                    int(self.addrs[k]),
                                    self.nameFile + self.programJson)

                            #print("xx:",x)
                            if x != None:
                                if x == 'PASS':
                                    self.chtext(x, self.addrs[k])

                                    self.checkPrograms(self.addrs[k])
                                    self.parent.saveprograms.append(
                                        self.nameFile)
                                    self.parent.saveprograms.append(
                                        'A=' + self.addrs[k])

                                    self.settingsPrograms()

                                    #time.sleep(0.5)
                                    if self.flagSect != True:
                                        run = BCmb.runClient(
                                            useHostname[j], usePort[j],
                                            int(self.addrs[k]))
                                    else:
                                        run = BCmb.runClient(
                                            useHostname[j], usePort[j], i + 1)

                                    if run != None:
                                        if run == 'PASS,RUN':
                                            self.chtext(run, self.addrs[k])

                                        else:
                                            self.chtext(run, self.addrs[k])
                                            self.flagFail = True

                                    else:
                                        self.chtext('None', self.addrs[k])
                                        self.flagFail = True

                                else:
                                    self.chtext(x, self.addrs[k])
                                    self.flagFail = True

                            else:
                                self.chtext('None', self.addrs[k])
                                self.flagFail = True
        else:
            for j in range(len(useHostname)):
                section = self.parent.tempAddr[j]
                for i in range(len(section)):
                    for k in range(len(self.addrs)):
                        if section[i] == self.addrs[k]:

                            #for i in range(len(self.addrs)):
                            x = BCmb.runClient(useHostname[j], usePort[j],
                                               int(self.addrs[k]))

                            if x != None:
                                if x == 'PASS,RUN':
                                    self.chtext(x, self.addrs[k])

                                else:
                                    self.chtext(x, self.addrs[k])
                                    self.flagFail = True

                            else:
                                self.chtext('None', self.addrs[k])
                                self.flagFail = True

        if self.flagFail != True:
            time.sleep(3)
            self.close()
コード例 #14
0
    def run(self):

        #try:
        print(self._name+" started")
        
        #self.pingForDevicesPresent() #verificar ping hacer pruebas 
        
        while not self._stop_event.is_set():
            
            # we do ping to the devices 
            lock_memory.acquire()
            for i in range(len(ON_PI)): #todos
                address = ON_PI[i]
                #print("DA_PI:",ON_PI[i])
                #print("DEV:",DEV[address][0])

                if DEV[address][0] == True:
                    print("Doing asking data to device No."+str(address))
                   
                    readData = BCmb.readData(address)
                    #print("ValueDLS:",readData)
                    
                    
                    if readData!= None and len(readData)==11:
                        #we store current
                        DEV[address][1] = str(readData[0].replace('I',''))
                        #we store voltage
                        DEV[address][2] = str(readData[1].replace('V',''))
                        #we store temperature
                        DEV[address][3] = str(readData[2].replace('T',''))
                        #we store step number and type
                        DEV[address][4] = str(readData[3].replace('AH',''))
                        #we store step number and type
                        DEV[address][5] = str(readData[4].replace('AC',''))
                        #we store step number and type
                        DEV[address][6] = str(readData[5].replace('P',''))
                        #we store step number and type
                        DEV[address][7] = str(readData[6].replace('S',''))
                        #we store time of current step
                        DEV[address][8] = str(readData[7].replace('t',''))
                        #we store current time program
                        DEV[address][9] = str(readData[8].replace('Tt',''))
                        #we store the total time program
                        DEV[address][10] = str(readData[9].replace('TT',''))
                        #we store the total time program
                        DEV[address][11] = str(readData[10].replace('',''))
                        '''
                        print("Current Value:")
                        print(DEV[address][1])
                        print(DEV[address][2])
                        print(DEV[address][3])
                        print(DEV[address][4])
                        print(DEV[address][5])
                        print(DEV[address][6])
                        print(DEV[address][7])
                        print(DEV[address][8]) 
                        '''
                        if (DEV[address][11] == 'S' or DEV[address][11] == 'E') and DEV[address][12] == True:
                            DEV[address][12] = False
                            ireport.appendWithTimeStampUsingFile(","+ DEV[address][1] + "," + DEV[address][2] + "," +\
                                                    DEV[address][3] + "," + DEV[address][4] + "," +\
                                                    DEV[address][5] + "," + DEV[address][6] + "," +\
                                                    DEV[address][7] + "," + DEV[address][8] + "," +\
                                                    DEV[address][9] + "," + DEV[address][10] + "," + DEV[address][11],str(RE_PI[i]))

                        if DEV[address][11] == 'R' or DEV[address][11] == 'P' or DEV[address][11] == 'T' or DEV[address][11] == 'W':
                            DEV[address][12] = True
                            ireport.appendWithTimeStampUsingFile(","+ DEV[address][1] + "," + DEV[address][2] + "," +\
                                                    DEV[address][3] + "," + DEV[address][4] + "," +\
                                                    DEV[address][5] + "," + DEV[address][6] + "," +\
                                                    DEV[address][7] + "," + DEV[address][8] + "," +\
                                                    DEV[address][9] + "," + DEV[address][10] + "," + DEV[address][11],str(RE_PI[i]))
                        
                    
                        #self.dataStr = str(readData[0])
                
                    #['VALUE', 'I0.27,V-0.98,T27.21']
                else:
                    self.pingForDevicesPresent(address)
                    
            #print("sleep22")
            sleep(.3)
            self.stop()
            #self._pause_event.set()
            lock_memory.release()
            #while not self._stop_event.is_set():
            #   print("stop_event")
            #   sleep(.2)
            #print(self._name+" stopped")
        
        '''
コード例 #15
0
def client_thread(conn):
    global ds
    while True:
        p_data = conn.recv(1024)
        if not p_data:
            break

        result = None
        data = None

        try:
            #cmd_data = bytes(cmd,'ISO-8859-1')
            #p_data = devInterface.packMessage(address, op, cmd_data)

            if appsettings.useDongle == True:
                print("Test Mac Server")
                sp = SerialPortUtil.getFirstPortByVID_PID(0x1a86, 0x7523)
                #print(sp)
                #print("p_data")
                #print(p_data)
                op_code = 0x57
                st_polling = 0x36
                cl_polling = 0x37
                op_data = 0x38
                da_ping = 0x65
                t_out = 10

                if p_data[1] == st_polling:
                    print("START_POLLING")
                    #msg = devInterface.unpackMessage(p_data)
                    msg = devInterface.unpackMessageWithoutAddr(p_data)

                    ds = DataListenerServer(None)
                    ds.start()
                    ds.join()

                    tmp = bytes("ACTION: PASS", 'ISO-8859-1')

                    data = bytes(
                        devInterface.packMessageWithoutAddr(msg[1], tmp))
                    #data = bytes(devInterface.packMessage(msg[1], msg[2], tmp))
                    #print("DATA1:",data)

                elif p_data[1] == cl_polling:
                    print("STOP_POLLING")
                    #msg = devInterface.unpackMessage(p_data)
                    msg = devInterface.unpackMessageWithoutAddr(p_data)
                    #print("msg:",msg)
                    tmp = bytes("ACTION: PASS", 'ISO-8859-1')
                    if ds is not None:
                        #print("Have Value: ")
                        #print(ds)
                        ds.stop()
                    #data = bytes(devInterface.packMessage(msg[1], msg[2], tmp))
                    data = bytes(
                        devInterface.packMessageWithoutAddr(msg[1], tmp))
                    #print("DATA2:",data)

                elif p_data[1] == da_ping:
                    print("DATAPING")
                    msg = devInterface.unpackMessageWithoutAddr(p_data)
                    #print("msg:",msg[2])

                    new = msg[2].decode("utf-8")
                    test = new.split('e')
                    test2 = test[1]
                    test2 = test2.split("'")

                    shared.DA_PI.clear()
                    shared.ON_PI.clear()
                    shared.RE_PI.clear()
                    for i in range(len(test2)):
                        if test2[i].isdigit():
                            shared.DA_PI.append(int(test2[i]))

                    print("sharedDA:", shared.DA_PI)

                    #preguntaria del 1 al 16 no importa lo que tenga shared OJO!!

                    #hace ping a todos los modulos
                    for i in range(shared.devStart,
                                   shared.devStop + 1):  #len(shared.DA_PI)
                        #address = shared.DA_PI[i]
                        address = i

                        #print("Doing ping to device No."+str(address))
                        readData = BCmb.ping(address)
                        #print("VALUE:",str(readData))

                        shared.DEV[address][0] = False
                        if readData != None:
                            if readData == True:
                                shared.DEV[address][0] = True
                                shared.ON_PI.append(int(address))
                                shared.RE_PI.append(int(shared.DA_PI[i - 1]))
                                print("DEV" + str(address) + " is Present!")
                            else:
                                print("DEV" + str(address) +
                                      " is not Present!")
                                #ireport.end()
                        else:
                            print("DEV" + str(address) + " is not Present!")
                            #ireport.end()

                    #dfile = FilesServer()

                    tmp = bytes("ACTION: PASS", 'ISO-8859-1')
                    data = bytes(
                        devInterface.packMessageWithoutAddr(msg[1], tmp))
                    #print("DATA3:",data)

                elif p_data[1] == op_data:
                    print("MEMORY_DATA")

                    #ds.stop()
                    #sleep(.2)
                    #msg = devInterface.unpackMessage(p_data)
                    lock_memory.acquire()
                    msg = devInterface.unpackMessageWithoutAddr(p_data)
                    #print("msg")
                    #print(msg)
                    #tmp = bytes("ACTION: PASS", 'ISO-8859-1')
                    #address = int(msg[1])
                    #print("started Acquire memory server")
                    tmp = "VALUE: "
                    for i in range(
                            shared.devStart, shared.devStop + 1
                    ):  #len(DA_PI) #en vez de solo los que estan pregunta por todos ON_PI

                        address = i
                        #address = DA_PI[i]
                        #print("Address: "+str(address))
                        if DEV[address][0] == True:
                            #DEV[address][0] = "True"
                            tmp += "{"
                            tmp +=  str(shared.DEV[address][0]) + "," +\
                                    "I" + shared.DEV[address][1] + "," +\
                                    "V" + shared.DEV[address][2] + "," +\
                                    "T" + shared.DEV[address][3] + "," +\
                                    "AH" + shared.DEV[address][4] + "," +\
                                    "AC" + shared.DEV[address][5] + "," +\
                                    "P" + shared.DEV[address][6] + "," +\
                                    "S" + shared.DEV[address][7] + "," +\
                                    "t" + shared.DEV[address][8] + "," +\
                                    "Tt" + shared.DEV[address][9] + "," +\
                                    "TT" + shared.DEV[address][10] + "," +\
                                    "" + shared.DEV[address][11]
                            tmp += "}"
                        else:
                            tmp += "{"
                            tmp += str(shared.DEV[address][0])
                            tmp += "}"
                        tmp += ";"
                        #print(tmp)

                    #print("stop RELEASE memory server")
                    #print("TMP")
                    #print(tmp)
                    #data = bytes(devInterface.packMessage(msg[1], msg[2], bytes(tmp,'ISO-8859-1')))
                    data = bytes(
                        devInterface.packMessageWithoutAddr(
                            msg[1], bytes(tmp, 'ISO-8859-1')))
                    lock_memory.release()
                    #print("DATA3:")
                    #print(data)

                else:

                    if p_data[2] == op_code:  #write eeprom json
                        t_out = 10
                        attempts = 1
                    else:
                        t_out = 1
                        attempts = 3

                    try:
                        lock_memory.acquire()
                        sct = SerialCommThread(None, sp,
                                               appsettings.FTDI_baudRate,
                                               p_data, b'\x04', t_out,
                                               attempts)
                        sct.start()
                        sct.join()

                        data = bytes(serial_cmd_result[0])
                        #print("DATA11:",data)
                        lock_memory.release()

                    except:
                        print("Error: Serial Communication")

            else:
                print("Test Raspbian")
                sp = SerialPortUtil.getPortByName("/dev/ttyS0")
                #print(sp)

            #sp = SerialPortUtil.getPortBySerialNumber(appsettings.FTDI_serialNumber)
            #sp = SerialPortUtil.getFirstPortByVID_PID(0x067b,0x2303)
            #sp = SerialPortUtil.getFirstPortByVID_PID(0x10c4,0xea60)
            if sp == None:
                raise Exception("devInterface", "No serial device found!")

            #print("serial thread stopped")
            #if sct.stopped() == False:
            #   e="serial thread not stopped"
            #   print("\033[1;31;40m"+str(e)+"\033[0;37;40m")
            '''
            result = None
            if data != None:
                result = devInterface.decodeMessage(data)
            else:
                result = None
            '''
        except Exception as e:
            print("\033[1;31;40m" + str(e) + "\033[0;37;40m")
        #return result

        #reply = b'OK . . '
        #reply = serial_cmd_result[0]
        #print('Received', repr(data))
        if data != None:
            conn.sendall(data)
            print("Send:", data)
        else:
            conn.sendall(b'None')
    print("[-] Closed connection")
    conn.close()