![]() ![]() '''Prompt Serial Port Open Status Information''' The signal slot code is as follows: def messageUI(self): After compiling the signal slot code, the button and the signal slot are correlated. ![]() Two buttons need to be added to the signal slot. In the layout management above, two buttons, Open and Send, are added. Self.open_(self.Check_serial) #Associate the Open button with the signal slot (self.Cosender) #Connect the "Send" button with the signal slot Grid.addWidget(self.datareviewEdit, 4, 1, 1, 6) Grid.addWidget(self.datasenderEdit, 3, 1, 1, 6) Grid.addWidget(self.datanumberEdit, 2, 1) Grid.addWidget(self.portname, 1, 0) #Location of add controls Self.datareview = QLabel("Receiving data:") Self.datanumber = QLabel("Send data bits:") Self.portname = QLabel("Port number") #add controls Using PyQt5 library to build the interface, using grid layout management QGridLayout in the interface layout, the code is as follows: def initUI(self): T1 = threading.Thread(target=mSerial.read_data) MSerial = SerialPort(serialPort, baudRate) ![]() The reference code is as follows: import serialÄata = input("Please enter the data to be sent (non-Chinese) and receive the data at the same time.: ") Similarly, the received data can be received by strings first, and then transmitted by hexadecimal system. In this paper, string sending is realized first, and then hexadecimal sending is realized later. The way of sending data is input sending. The sending data type can be divided into string sending and hexadecimal sending. Later ports and baud rates become optional In this way, the serial port is simply set to COM4 when the serial port is opened, the baud rate is 9600, and COM4 is the computer port used by the author. The reference codes are as follows: self.t = serial.Serial('com4', 9600) When the author designs, a serial port is fixed as COM4 and baud rate is 9600. Fixed serial port and baud rate can be selected to design first. It is suggested that the first edition of serial assistant be made. In the design of serial assistant, the main body is to obtain serial ID number, set baud rate, send and receive data, add interface layout, signal trigger and other operations. Thought: Make the main body first, optimize and add other functions slowly. Objectives: Write a simple serial assistant in PythonÄ®nvironment: Win10, python, PyQt5, Pycharm Upper computer, lasted a month, finally wrote a simple serial assistant, the author's own software, some Bug, to share, for reference only, welcome to learn and discuss together. ![]() If you can write the software of serial assistant, you can write one by yourself. Using serial assistant is the most direct way of communication, but serial assistant is not suitable for PC. It has always wanted to use PC to transmit data between PC and SCM. STM32 has been studying SCM for a long time, and has also done some projects. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |