1. Python Tools
#coding = Utf-8 ImportPtyImportOSImportSelectdefmkpty (): Master1, slave=pty.openpty () slaveName1=os.ttyname (slave) master2, slave=pty.openpty () slaveName2=os.ttyname (slave)Print '\nslave device names:', slaveName1, SlaveName2returnMaster1, Master2if __name__=="__main__": Master1, Master2=Mkpty () whileTrue:rl, WL, El= Select.select ([Master1, Master2], [], [], 1) forMasterinchRl:data= Os.read (Master, 128) Print "read%d data."%len (data)ifmaster = =Master1:os.write (master2, data)Else: Os.write (Master1, data)
How to use:
Start: Run "Python mkptych.py&" in the terminal so that you can generate a virtual port pair based on the Pty (pseudo terminal), and the two device names will be displayed in the terminal. The two device names can then be used to debug the virtual serial port on this machine.
Close: Use PS to view the PID number of this Python process and kill it.
2. Ubuntu under cutecom image Interface serial debugging tool (reference: 72238546)
(1) Terminal download command: sudo apt-get install cutecom
(2) Open the software through the terminal:sudo cutecom (requires root access, otherwise cannot open the serial port)
(3) in Device, fill in the generated virtual string number/dev/pts/24 and/DEV/PTS/25, input text, click Enter to send the test
3. Python Writing test program
(ref. 78874165, 75107330)
(1) 1. Install pyserial (install serial module)
Here the distinction between Python2 and Python3:
1 sudo apt install python-pip//python22 sudo apt install python3-pip //python3
(2) Then by:
1 pip install pyserial //python22 pip3 install pyserial //python3
(3) test procedure
1 ImportSerial2 fromTimeImportSleep3 4 defrecv (serial):5 whileTrue:6data =Serial.read_all ()7 ifdata = ="':8 Continue9 Else:Ten Break OneSleep (0.02) A returnData - - if __name__=='__main__': theserial = serial. Serial ('COM5', 9600, timeout=0.5)#/dev/ttyusb0 - ifSerial.isopen (): - Print("Open Success") - Else : + Print("Open Failed") - + whileTrue: Adata =recv (serial) at ifData! = B"' : - Print("Receive:", data) -Serial.write (data)#Data Writeback
Reference article: 80624019
51996613
78874165
Note: Solve Importerror:no module named ' Serial ' problem
75107330
Using virtual serial port for development testing under Ubuntu