【发布时间】:2016-01-21 23:57:46
【问题描述】:
我有两个串行端口将数据输入 Python。 一个是馈送 GPS 字符串(大约每秒 4 行) 以及来自气体监视器的其他馈送数据字符串(大约每秒 1 行)
我想同时监控 gps 和 gas feed,并实时合并数据。我只需要通过串口接收数据frpm。
我的问题是我似乎无法弄清楚如何让两个 python 函数同时运行。
我安装了 Python 2.7 的线程模块和多处理模块。
关于组合串行信息的好方法有什么想法吗?这是我的第三个 Python 程序,所以请对我温柔:-)
代码如下:
import threading
import multiprocessing
def readGas():
global GAScount
global GASline
while GAScount<15:
GASline = gas.readline()
GasString = GASline.startswith('$')
if GasString is True:
print GASline
GAScount = GAScount+1
def readGPS():
global GPScount
global GPSline
while GPScount<50:
GPSline = gps.readline()
GPSstring = GPSline.startswith('$')
if GPSstring is True:
print GPSline
GPScount = GPScount+1
openGPS()
openGas()
【问题讨论】:
标签: serial-port python-multithreading python-multiprocessing