我是 javax.usb API 的新手,我的目的是在特定时间禁用 USB 端口以阻止与 USB 设备的通信,然后在一段时间后重新启用它。下面是我获取设备信息并识别要关闭/禁用的端口的代码。我做了一些研究并了解了管道,open(); 和关闭();javax.usb API 中的函数。请帮助我了解如何关闭或禁用 USB 端口。
import java.io.UnsupportedEncodingException;
import java.util.*;
import javax.usb.*;
public class USBDemo1
{
public static void main(String[] args)
throws UsbException, UnsupportedEncodingException, NullPointerException
{
UsbServices services = UsbHostManager.getUsbServices();
UsbHub root = services.getRootUsbHub();
List devices = root.getAttachedUsbDevices();
Iterator iterator = devices.iterator();
if(iterator.hasNext())
{
UsbDevice device = (UsbDevice) iterator.next();
UsbDeviceDescriptor descriptor = device.getUsbDeviceDescriptor();
byte manufacturerCode = descriptor.iManufacturer();
System.out.println("Manufacturer index: " + manufacturerCode);
System.out.println("Manufacturer string: "
+ device.getString(manufacturerCode));
byte productCode = descriptor.iProduct();
System.out.println("Product index: " + productCode);
System.out.println("Product string: " + device.getString(productCode));
byte serialCode = descriptor.iSerialNumber();
System.out.println("Serial number index: " + serialCode);
System.out.println("Serial Number string: " + device.getString(serialCode));
System.out.println("Vendor ID: 0x" + Integer.toHexString(descriptor.idVendor()));
System.out.println("Product ID: 0x"
+ Integer.toHexString(descriptor.idProduct()));
System.out.println("Class: " + descriptor.bDeviceClass());
System.out.println("Subclass: " + descriptor.bDeviceSubClass());
System.out.println("Protocol: " + descriptor.bDeviceProtocol());
}
}
}