【发布时间】:2018-10-24 10:19:15
【问题描述】:
环境
Windows Subsystem for Linux与 GPS 进行串行通信。Adafruit GPS 连接到连接到
COM10的 Arduino Nano。在Windows Subsystem for Linux中,这相当于/dev/ttyS10要求:
pyserial
我编写了一个简单的脚本来从 GPS 模块读取信息:
import serial
def select_sentence():
""" This function sends serial data to the GPS module to display only GPGGA and GPRMC"""
def read_gps():
ser = serial.Serial("/dev/ttyS10", 9600)
while True:
print(ser.readline().decode('utf-8'))
if __name__ == "__main__":
select_sentence()
read_gps()
在 virtualenv 中,我选择了Python3,当我执行它时,我得到了Permission Error 用于串行端口/ttyS10,所以我选择sudo chmod 666 /dev/ttyS10 来使用virtualenv 中的脚本。
但是,为了避免PermissionErrors,是否有上述chmod /dev/serial 的替代方法?
我知道,即使在 virtualenv 中使用 sudo 时,也不会考虑安装在 virtualenv 中的软件包,而是 sudo 会查找您的全局 pip 软件包。
【问题讨论】:
标签: python python-3.x virtualenv