def __init__(self, parent=None): super(mainInterface, self).__init__(parent) # self.setMinimumHeight(720) # self.setMinimumWidth(1280) self.resize(1280, 720) self.portInstance = Protocol.Protocol() self.setWindowTitle("ECE121 Main Interface") self.mainWindow = mainWidget(self.portInstance) # self.statusBar().showMessage("Active Connection: {}".format(self.portInstance.activeConnection), 1000) self.setCentralWidget(self.mainWindow) self.show() # we add permanent widgets to the status bar to show a variety of information self.serialStatus = QLabel("Hi ") self.packetTransmissions = QLabel(" Bob") self.statusBar().addPermanentWidget(self.serialStatus) self.statusBar().addPermanentWidget(self.packetTransmissions) self.updateStatus() self.Timer = QTimer() self.Timer.timeout.connect(self.updateStatus) self.Timer.start(100) # if not self.portInstance.activeConnection: # QMessageBox.information(self, "Serial Port Status", "No Serial Ports Found") return
def __init__(self, parent=None): super(Foo, self).__init__(parent) self.outerLayout = QVBoxLayout() self.setLayout(self.outerLayout) self.setWindowTitle('Dummy Gui') self.outerLayout.addWidget(QLabel("LED Setting Example")) checkLayout = QHBoxLayout() self.outerLayout.addLayout(checkLayout) self.ledCheckButtons = list() for i in range(7, -1, -1): newCheck = QCheckBox("{}".format(i)) # newCheck.setTristate(False) checkLayout.addWidget(newCheck) newCheck.clicked.connect(self.handleLEDOut) self.ledCheckButtons.append(newCheck) # self.setCheckBoxes(random.randint(0, 255)) print(self.getCheckBoxes()) # we now instantiate a copy of the protocol and link it to the led message self.protInstance = Protocol.Protocol() self.protInstance.registerMessageHandler( Protocol.MessageIDs.ID_LEDS_STATE, self.handleLEDIn) self.protInstance.registerMessageHandler(Protocol.MessageIDs.ID_DEBUG, self.updateDebug) # send a request for current LED state self.protInstance.requestLEDState() # add a label for debug messages self.debugLabel = QLabel() self.outerLayout.addWidget(self.debugLabel) return
from ece121 import Protocol import time startNumber = 0 def updateLEDs(currentNumber): global startNumber messageOut = Protocol.MessageIDs.ID_LEDS_SET.value.to_bytes( 1, byteorder='big') messageOut += startNumber.to_bytes(1, byteorder='big') startNumber = (startNumber + 1) % 256 print(startNumber) protInstance.sendRawMessage(messageOut) protInstance.requestLEDState() return protInstance = Protocol.Protocol() protInstance.registerHandler(Protocol.MessageIDs.ID_LEDS_STATE, updateLEDs) protInstance.requestLEDState() while True: time.sleep(1)
print("{}\t{}\t{}".format(datetime.datetime.now(), IDString, Message)) return def DisconnectHandler(inException): print(inException) while True: time.sleep(.1) if prot.Connect(): print("Connected to {}".format(prot.Port)) break return print("Current Serial Ports", Protocol.Protocol.listSerialPorts()) prot = Protocol.Protocol() for enum in Protocol.MessageIDs: prot.registerMessageHandler(enum, MonitorPrint) # prot.registerHandler(Protocol.MessageIDs.ID_DEBUG, MonitorPrint) prot.registerErrorHandler(DisconnectHandler) if not prot.activeConnection: print("No Serial Port Found") while True: time.sleep(.1) if prot.Connect(): print("Connected to {}".format(prot.Port)) break while True: