该程序实现的功能是:两个线程通过 UART 串口协议进行通信,发送比特的时间间隔为 1s,虚拟时钟为 4hz。线程在收到数字后加 1 重新发送,直到接收的数字大于 3 为止。
直接使用 Python
运行即可:
python port.py
你会看到:
computer2: start receive
computer1: start send 1
computer1: end send
computer1: start receive
computer2: end receive 1
computer2: start send 2
computer2: end send
computer2: start receive
computer1: end receive 2
computer1: start send 3
computer1: end send
computer1: start receive
computer2: end receive 3
computer2: start send 4
computer2: end send
computer1: end receive 4