Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何连接Jupyter笔记本中的Usb端口?_Python_Jupyter Notebook_Serial Port_Usb - Fatal编程技术网

Python 如何连接Jupyter笔记本中的Usb端口?

Python 如何连接Jupyter笔记本中的Usb端口?,python,jupyter-notebook,serial-port,usb,Python,Jupyter Notebook,Serial Port,Usb,我正在尝试使用激光雷达传感器获取距离测量值,以便进行处理算法。我想将激光雷达连接到jupyter笔记本电脑,并尝试使用下面提供的制造商代码进行连接。在我的笔记本电脑上,激光雷达连接在COM4端口,但我不完全确定我是否尝试以正确的方式连接,因为我不断收到以下错误: 无法打开端口“/dev/ttyUSB0”:FileNotFoundError(2),“系统错误” 找不到指定的路径。“,无 制造商提供的标准代码: import serial print('Running SF30 s

我正在尝试使用激光雷达传感器获取距离测量值,以便进行处理算法。我想将激光雷达连接到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 scope的方法,否则恐怕这是不可能的。 Jupyter正在某些沙盒环境中运行(通常从特定文件夹开始),并且不知道/拥有对计算机资源的权限

您仍然可以在Jupyter之外运行代码,并将数据存储在Jupyter文件夹中,然后定期从Jupyter访问它