def readyRead(self): while self.socket.canReadLine(): message = str(self.socket.readLine())[:-1] if hdebug.getDebug(): hdebug.logText("Got: " + message) # Send an acknowledgement that the command was recieved. self.socket.write(QtCore.QByteArray("Ack\n")) self.socket.flush() # Parse the message to generate the command. message_split = message.split(",") # Get command type. command_type = message_split[0] # Parse command data. i = 0 command_data = [] message_data = message_split[1:] while(i < len(message_data)): m_type = message_data[i] m_value = message_data[i+1] if (m_type == "string"): command_data.append(m_value) elif (m_type == "int"): command_data.append(int(m_value)) elif (m_type == "float"): command_data.append(float(m_value)) else: print "Unknown type:", m_type i += 2 self.commMessage.emit(TCPMessage(command_type, command_data))
def disconnected(self): if hdebug.getDebug(): hdebug.logText(" TCPControl lost connection. " + str(self.isConnected())) self.socket.disconnectFromHost() self.socket.close() self.socket = None self.commLostConnection.emit()
def disconnect(self): if hdebug.getDebug(): hdebug.logText(" TCPControl forced dis-connect. " + str(self.isConnected())) if self.isConnected(): self.socket.disconnectFromHost() self.socket.waitForDisconnected() self.socket.close() self.socket = None self.listen(QtNetwork.QHostAddress(QtNetwork.QHostAddress.LocalHost), self.port) self.commLostConnection.emit()
def handleConnection(self): if hdebug.getDebug(): hdebug.logText(" TCPControl got connection. " + str(self.isConnected())) socket = self.nextPendingConnection() if self.isConnected(): print " busy.." socket.write(QtCore.QByteArray("Busy\n")) socket.disconnectFromHost() socket.close() else: print " connecting.." self.socket = socket self.socket.readyRead.connect(self.readyRead) self.socket.disconnected.connect(self.disconnected) self.commGotConnection.emit()
def initCamera(self): if not self.camera: if hdebug.getDebug(): print " Initializing None Camera Type" self.camera = True self.got_camera = True
def initCamera(self): if not self.camera: if hdebug.getDebug(): print " Initializing None Camera Type" self.camera = 1 self.got_camera = 1