问题描述
我正在尝试使用激光雷达传感器获取处理算法的距离测量值。我想将激光雷达连接到Jupyter笔记本电脑,并尝试使用下面提供的制造商代码建立此连接。在我的笔记本电脑上,激光雷达已连接到COM4端口,但是由于不断出现以下错误,我不确定我是否尝试以正确的方式进行连接:
无法打开端口'/ dev / ttyUSB0':FileNotFoundError(2,'系统 找不到指定的路径。',无
制造商的标准代码:
import serial
print('Running SF30 sample.')
# Make a connection to the com port. USB0 is the first default port assigned to USB serial devices.
serialPortName = '/dev/ttyUSB0'
serialPortBaudrate = 115200
port = serial.Serial(serialPortName,serialPortBaudrate,timeout=0.1)
# Clear buffer of any partial responses.
port.readline()
# Continuously gather distance data.
while True:
# Each reading is contained on a single line.
distanceStr = port.readline()
# Convert the string to a numeric distance value.
try:
splitStr = distanceStr.split(" ")
distance = float(splitStr[0])
except ValueError:
# It is possible that the SF30 does not get a valid signal,we represent this case as a -1.0m.
distance = -1.0
# Do what you want with the distance information here.
print(distance)
我尝试将/ dev / ttyUSB0更改为COM4,并收到以下错误: 无法打开端口“ COM4”:PermissionError(13,'访问被拒绝。',无,5)
关于如何解决此问题的任何想法?
解决方法
除非您能找到一种方法来将USB资源转发到Jupyter示波器,否则恐怕不可能。 Jupyter在某些沙箱环境中运行(通常从特定的文件夹开始),并且不知道/不具有对计算机资源的许可。
您仍然可以在Jupyter外部运行代码并将数据存储在Jupyter文件夹中,然后按常规从Jupyter访问数据。