Reputation: 59
We have a SpringBoot3 app that communicates with virtual UART port via USB. App runs just fine as a JAR, however, there are strange issues we face once it gets compiled to a native .exe using GraalVM. Some methods of usb4java work fine, some work only partially and one method even causes a segfault.
For example,
Context context = new Context();
int result = LibUsb.init(context);
will result in
java.lang.UnsupportedOperationException: null not supported as key!
while calling it as
LibUsb.init(null);
will work just fine,
list = new DeviceList();
result = LibUsb.getDeviceList(context, list);
works alright, as well as
Version version = LibUsb.getVersion();
however, calling
descriptor = new DeviceDescriptor();
result = LibUsb.getDeviceDescriptor(device, descriptor);
causes segfault right away. Once again, none of this happens given app is run as jar.
Was able to find very little info on that issue on the Internets.
Upvotes: 0
Views: 58
Reputation: 59
Looks like have it sorted. All these glitches happen because of missing method fields in jni-config.json, once
{
"name":"org.usb4java.Context",
"fields":[{"name":"contextPointer"}]
},
{
"name":"org.usb4java.Device",
"fields":[{"name":"devicePointer"}],
"methods":[{"name":"<init>","parameterTypes":[] }]
},
{
"name":"org.usb4java.DeviceDescriptor",
"fields":[{"name":"deviceDescriptorBuffer"}, {"name":"deviceDescriptorPointer"}]
},
{
"name":"org.usb4java.DeviceList",
"fields":[{"name":"deviceListPointer"}, {"name":"size"}]
},
added, the problem's gone.
Upvotes: 0