在服务器自动化测试开发中,服务器sut是如何跟host主机进行通信的?网络通信就不多说了,这里说说如何用串口实现
将usb to console线(一端usb口,插host,一端类似网口,接sut)接到sut和host之间,host上device manager的port里会多个com口,如com100,这样sut就可以通过自身的com1或com2跟host插入usb to console后的com100口进行通信了
Host端
import serial import threading from multiprocessing import Process import sys import os port="COM100" bps = 115200 timex=5 ser = serial.Serial(port,bps,timeout=timex) def thread_recv(name): while True: if ser.in_waiting > 0: print(ser.in_waiting) data = ser.read(1024) print("[{}] recv data:{}".format(name,data)) if __name__ == '__main__': print ("main process start to end data; process start to recv data") # t_Recv = threading.Thread(target=thread_recv,args=("Thread Recv ",)) p_Recv = Process(target=thread_recv, args=("Process Recv ",)) p_Recv.daemon=True p_Recv.start() while True: data = raw_input("[{}] Input the data that you want to send:") if data == "exit": break ret = ser.write(bytes(data)) print ("Send {} bytes {}".format(ret,data)) p_Recv.join() print ("main thread ended")
这样一来sut和host就可以通过串口进行通信了
虽然已经有完善的框架了,但是了解下底层是如何通过串口进行通信的还是很有必要的!
问题,SUT上刚开始用的是多进程,但是子进程不执行,所以换成了多线程,另外两端的脚本的串口读写同步还得再优化下。
标签:data,通信,host,sut,串口,print,服务器,Recv From: https://www.cnblogs.com/pfeiliu/p/17192133.html