Re: set data in array in a native method
Thomas Chenot <tom.chenot-6tN4nzCoH/[email protected]> Thu, 20 May 2004 10:01:53 -0500
| Newsgroups | gmane.comp.hardware.microcontrollers.tini |
|---|---|
| Message-ID | <[email protected]> |
I do not see where you are specifying a parameter number. This number
depends on your method signature, which was not provided.
If your native method is static then the parameter numbering begins at
zero (see Native_Methods.txt for more info). Otherwise the numbering
begins at one.
If your native method looks like this
public static native int Test(byte[] b);
your native code should look like this
Native_Test:
CLR A
lcall NatLib_LoadJavaByteArray
;...
If your native method looks like this
public native int Test(byte[] b);
your native code should look like this
Native_Test:
MOV A, #1
lcall NatLib_LoadJavaByteArray
;...
I am sure LoadJavaByteArray is failing since Acc has an unknown value when you call it and since you do not see any data in your array.
Since you are not handling the error condition in your code (you are not
returning the exception from native, since you CLR A before RETurning,
and your Java code does not look at the return value from the native
method) you are not detecting the error condition.
Koen Swinters wrote:
>Hello,
>
>Im trying to fill a Byte array in a native method with some data. But for
>some reason the array stays empty when I check the array in java.
>I've written some test code to see if I can change the data in a byte Array
>in a native function(see code below).
>Does some-one know what I'm doing wrong or how can I change the data in a
>Array with a native methode and than give it back to my java program.
>
>native code:
>
>Native_Test:
> lcall NatLib_LoadJavaByteArray
> jz NM3_PointerIsValid
> mov R0,#0 ; return empty arry
> sjmp NM3_Exit ;
>NM3_PointerIsValid:
> mov a, R0 ; check the array length
> orl a, R1 ;
> orl a, R2 ;
> orl a, R3 ;
> jz NM3_Exit
> mov a,#'K'
> putx
> inc dptr
> mov a,#'L'
> putx
> inc dptr
> mov a,#'G'
> putx
> inc dptr
> NM3_Exit:
> clr a
> ret
>
>java code:
>
>irData = new byte[4];
>Test(irData);
>for (int i=0; i<4;i++)
>{
> System.out.print(" " + irData[i]);
>}
>
>regards
>
>Koen
>
>
>
>
--
Thomas Chenot
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini