If you still do not know how to use the Python serial port during the Python application process, you can refer to the following articles to have a correct understanding of the use of the Python serial port, the following is an introduction to the relevant content of the article. I hope you will have some gains.
To use the Python serial port, you must first download the relevant modules:
- 1. pyserial
- 2. pywin32 (http://sourceforge.net/projects/pywin32/)
-
Google "Python serial port operation" keyword, find the relevant python code, send data can be assembled and processed by chr and pack, such:
- snd = ''
- snd += chr(97)
- data = 0x12345678
- snd += pack.('i', data)
- snd += chr(0x64)
- self.l_serial.write(snd);
-
# The sent data is in hexadecimal format: 61 78 56 34 12 64 the received data uses the ord function to convert the byte content into an integer for processing. For example:
- if ord(recv[2])== 0x01:
Determine whether recv [2] is 0x01. Note: This comparison cannot be performed.
- if recv[2] == 'a':
- pass
-
Cannot be compared like this.
- if recv[2] == 0x97:
- pass
-
The above article describes how to use the Python serial port.