Python serial programming example
Python is purely free software, and the source code and interpreter CPython follows the GPL (GNU General Public License) protocol.
Python has a rich and powerful library. It is often nicknamed the glue language and can easily connect various modules made in other languages ​​(especially C/C++). A common application scenario is to use Python to quickly prototype a program (sometimes even the final interface of a program), and then rewrite the parts that have special requirements, such as graphics rendering modules in 3D games. Performance requirements are particularly high, can be rewritten in C / C + +, and then encapsulated as an extension class library that Python can call.
1, the transmission and reception of the stringShort the 2 and 3 pins of the serial port and create a text such as:
Or you can add a few words a little and become your input and print out your typing information.
The value of the read(value) method is the length of the character to be read. If you want to read all, provide two methods:
1) inWaiTIng:: Monitors received characters. inWaitTIng returns the length value of the received string, and then assigns this value to the read parameter.
2) readall():: Read all characters.
2, hexadecimal displayThe essence of the hexadecimal display is to convert the received character gems into their corresponding ASCII codes, and then convert the ASCII code values ​​into hexadecimal numbers for display, so that special characters can be displayed.
A function is defined here, such as hexShow(argv), the code is as follows:
3, hexadecimal transmissionHexadecimal transmission is essentially a string that is sent in hexadecimal format, such as '\xaa', '\x0b'. The point is how to convert a string into a hexadecimal format with two misunderstandings:
1) '\x'+'aa' is not possible, involving the escape character backslash
2) '\\x'+'aa' and r'\x'+'aa' are not allowed. Although the print result is \xaa, the value assigned to the variable is '\\xaa'.
Here we use the decode function,
It should be noted that if the length of the string list is odd, the decode will report an error. You can use the slice operation of the string according to the actual situation, and add a '0' at the beginning or end of the string.
If the serial port assistant sends the string "abc" in hexadecimal, then you do "self.l_serial.write("\x61\x62\x63")" in python.
Of course, there is another way:
The same goal can be achieved.
Semiconductor Plastic Package.Refers to the material whose conductivity is between the conductor and the insulator at room temperature. Semiconductors have a wide range of applications in radios, televisions, and temperature measurement. Diodes are semiconductor devices. Semiconductor refers to a material whose conductivity can be controlled and can range from insulator to conductor. Regardless of technology or economic development, the importance of semiconductors is enormous. Most of today`s electronic products, such as computers, mobile phones or digital recorders, have core units that are very closely related to semiconductors. The common semiconductor materials are silicon, germanium, gallium arsenide, etc., and silicon is a kind of most influential one among various semiconductor materials in commercial applications.
Semiconductor Plastic Package,Semiconductor Package,Silicon Transistor,Bi Directions Thyristor
YANGZHOU POSITIONING TECH CO., LTD. , https://www.yzpst.com