Windows 10 と Java を Eclipse で使用しています。私はプログラミングが初めてで、USB デバイスからデータを読み込む必要があるプロジェクトに取り組んでいます。
LibUsb.open(device, Handle) を実行すると、次のエラーが表示されます: USB エラー 3: USB デバイスを開けません: アクセスが拒否されました (権限が不十分です)
すでにzadigプログラムを実行して他のエラーを修正しましたが、これを回避できないようです. 誰かが私を助けてくれることを願っていますか?
私のコードは以下のとおりです (FindDevice は正常に動作します。結果 = LibUsb.open(device, handle) が実行されたときの結果 = USB エラー 3: USB デバイスを開けません: アクセスが拒否されました (権限が不十分です)
Googleでこれに関する多くの助けを見つけることができませんでした。
public void actionPerformed(ActionEvent arg0) {
//Initialize the libusb
context = new Context();
int result = LibUsb.init(context);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to initialize libusb.", result);
}
//Find the Device on the System
short vendorId = (short)1545;
short productId = (short)797;
Device device = findDevice(vendorId,productId);
DeviceHandle handle = new DeviceHandle();
//Create the DeviceHandle
//Open the Test Device
result = LibUsb.open(device, handle);
if (result != LibUsb.SUCCESS) {
throw new LibUsbException("Unable to open USB device", result);
}
try
{
// Use device handle here
System.out.println("Does this happen?");
//claimDevice(vendorId, productId);
}
finally
{
LibUsb.close(handle);
}
LibUsb.exit(context);
}
public Device findDevice(short vendorId, short productId)
{
// Read the USB device list
DeviceList list = new DeviceList();
int result = LibUsb.getDeviceList(null, list);
if (result < 0) throw new LibUsbException("Unable to get device list", result);
try
{
// Iterate over all devices and scan for the right one
for (Device device: list)
{
DeviceDescriptor descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
if (result != LibUsb.SUCCESS) throw new LibUsbException("Unable to read device descriptor", result);
//Below is only executed when trying to figure out the Vendor ID and Descripter ID.
//System.out.println("VendorID:" + descriptor.idVendor());
//System.out.println("Descripter ID:" + descriptor.idProduct());
if (descriptor.idVendor() == vendorId && descriptor.idProduct() == productId) {
System.out.println("Found Device!");
return device;
}
}
}
finally
{
// Ensure the allocated device list is freed
}
// Device not found
return null;
}