0
我是javax.usb API的新手,我的目的是在特定時間禁用USB端口,以阻止與USB設備的通信,並在一段時間後重新啓用它。以下是我獲取設備信息並識別關閉/禁用端口的代碼。我做了一些研究並瞭解了管道,open();和close();函數在javax.usb API中。請幫助我如何關閉或禁用USB端口。禁用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());
}
}
}
你究竟想在這裏做什麼?就像,你期待什麼結果「關閉或禁用USB端口」? – duskwuff
@duskwuff在上面的代碼中,我只是獲取有關連接到USB端口的設備的信息(以確定要禁用哪個端口)。我期望禁用USB端口的結果是阻止/關閉與特定設備的通信。 –
@Tdorno像我之前說過的,我是javax.usb API的新手。所以我希望能得到一個關於如何接近它的方向。我試着用close()函數關閉管道。 –