我使用的是 Raspberry Pi 2 板,并且已将 Nonin Xpod PulseOxy 传感器连接到它。我在 python 脚本中使用 PyUSB 模块来访问传感器的基本数据,如供应商 ID、产品 ID 等。我无法设置设备的配置并继续收集读数。我尝试安装 http://www.ftdichip.com/ 提供的 ftdi 驱动程序对于树莓派。但 d2xx 模块没有导入到我的 python 脚本中。 我是为设备编写代码的新手。请帮助我了解如何继续。
我厌倦了以下内容:
import usb.core
import usb.util
dev = usb.core.find(idVendor=0x0424, idProduct=0x9514)
dev.set_configuration()
我在设置配置时遇到错误。
Traceback (most recent call last):
File "s1.py", line 18, in <module>
main()
File "s1.py", line 13, in main
dev.set_configuration()
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 799, in set_configuration
self._ctx.managed_set_configuration(self, configuration)
File "/usr/local/lib/python2.7/dist-packages/usb/core.py", line 128, in managed_set_configuration
self.backend.set_configuration(self.handle, cfg.bConfigurationValue)
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py", line 439, in set_configuration
_check(_lib.usb_set_configuration(dev_handle, config_value))
File "/usr/local/lib/python2.7/dist-packages/usb/backend/libusb0.py", line 380, in _check
raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] could not set config 1: Device or resource busy
传感器的数据表为 Nonin Xpod 3012LP
首先感谢您的回答。我尝试了 libftd2XX 安装,在使用命令 make -B
for n in BitMode EEPROM/erase EEPROM/read EEPROM/write EEPROM/user/read EEPROM/user/size EEPROM/user/write Events LargeRead MultiThread SetVIDPID Simple Timeouts ; do make -C $n || exit 1; done
make[1]: Entering directory '/home/pi/iiitd/release/examples/BitMode'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/BitMode'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/erase'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/erase'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/read'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/read'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/write'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/write'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/user/read'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/user/read'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/user/size'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/user/size'
make[1]: Entering directory '/home/pi/iiitd/release/examples/EEPROM/user/write'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/EEPROM/user/write'
make[1]: Entering directory '/home/pi/iiitd/release/examples/Events'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/Events'
make[1]: Entering directory '/home/pi/iiitd/release/examples/LargeRead'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory '/home/pi/iiitd/release/examples/LargeRead'
make[1]: Entering directory '/home/pi/iiitd/release/examples/MultiThread'
gcc main.c -o multi -Wall -Wextra -L. -lftd2xx -Wl,-rpath /usr/local/lib
/usr/bin/ld: /tmp/ccStfEVz.o: undefined reference to symbol 'pthread_join@@GLIBC_2.4'
//lib/arm-linux-gnueabihf/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: ld returned 1 exit status
Makefile:9: recipe for target 'multi' failed
make[1]: *** [multi] Error 1
make[1]: Leaving directory '/home/pi/iiitd/release/examples/MultiThread'
Makefile:11: recipe for target 'subdirs' failed
make: *** [subdirs] Error 1
最佳答案
我还没有使用过 Nonin Xpod PulseOxy 传感器,但现在还不清楚它的接口(interface)。如果有用于通信的数据表,请发布。
如果设备显示为虚拟 com 端口,则 Raspberry PI 应该已准备好来自 Python 的库,pySerial应该可以。
如果您需要使用 FTDI D2XX 库,请首先安装 native library first (直接链接)。详情可查询here并查看 readme ,尤其是这部分:
> If the message "FT_Open failed" appears:
> Perhaps the kernel automatically loaded another driver for the
> FTDI USB device.
>
> `sudo lsmod`
>
> If "ftdi_sio" is listed:
> Unload it (and its helper module, usbserial), as follows.
>
> `sudo rmmod ftdi_sio`
> `sudo rmmod usbserial`
>
> Otherwise, it's possible that libftd2xx does not recognise your
> device's Vendor and Product Identifiers. Call FT_SetVIDPID before
> calling FT_Open/FT_OpenEx/FT_ListDevices.
我发现 Raspberry PI 默认加载 ftdi_sio 和 usbserial 驱动程序,因此必须先禁用这些驱动程序,然后才能使用 D2XX 库列出 FTDI 设备和详细信息。确保您可以首先编译他们的示例(库已正确链接)并运行他们的示例(您会看到列出的 FTDI 设备以及详细信息(例如 VID/PID/等))。只需导航到示例文件夹并使用 make -b
即可。
请注意,您可能需要以 sudo 身份运行它们。
如果上述操作正常,剩下的就是安装 D2XX 库的 Python 绑定(bind)。我用过这些ftd2xx Python bindings 。设置应该很简单。如果出现错误,请检查 ftd2xx 是否在正确的路径中查找 .so 文件 (/usr/local/lib/libftd2xx.so
)
安装完成后,您可以尝试先列出您的设备:
import ftd2xx
print ftd2xx.listDevices()
更新
看起来只有一个示例存在错误,这取决于 pthreads 库。我现在尝试安装 ftd2xx python 库。 令人困惑的部分是普通串行应该可以工作:
"Green Wire = Serial Output: 9600 Baud, 8 data bits, One Start bit (Start bit =0), One Stop bit (Stop bit = 1), No Parity."
您应该尝试使用串行库简单地读取数据:
import serial,time
def stringAsHex(s):
return ":".join("{:02x}".format(ord(c)) for c in s)
sensor = serial.Serial('/dev/ttyACM0',timeout=1)#should default to 9600, 8 data bits, 1 stop bit, but feel free to use the constructor arguments to configure it
while True:
data = sensor.read()
if len(data) > 0:
print "data str:",data,"hex:",stringAsHex(data)
请务必阅读有关 3.8v 至 3.3v 转换以及基于所使用电阻器的不同数据格式的说明(位于数据表的第 3 页和第 4 页)。
注意我使用的端口 (/dev/ttyACM0
):这通常是新的 Arduino 端口显示的样子。您必须检查您的设备是什么(可能显示为 /dev/ttyUSB0
,在连接设备之前和之后执行 ls/dev/tty*
到 USB 端口)。
关于python - 如何将数据从 Nonin Xpod PulseOxy 传感器获取到 Raspberry Pi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31290808/