目前我正在为大学做一个项目,我必须创建一个程序来控制玻璃容器中的湿度。为此,我有一个湿度计。
首先程序必须从湿度计导入原始数据,但我不知道它是如何工作的。文档说它有一个 USB 接口,但我只能找到解析原始数据的方法。我还给销售这个湿度计的公司写了一封电子邮件。他们说有一个外部软件可以导入和处理这些数据。但是我不允许使用外部软件。因此我不得不直接从 USB 端口读取原始数据。我尝试使用 usb4java,但我只能找到所有连接的 USB 设备。我不知道该怎么做。请帮助我 文档 文档
下面的代码
public class DumpDevices
{
/**
* Dumps the specified USB device to stdout.
*
* @param device
* The USB device to dump.
*/
private static void dumpDevice(final UsbDevice device)
{
// Dump information about the device itself
System.out.println(device);
final UsbPort port = device.getParentUsbPort();
if (port != null)
{
System.out.println("Connected to port: " + port.getPortNumber());
System.out.println("Parent: " + port.getUsbHub());
}
// Dump device descriptor
System.out.println(device.getUsbDeviceDescriptor());
// Process all configurations
for (UsbConfiguration configuration: (List<UsbConfiguration>) device
.getUsbConfigurations())
{
// Dump configuration descriptor
System.out.println(configuration.getUsbConfigurationDescriptor());
// Process all interfaces
for (UsbInterface iface: (List<UsbInterface>) configuration
.getUsbInterfaces())
{
// Dump the interface descriptor
System.out.println(iface.getUsbInterfaceDescriptor());
// Process all endpoints
for (UsbEndpoint endpoint: (List<UsbEndpoint>) iface
.getUsbEndpoints())
{
// Dump the endpoint descriptor
System.out.println(endpoint.getUsbEndpointDescriptor());
}
}
}
System.out.println();
// Dump child devices if device is a hub
if (device.isUsbHub())
{
final UsbHub hub = (UsbHub) device;
for (UsbDevice child: (List<UsbDevice>) hub.getAttachedUsbDevices())
{
dumpDevice(child);
}
System.out.println(hub);
}
}
/**
* Main method.
*
* @param args
* Command-line arguments (Ignored)
* @throws UsbException
* When an USB error was reported which wasn't handled by this
* program itself.
*/
public static void main(final String[] args) throws UsbException
{
// Get the USB services and dump information about them
final UsbServices services = UsbHostManager.getUsbServices();
System.out.println("USB Service Implementation: "
+ services.getImpDescription());
System.out.println("Implementation version: "
+ services.getImpVersion());
System.out.println("Service API version: " + services.getApiVersion());
System.out.println();
// Dump the root USB hub
dumpDevice(services.getRootUsbHub());
}