我是javax.usb API的新手,我打算在特定时间禁用usb-port,以阻止与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());
}
}
}
答案 0 :(得分:0)
安装devcon应用程序。使用批处理文件中的“devcon remove”命令删除特定的usb键盘,然后使用java代码执行批处理文件。现在键盘在运行“devcon rescan”命令之前不会收到任何数据。