Processing中如何判断Serial COM是USB还是Bluetooth?
How to tell if Serial COM is USB or Bluetooth in Processing?
我有一个可以通过 USB 和蓝牙连接的设备,但是如果它是蓝牙或 USB,发送到此设备的就绪消息会有所不同。
就绪消息作为字节数组发送,其中第二个元素不同,其中 0x01 用于 USB,0x02 用于蓝牙。
Serial serial = Serial(s, Serial.list()[0], BAUD_RATE);
byte[] message = new byte[3];
byte[0] = 0x01;
byte[0] = 0x01; // 0x02 for bluetooth
byte[0] = 0x12;
serial.write(message);
我想让我的代码根据用户使用的内容动态工作,所以如果 usb 不工作,则测试蓝牙,如果不工作,则打印错误消息。
我环顾四周,但找不到任何方法来检测 COM 端口是否在处理中是蓝牙的。在 Processing 中是否有可靠的方法来对此进行测试?
Processing Serial library doesn't expose any functionality to provide details about the device itself. If you already know the Vendor ID (VID) and Product ID (PID) of these devices, on Windows you can try something like this.
我个人使用 Python PySerial's ListPortInfo 来完成相关任务。
如果上面的代码是您 运行 所需的全部串行代码,您可以使用 Python Pyserial 脚本轻松完成检查端口信息并写入这些字节
如果您真的需要使用 Processing,要么寻找可以提供此信息的串行甚至 USB Java 库,要么通过 exec() 从 Processing 调用 Python
我有一个可以通过 USB 和蓝牙连接的设备,但是如果它是蓝牙或 USB,发送到此设备的就绪消息会有所不同。
就绪消息作为字节数组发送,其中第二个元素不同,其中 0x01 用于 USB,0x02 用于蓝牙。
Serial serial = Serial(s, Serial.list()[0], BAUD_RATE);
byte[] message = new byte[3];
byte[0] = 0x01;
byte[0] = 0x01; // 0x02 for bluetooth
byte[0] = 0x12;
serial.write(message);
我想让我的代码根据用户使用的内容动态工作,所以如果 usb 不工作,则测试蓝牙,如果不工作,则打印错误消息。
我环顾四周,但找不到任何方法来检测 COM 端口是否在处理中是蓝牙的。在 Processing 中是否有可靠的方法来对此进行测试?
Processing Serial library doesn't expose any functionality to provide details about the device itself. If you already know the Vendor ID (VID) and Product ID (PID) of these devices, on Windows you can try something like this.
我个人使用 Python PySerial's ListPortInfo 来完成相关任务。 如果上面的代码是您 运行 所需的全部串行代码,您可以使用 Python Pyserial 脚本轻松完成检查端口信息并写入这些字节
如果您真的需要使用 Processing,要么寻找可以提供此信息的串行甚至 USB Java 库,要么通过 exec() 从 Processing 调用 Python