【发布时间】:2019-12-18 05:32:33
【问题描述】:
我目前有一个从串行设备获取提要的脚本。
feed.py
from serial import Serial
ser = Serial('COM27', 9600, timeout=5)
def scrape():
while True:
raw = ser.readline()
raw = raw.decode('utf-8')
if raw == "":
pass
else:
print(raw)
#print (raw.decode('utf-8'))
scrape()
我现在想做的是从其他 python 脚本访问该提要。 我确实尝试使用 SimpleXMLRPCServer 但无法获得输出
feed.py
from serial import Serial
from xmlrpc.server import SimpleXMLRPCServer
ser = Serial('COM27', 9600, timeout=5)
def scrape():
while True:
raw = ser.readline()
raw = raw.decode('utf-8')
if raw == "":
pass
else:
print(raw)
try:
server = SimpleXMLRPCServer(("localhost", 8000), allow_none=True)
server.register_function(scrape)
server.serve_forever()
except Exception as e:
print(e)
listener.py
import xmlrpc.client
feed = xmlrpc.client.ServerProxy('http://localhost:8000')
print(feed.scrape())
监听器脚本没有输出
【问题讨论】:
标签: python python-3.x xml-rpc pyserial