我发现,这部法律适用于使用序列港口进行通信的简单聊天,我希望看到它发挥作用。 由于我没有电缆,但现在我 st忙,不知道如何实际开展这项工作,我发现 com0com模拟RS-232的连接。
法典(在座):
from serial import *
from threading import Thread
class Receiver(Thread):
def __init__(self, serialPort):
Thread.__init__(self)
self.serialPort = serialPort
def run(self):
text = ""
while (text != "exit
"):
text = serialPort.readline()
print ("
machine1: " + text)
self.serialPort.close()
class Sender(Thread):
def __init__(self, serialPort):
Thread.__init__(self)
self.serialPort = serialPort
def run(self):
text = ""
while(text != "exit
"):
text = raw_input("Type your message>>") + "
"
self.serialPort.write(text)
self.serialPort.close()
serialPort = Serial("\\.\CNCA0")
send = Sender(serialPort)
receive = Receiver(serialPort)
send.start()
receive.start()
提前感谢。