Closed oliverlan closed 8 years ago
Can you paste the complete stack trace here please.
C:\Users\Leo\Desktop\JavaTest\purejavahidapi-master\purejavahidapi-master\exampl
e>java -cp .;..\bin\purejavahidapi.jar;..\lib\jna-4.0.0.jar Example2
vid=4df, pid=30...., wanted 4df, 30java.lang.IllegalArgumentException: Allocatio
n size must be greater than zero
at com.sun.jna.Memory.
Here is the source code:
public static void main(String[] args) {
try {
List
}
}
Hi,
looking at the code it looks to me that you have device that has no output reports and hence the length of the report is zero which cause the JNA memory allocation to fail. Without testing it looks to me that a simple fix would be to change the line 94 (in purejavahidapi.windows.HidDevice) to:
m_OutputReportMemory = new Memory(m_OutputReportLength+1);
This will always allocate one extra byte which should have no ill consequences but should let the code run past that point.
I will add that to the code but that will take some time. If you make work and create a pull request I'm happy to merge it.
From the Ellisys USB sniffer, we got following descriptor data (34bytes)
configuration descriptor: (all hex)
GetDescriptor (Configuration) 1 0 OK FS 34 bytes (09 02 22 00 01 01 05 80 64 09 04 00 00 01 03 00 00 06 09 21 10 01 00 01 22 D0 00 07 05 81 03 08 00 0A)
Which has Hid descriptor with Report type 0x22, length 0x00D0
ENdPoint descripotr 0x81, interrupt type 0x03, maxpacketsize 0x0008, interval 0x0A
I don't know what Output Report you were referring to, could you explore it more? Thanks
Well I assumed the device had no output reports because a few lines up in the code you see:
m_OutputReportLength = caps.OutputReportByteLength;
where 'caps' comes from a Windows API call and obviously m_OutputReportLength is zero when you get the
has runtime error IllegalArgumentException: Allocatation size must be greater than zero.
but maybe that was a wrong conclusion and the actual problem is that call that is used to get the caps is wrong. Can't really investigate this atm as I have no hardware suitable for this task.
I am confirmed that the HidP_GetCaps() return cpas with OutputReportByLength is 0 for my device. Now what is command to rebuild the purejavahidapi.jar file?
I've got simple Ant-file for it but for some reason I cannot push it atm. Need to sort that out as I've got some other fixes too to push.
oliverlan wrote:
I am confirmed that the HidP_GetCaps() return cpas with OutputReportByLength is 0 for my device. Now what is command to rebuild the purejavahidapi.jar file?
Reply to this email directly or view it on GitHub: https://github.com/nyholku/purejavahidapi/issues/8#issuecomment-93840480
I just pushed the ant file (and some other changes, unfortunately my Windows set up is not usable for testing atm so I could not test them.)
I modified the PurejavaHidApi.java from m_OutputReportLength = caps.OutputReportByteLength; to m_OutputReportMemory = new Memory(m_OutputReportLength+1); and then run ant -buildfile buildjars.xml The modified Example2 program can open our device and get the HID interrupt data on WIndows. Now need to test it on Mac
I have downloaded the jar and am having the same problem as oliverlan. He seems to have soved it. How do I get a jar that incorporates the solution. I am new to github and find it extremely confusing.
abg
The jars are not available ATM, just download the source and use them directly or spin your own jars, standard Java stuff. I will be making the jars available when I have time.
Hi - I have spent all day on this and am getting nowhere. I have downloaded purejavahidapi-master.zip and expanded this. I created a Netbeans library project called purejavahidapi and moved the files into this project. I then built this project and got a purejavahidapi.jar which I thencopied into my project, replacing the one previously downloaded from your site. Still got the error on line 94 of purejavehidapi.windows.HidDevice. The program in that area (lines 92-96) reads:
}
m_OutputReportLength = caps.OutputReportByteLength ;
m_OutputReportMemory = new Memory(m_OutputReportLength );
m_OutputReportOverlapped = new OVERLAPPED();
m_OutputReportBytesWritten = new int[] { 0 };
I have tried changing this as suggested above to no avail. There is curious behaviour - even if I put in blank lines moving this block down, the error is always reported as being on line 94. The stack trace is
java.lang.IllegalArgumentException: Allocation size must be greater than zero
at com.sun.jna.Memory.
I hope that you can sort this out as others seem to have got it working
Alex
Alex,
m_OutputReportLength = caps.OutputReportByteLength+1;
will solve the problem, please give it a try.
Oliver
From: AlexBGar [mailto:notifications@github.com] Sent: Tuesday, June 30, 2015 9:31 AM To: nyholku/purejavahidapi Cc: oliverlan Subject: Re: [purejavahidapi] sample2 crash on Windows (#8)
Hi - I have spent all day on this and am getting nowhere. I have downloaded purejavahidapi-master.zip and expanded this. I created a Netbeans library project called purejavahidapi and moved the files into this project. I then built this project and got a purejavahidapi.jar which I thencopied into my project, replacing the one previously downloaded from your site. Still got the error on line 94 of purejavehidapi.windows.HidDevice. The program in that area (lines 92-96) reads:
}
m_OutputReportLength = caps.OutputReportByteLength ;
m_OutputReportMemory = new Memory(m_OutputReportLength );
m_OutputReportOverlapped = new OVERLAPPED();
m_OutputReportBytesWritten = new int[] { 0 };
I have tried changing this as suggested above to no avail. There is curious behaviour - even if I put in blank lines moving this block down, the error is always reported as being on line 94. The stack trace is
java.lang.IllegalArgumentException: Allocation size must be greater than zero at com.sun.jna.Memory.(Memory.java:87) at purejavahidapi.windows.HidDevice.(HidDevice.java:94) at purejavahidapi.windows.WindowsBackend.openDevice(WindowsBackend.java:237) at purejavahidapi.PureJavaHidApi.openDevice(PureJavaHidApi.java:97) at purejavahid.IOHID.findMyDevice(IOHID.java:40)
I hope that you can sort this out as others seem to have got it working
Alex
— Reply to this email directly or view it on GitHub https://github.com/nyholku/purejavahidapi/issues/8#issuecomment-117246478 . https://github.com/notifications/beacon/AGa4yv0EMoieEYLQo-1lQgGo629d_83cks5oYru9gaJpZM4EArZH.gif
Don't use the jars, they are not uptodate.
Hi I think my problems yesterday were caused by Netbeans. Things are working more rationally this morning. I got passed the OutputReportLength problem only to encounter a problem with InputReportLength.
The line has been changed to
m_InputReportMemory = new Memory(m_InputReportLength + 1);
I can move on now and see if I can get the whole thing to work. Thanks for your help
Alex
I'm getting the same thing on mac
/tmp/pur/example(master*)❯ java -cp ../target/purejavahidapi-0.0.1.jar:../lib/jna-4.0.0.jar:. Example2
java.lang.IllegalArgumentException: Allocation size must be greater than zero at com.sun.jna.Memory.(Memory.java:88) at purejavahidapi.macosx.HidDevice. (HidDevice.java:96) at purejavahidapi.macosx.MacOsXBackend.openFromPath(MacOsXBackend.java:117) at purejavahidapi.macosx.MacOsXBackend.openDevice(MacOsXBackend.java:77) at purejavahidapi.PureJavaHidApi.openDevice(PureJavaHidApi.java:96) at Example2.main(Example2.java:20)```
Not heard from this since, so I'm closing this, please feel free to re-open if necessary. Latest jars should include the fix.
This works now for me! Thank you for the fix! :+1:
May I suggest that you put the current version somewhere easily seen on the page and add a version string to the jar file? Otherwise we wouldn't think to retest things that were previously broken :)
Thanks for the feedback. Yes, I will need to put the version number somewhere easily visible and do some other light maintenance too.
Sample2 program crashed after modified program to vid = 0x04df and pid = 0x0030, and the USB device attached to the system. The statemet: devInfo = info; has runtime error IllegalArgumentException: Allocatation size must be greater than zero.
Please help