

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
2 messages in net.java.dev.jna.usersRe: [jna-dev] Problem reading a memor...| From | Sent On | Attachments |
|---|---|---|
| Timothy Wall | Mar 17, 2008 6:54 am | |
| Timothy Wall | Mar 17, 2008 8:31 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-dev] Problem reading a memory card | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Mar 17, 2008 8:31:50 am | |
| List: | net.java.dev.jna.users | |
On Mar 17, 2008, at 10:26 AM, LUCKY LUCKE wrote:
If the first argument is a w32 HANDLE, use the W32API.HANDLE type and pass null. Again, this is mostly style.
The first argument is an LPINT handle thus i suppose NativeLong is correctly used
Assuming the native definition is "int*", you should use Pointer or IntByReference.
Then i run the command
OutData out = new OutData(256); int response = lib.SCardComand(new NativeLong(0), "Device,InfoDeviceIDCard,1,Type", new NativeLong(0), null, new NativeLong(0), out, new NativeLong(256));
If I'm reading this correctly, you're passing a cmdLen of zero; is this supposed to be the length of the command string?
As for the length of the command: If the data transfer to the SCardServer is encrypted then we need to set the length, otherwise (unencrypted) this value must be set to zero
How does the native code know where the data ends? If it's looking for a NUL byte, you'll need to explicitly put one in your String or byte[].
byte newByte[] = new byte[256];
out.read(0, newByte, 0, 256); // byte array[] = out.getByteArray(0, 6);
for (int j = 0; j < newByte.length; j++) { if (j != 0 && j % 16 == 0) { System.out.println(); } System.out.print(newByte[j] + " "); }
If you use a byte array, you can simply call Native.toString(byte[]) to convert to a Java String. It'll automatically stop reading when it encounters a NUL byte.
I used this too, but got the ΐ:ϋxϋ so i resorted to the loop for a more analytical view
You probably need to set the jna.encoding property to be whatever encoding your native code is using, since it seems to be different than the default native encoding.
where i get a bunch of integers. What i want to ask is whether i do the right mapping for the LPSTR native type (the pointer to the byte array), or not. When i try the command "Device,List" which produces the output
'CHIPDRIVE micro' at COM2 'CHIPDRIVE exten I' at COM2-1 'CHIPDRIVE ................................ 'whatever the driver is....................
and it would need a two dimensional array to hold this data,
Not clear what you mean by needing a two dimensional array to hold this data.
In this case we would need an array eg Object arr[][ ] = new Object [4][lengthOfEachOuputLine]; How do i declare this by extending the class Memory?
First determine what you need on the native side. I think you mean you get an array of char*. Translating this into JNA types, that's either Pointer[] or Memory(size * Pointer.SIZE).
How does the native library documentation say it puts an array of output lines into the LPSTR that you provide it as a buffer?
i get a VM crash, that is the OutData mapping is not correct. I also get a VM crash when i try to write to the card, no matter if i pass the command as a java String or a byte array (im not trying to write outside of the memory's bounds. I checked this)
Presumably when you write to the card you have to set inData/inDataLen appropriately. You'll get a crash if you pass "null".
I dont pass null value. I pass it as a string (chashhh!) or a byte array (crashhh!)
byte dataIn[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x53, 0x6D, 0x61, 0x72, 0x74, 0x43, 0x61, 0x72, 0x64, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64 }; //this means Hello SmartCard World dataInLen is set to 21
Try terminating with a zero byte.







