Exemplo n.º 1
0
    def __init__(self):
        """
        Main shared data object.
        """
        super().__init__()

        self.serialSettings: serComm.SerialCommSettings = serComm.SerialCommSettings(
        )

        self.configurationFilePath: str = None

        self.dataFields: [str] = [''] * NUM_OF_DATA_CHANNELS
        self.parsedDataFields: list = [
            None
        ] * NUM_OF_DATA_CHANNELS  # list of integers (bytes), as they are send over serial port
        self.noteFields: [str] = [''] * NUM_OF_DATA_CHANNELS
        self.seqFields: [str] = [''] * NUM_OF_SEQ_CHANNELS
        self.parsedSeqFields: [
            SequenceData
        ] = [None] * NUM_OF_SEQ_CHANNELS  # list of parsed sequence blocks

        self.allRxTxData = []

        self.outputDataRepresentation = OutputRepresentation.STRING
        self.displayReceivedData: bool = True
        self.displayTransmittedData: bool = True
        self.rxNewLine: bool = False
        self.rxNewLineTimeout: int = DEFAULT_RX_NEWLINE_TIMEOUT_MS
Exemplo n.º 2
0
    def loadConfiguration(self, filePath: str):
        """
        Read (load) given json file and set new configuration.
            @param filePath: path to load file from.
        """
        with open(filePath, 'r') as fileHandler:
            wData = json.load(fileHandler)

        if (CFG_TAG_FILE_VERSION
                not in wData) or (wData[CFG_TAG_FILE_VERSION] != __version__):
            errorMsg = f"Configuration file syntax has changed - unable to set configuration."
            errorMsg += f"\nCurrent version: {__version__}, config file version: {wData[CFG_TAG_FILE_VERSION]}"
            raise Exception(errorMsg)

        try:
            # serial settings
            serialSettings = serComm.SerialCommSettings()
            serialSettings.port = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_PORT]
            serialSettings.baudrate = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_BAUDRATE]
            serialSettings.dataSize = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_DATASIZE]
            serialSettings.stopbits = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_STOPBITS]
            serialSettings.parity = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_PARITY]
            serialSettings.swFlowControl = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_SWFLOWCONTROL]
            serialSettings.hwFlowControl = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_HWFLOWCONTROL]
            serialSettings.readTimeoutMs = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_READTIMEOUTMS]
            serialSettings.writeTimeoutMs = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_WRITETIMEOUTMS]
            self.dataModel.setSerialSettings(serialSettings)

            for channel, data in wData[CFG_TAG_DATA_FIELDS].items():
                self.dataModel.setDataField(int(channel), data)

            for channel, data in wData[CFG_TAG_NOTE_FIELDS].items():
                self.dataModel.setNoteField(int(channel), data)

            for channel, data in wData[CFG_TAG_SEQ_FIELDS].items():
                self.dataModel.setSeqField(int(channel), data)

            self.dataModel.setRxDisplayMode(wData[CFG_TAG_RXLOG])
            self.dataModel.setTxDisplayMode(wData[CFG_TAG_TXLOG])
            self.dataModel.setOutputRepresentationMode(
                wData[CFG_TAG_OUTPUT_REPRESENTATION])
            self.dataModel.setVerboseDisplayMode(
                wData[CFG_TAG_VERBOSE_DISPLAY])

        except Exception as err:
            errorMsg = f"Unable to load configuration from a file: {filePath}"
            errorMsg += f"\nError:\n{err}"
            errorMsg += f"\nFile content:\n{wData}"
            raise Exception(errorMsg)
Exemplo n.º 3
0
def main():
    app = QtWidgets.QApplication(sys.argv)

    initialSerialDialogSettings = serComm.SerialCommSettings()
    initialSerialDialogSettings.swFlowControl = True
    initialSerialDialogSettings.stopbits = serial.STOPBITS_TWO
    initialSerialDialogSettings.dataSize = serial.SIXBITS

    #setupDialog = SerialSetupDialog()
    setupDialog = SerialSetupDialog(initialSerialDialogSettings)
    setupDialog.showDialog()

    ret = app.exec_()
Exemplo n.º 4
0
    def createDefaultConfiguration(self):
        """
        Set instance of data model with default values.
        Will emit signals to update GUI.
        """
        self.dataModel.setSerialSettings(serComm.SerialCommSettings())
        for channel in range(NUM_OF_DATA_CHANNELS):
            self.dataModel.setDataField(channel, '')
            self.dataModel.setNoteField(channel, '')

        for channel in range(NUM_OF_SEQ_CHANNELS):
            self.dataModel.setSeqField(channel, '')

        self.dataModel.setRxDisplayMode(True)
        self.dataModel.setTxDisplayMode(True)
        self.dataModel.setOutputRepresentationMode(OutputRepresentation.STRING)
        self.dataModel.setVerboseDisplayMode(True)
Exemplo n.º 5
0
    def __init__(self, serialSettings: serComm.SerialCommSettings = None):
        """
        Serial settings dialog.
            @param serialSettings: if None, new blank (default settings) are applied. Otherwise, pre-set default given values
        """
        QtWidgets.QDialog.__init__(self)
        self.ui = Ui_SerialSetupDialog()
        self.ui.setupUi(self)

        if serialSettings is None:
            self.dialogSettings: serComm.SerialCommSettings = serComm.SerialCommSettings(
            )
        else:
            self.dialogSettings: serComm.SerialCommSettings = serialSettings

        self.applySettingsOnClose = False

        self.connectSignalsToSlots()

        self.setDialogValues(self.dialogSettings)
Exemplo n.º 6
0
    def loadConfiguration(self, filePath: str):
        """
        Read (load) given json file and set new configuration.
            @param filePath: path to load file from.
        """
        with open(filePath, 'r') as fileHandler:
            wData = json.load(fileHandler)

        if (CFG_TAG_FILE_VERSION
                not in wData) or (wData[CFG_TAG_FILE_VERSION] != __version__):
            errorMsg = f"Configuration file syntax has changed - unable to set configuration."
            errorMsg += f"\nCurrent version: {__version__}, config file version: {wData[CFG_TAG_FILE_VERSION]}"
            raise Exception(errorMsg)

        try:
            serialSettings = serComm.SerialCommSettings()
            serialSettings.port = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_PORT]
            serialSettings.baudrate = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_BAUDRATE]
            serialSettings.dataSize = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_DATASIZE]
            serialSettings.stopbits = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_STOPBITS]
            serialSettings.parity = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_PARITY]
            serialSettings.swFlowControl = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_SWFLOWCONTROL]
            serialSettings.hwFlowControl = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_HWFLOWCONTROL]
            serialSettings.readTimeoutMs = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_READTIMEOUTMS]
            serialSettings.writeTimeoutMs = wData[CFG_TAG_SERIAL_CFG][
                CFG_TAG_SERIAL_CFG_WRITETIMEOUTMS]
            self.dataModel.setSerialSettings(serialSettings)
        except Exception as err:
            errorMsg = f"Unable to set serial settings from a configuration file: {err}"
            self.signals.sigWarning.emit(errorMsg, LOG_COLOR_WARNING)

        try:
            for channel, data in wData[CFG_TAG_DATA_FIELDS].items():
                self.dataModel.setDataField(int(channel), data)

            for channel, data in wData[CFG_TAG_NOTE_FIELDS].items():
                self.dataModel.setNoteField(int(channel), data)

            for channel, data in wData[CFG_TAG_SEQ_FIELDS].items():
                self.dataModel.setSeqField(int(channel), data)
        except Exception as err:
            errorMsg = f"Unable to set data/note/sequence settings from a configuration file: {err}"
            self.signals.sigWarning.emit(errorMsg, LOG_COLOR_WARNING)

        try:
            self.dataModel.setRxDisplayMode(wData[CFG_TAG_RXLOG])
            self.dataModel.setTxDisplayMode(wData[CFG_TAG_TXLOG])
            self.dataModel.setOutputRepresentationMode(
                wData[CFG_TAG_OUTPUT_REPRESENTATION])
            self.dataModel.setRxNewlineMode(wData[CFG_TAG_RX_NEW_LINE])
            self.dataModel.setRxNewlineTimeout(
                wData[CFG_TAG_RX_NEW_LINE_TIMEOUT])
        except Exception as err:
            errorMsg = f"Unable to set log settings from a configuration file: {err}"
            self.signals.sigWarning.emit(errorMsg, LOG_COLOR_WARNING)