Пример #1
0
    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
Пример #2
0
 def MonitorOutgoingPrint(self, inBytes):
     ID = inBytes[2]
     try:
         IDString = Protocol.MessageIDs(ID).name
     except ValueError:
         IDString = "Invalid ID ({})".format(ID)
     curline = "{}\t{}\t0X{}".format(datetime.datetime.now(), IDString,
                                     inBytes.hex().upper())
     self.outStrSignal.emit(curline)
     return
Пример #3
0
def MonitorPrint(inBytes):
    Message = inBytes[1:]
    ID = inBytes[0]
    try:
        IDString = Protocol.MessageIDs(ID).name
    except ValueError:
        IDString = "Invalid ID ({})".format(ID)
    # print(IDString)
    try:
        Message = Message.decode('ascii')
    except UnicodeError:
        pass
    print("{}\t{}\t{}".format(datetime.datetime.now(), IDString, Message))
    return
Пример #4
0
    def MonitorIncomingPrint(self, inBytes):
        Message = inBytes[1:]
        ID = inBytes[0]
        try:
            IDString = Protocol.MessageIDs(ID).name
        except ValueError:
            IDString = "Invalid ID ({})".format(ID)
        # print(IDString)
        if Protocol.MessageIDs(ID) == Protocol.MessageIDs.ID_DEBUG:
            try:
                Message = Message.decode('ascii')
            except UnicodeDecodeError:
                Message = 'Non-Ascii Characters in Message: 0X' + Message.hex(
                ).upper()
        else:
            Message = '0X' + Message.hex().upper()

        self.curLine = "{}\t{}\t{}".format(datetime.datetime.now(), IDString,
                                           Message)
        # QCoreApplication.postEvent(self, QEvent(self.newMessageEvent))
        self.inStrSignal.emit(self.curLine)

        return
Пример #5
0
    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
Пример #6
0
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)
Пример #7
0
	def AdvanceTest(self, newBytes=None):
		if newBytes is not None:
			ID = Protocol.MessageIDs(newBytes[0])
			# print(ID)
		else:
			ID = Protocol.MessageIDs.ID_INVALID
		if self.testState == testStates.IDLE:
			if newBytes is None: # this is the start case
				self.PGain = random.randint(10000, 20000)
				self.IGain = random.randint(1000, 2000)
				self.DGain = random.randint(100, 200)
				# self.DGain = 0
				self.AccumulatedError = 0
				self.lastSensorValue = 0
				self.testCount = 0
				self.refValue = random.randint(400,600)
				self.sensorValue = self.refValue
				self.portInstance.sendMessage(Protocol.MessageIDs.ID_FEEDBACK_SET_GAINS, struct.pack("!iii", self.PGain, self.IGain, self.DGain))
				self.stringSignal.emit("Setting Gains to P:{} I:{} D:{}".format(self.PGain, self.IGain, self.DGain))
				self.testState = testStates.SENDINGGAINS
		elif self.testState == testStates.SENDINGGAINS:
			if ID == Protocol.MessageIDs.ID_FEEDBACK_SET_GAINS_RESP:
				self.stringSignal.emit("Resetting Controller")
				self.portInstance.sendMessage(Protocol.MessageIDs.ID_FEEDBACK_RESET_CONTROLLER, None)
				self.testState = testStates.RESETTINGINTEGRATOR
		elif self.testState == testStates.RESETTINGINTEGRATOR:
			if ID == Protocol.MessageIDs.ID_FEEDBACK_RESET_CONTROLLER_RESP:
				self.testState = testStates.TESTZERO
				self.stringSignal.emit("Sending Test Signal of R:{} S:{}".format(self.refValue, self.sensorValue))
				self.portInstance.sendMessage(Protocol.MessageIDs.ID_FEEDBACK_UPDATE, struct.pack("!ii", self.refValue, self.sensorValue))
		elif self.testState == testStates.TESTZERO:
			if ID == Protocol.MessageIDs.ID_FEEDBACK_UPDATE_OUTPUT:
				output = struct.unpack("!i", newBytes[1:])[0]
				testOutput = self.UpdateFeedBack(self.refValue, self.sensorValue)
				if abs(output - testOutput) < 5:
					self.stringSignal.emit("Received {} and calculated {}, passed".format(output, testOutput))
				else:
					self.stringSignal.emit("Received {} and calculated {}, failed".format(output, testOutput))
					self.stringSignal.emit("Test Failed, exiting")
					self.testState = testStates.IDLE
				# print(output, testOutput)

				self.refValue += random.randint(-50, 50)
				self.sensorValue += random.randint(-50, 50)
				self.portInstance.sendMessage(Protocol.MessageIDs.ID_FEEDBACK_UPDATE, struct.pack("!ii", self.refValue, self.sensorValue))
				self.testState = testStates.TESTPOINTS
				self.testCount += 1
				# self.testState = testStates.IDLE
		elif self.testState == testStates.TESTPOINTS:
			if ID == Protocol.MessageIDs.ID_FEEDBACK_UPDATE_OUTPUT:
				output = struct.unpack("!i", newBytes[1:])[0]
				testOutput = self.UpdateFeedBack(self.refValue, self.sensorValue)
				if abs(output - testOutput) < 5:
					self.stringSignal.emit("Received {} and calculated {}, passed".format(output, testOutput))
				else:
					self.stringSignal.emit("Received {} and calculated {}, failed".format(output, testOutput))
					self.stringSignal.emit("Test Failed, exiting")
					self.testState = testStates.IDLE
				self.testCount += 1
				if self.testCount >= 10:
					self.stringSignal.emit("Test Complete at {}".format(datetime.datetime.now()))
					self.testState = testStates.IDLE
				else:
					self.refValue += random.randint(-50, 50)
					self.sensorValue += random.randint(-50, 50)
					self.stringSignal.emit("Sending Test Signal of R:{} S:{}".format(self.refValue, self.sensorValue))
					self.portInstance.sendMessage(Protocol.MessageIDs.ID_FEEDBACK_UPDATE, struct.pack("!ii", self.refValue, self.sensorValue))
		return
Пример #8
0
    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: