java usberror: javax.usb.UsbPlatformException
UsbPlatformException -> класс org.usb4java.javax.Services не имеет необходимого конструктора
в javax.usb.UsbHostManager.initialize(UsbHostManager.java:46)
- в javax.usb.UsbHostManager.getUsbServices(UsbHostManager.java:24)
- в MissileLauncher.main(MissileLauncher.java:160)
Пожалуйста, помогите мне решить это. прикрепил код
public class MissileLauncher
{
private static final short VENDOR_ID = 0x03eb;
private static final short PRODUCT_ID = 0x6124;
private static final byte[] INIT_A = new byte[] { 85, 83, 66, 67, 0, 0, 4,0 };
private static final byte[] INIT_B = new byte[] { 85, 83, 66, 67, 0, 64, 2,0 };
private static final int CMD_UP = 0x01;
private static final int CMD_DOWN = 0x02;
private static final int CMD_LEFT = 0x04;
private static final int CMD_RIGHT = 0x08;
private static final int CMD_FIRE = 0x10;
public static UsbDevice findMissileLauncher(UsbHub hub)
{
System.out.println("------9");
UsbDevice launcher = null;
for (UsbDevice device: (List<UsbDevice>) hub.getAttachedUsbDevices())
{
if (device.isUsbHub())
{
launcher = findMissileLauncher((UsbHub) device);
if (launcher != null)
return launcher;
}
else
{
UsbDeviceDescriptor desc = device.getUsbDeviceDescriptor();
if (desc.idVendor() == VENDOR_ID && desc.idProduct() == PRODUCT_ID)
System.out.println("VENDOR_ID");
return device;
}
}
return null;
}
public static void sendMessage(UsbDevice device, byte[] message)
throws UsbException
{
UsbControlIrp irp = device.createUsbControlIrp(
(byte) (UsbConst.REQUESTTYPE_TYPE_CLASS |
UsbConst.REQUESTTYPE_RECIPIENT_INTERFACE), (byte) 0x09,
(short) 2, (short) 1);
irp.setData(message);
device.syncSubmit(irp);
}
public static void sendCommand(UsbDevice device, int command)
throws UsbException
{
byte[] message = new byte[64];
message[1] = (byte) ((command & CMD_LEFT) > 0 ? 1 : 0);
message[2] = (byte) ((command & CMD_RIGHT) > 0 ? 1 : 0);
message[3] = (byte) ((command & CMD_UP) > 0 ? 1 : 0);
message[4] = (byte) ((command & CMD_DOWN) > 0 ? 1 : 0);
message[5] = (byte) ((command & CMD_FIRE) > 0 ? 1 : 0);
message[6] = 8;
message[7] = 8;
sendMessage(device, INIT_A);
sendMessage(device, INIT_B);
sendMessage(device, message);
}
public static char readKey()
{
try
{
String line =
new BufferedReader(new InputStreamReader(System.in)).readLine();
if (line.length() > 0) return line.charAt(0);
return 0;
}
catch (IOException e)
{
throw new RuntimeException("Unable to read key", e);
}
}
public static void main(String[] args) throws UsbException
{
System.out.println("///////////");
UsbDevice device = findMissileLauncher(UsbHostManager.getUsbServices().getRootUsbHub());
System.out.println("///////////");
if (device == null)
{
System.err.println("Missile launcher not found.");
System.exit(1);
return;
}
UsbConfiguration configuration = device.getUsbConfiguration((byte) 1);
UsbInterface iface = configuration.getUsbInterface((byte) 1);
iface.claim(new UsbInterfacePolicy()
{
public boolean forceClaim(UsbInterface usbInterface)
{
return true;
}
});
System.out.println("WADX = Move, S = Stop, F = Fire, Q = Exit");
boolean exit = false;
while (!exit)
{
System.out.print("> ");
char key = readKey();
switch (key)
{
case 'w':
sendCommand(device, CMD_UP);
break;
case 'x':
sendCommand(device, CMD_DOWN);
break;
case 'a':
sendCommand(device, CMD_LEFT);
break;
case 'd':
sendCommand(device, CMD_RIGHT);
break;
case 'f':
sendCommand(device, CMD_FIRE);
break;
case 's':
sendCommand(device, 0);
break;
case 'q':
exit = true;
break;
default:
}
}
System.out.println("Exiting");
}
}