Results 1 to 1 of 1
Thread: Problem using Structure in JNA
- 04-28-2011, 03:59 PM #1
Member
- Join Date
- Apr 2011
- Location
- Brazil
- Posts
- 1
- Rep Power
- 0
Problem using Structure in JNA
Hello there,
I have some Shared Objects (.os files) to operate an equipment and I am having the following problem:
I am loading the library and executing a method that will return an int. It will change the values of the items in the Structure that is passed ByReference (it was passed the pointer in the native). Everything run just fine, but when I read the contents of the Structure, what I get are values like: "[B@1133F1D7" that looks to me like memory position. Or making some changes it returns strange values when all I wanted was some regular values that I've set in the equipment as 1550 for wavelength. I am guessing the problem that I am dealing is a problem of knowing how to use the JNA ByReference on Structures.
Following there are the codes that I used. I also have some example of the use of the libraries in C++, but I have to use java:
Using the app in C++, it returns the values that I wish.Java Code://Native C++ //Struct to be used. It's in a header file: struct.h #pragma pack(push,1) typedef struct ST_SCANPARMS { unsigned char iCommand; // 1 ±íÊ?ÉèÖòÎÊý 2±íÊ?É?Ãè int sortype; // 1 :GR169 2 :SR4731 int scanmode; //average scan int scanrange; //60KM int avgtime; //6s int wavelength; //wave length 1310 int pulsewidth; //3000ns int ior; double sensitivity; //low double filberendloss; unsigned char crcLow; unsigned char crcHigh; }SCANPARMS,*PSCANPARMS; #pragma pack(pop) //Method's signature to use the .so, it is in a header file called nfosock.h and the .so is nfosock.so int GetParms(SCANPARMS *tRetParms ,char sIP[],short nPort); //Calling the method in the main fuction, nfo.cpp int ret=-1; SCANPARMS parms; char arrIP[30] = {0}; short nPort = 0; //... //Values of IP and port are set in the code... //... ret = GetParms(&parms ,arrIP ,nPort);
But using java it's different.
Follows tha java code:
What could I be doing wrong? Can someone help me with my problem?Java Code:public class SCANPARMS extends Structure{ public static class ByReference extends SCANPARMS implements Structure.ByReference { } public char iCommand; // 1 ±íÊ?ÉèÖòÎÊý 2±íÊ?É?Ãè public int sortype; // 1 :GR169 2 :SR4731 public int scanmode; //average scan public int scanrange; //60KM public int avgtime; //6s public int wavelength; //wave length 1310 public int pulsewidth; //3000ns public int ior; public double sensitivity; //low public double filberendloss; public char crcLow; public char crcHigh; } //the signature of the methods are weird, but this is what I found when i typed "nm //nfosock.so" public interface NFOSock extends Library{ int _Z8GetParmsP12ST_SCANPARMSPcs(SCANPARMS.ByReference tRetParms,String sIP,short nPort); int _Z9GetDeviceP14ST_Device_Info(ST_Device_Info[] tDevice); String _Z13GetLibVersionv(); } //Main code public static void main(String args[]){ NFOSock nfosock = (NFOSock)Native.loadLibrary("/home/pedro.carvalho/workspace/WwRadiantech/lib/nfosock.so", NFOSock.class); SCANPARMS.ByReference parms = new SCANPARMS.ByReference(); short nPort = 4997; //porta que estou utilizando para comunicacao com o equipamento int ret = 0; String IP = "192.168.1.57"; //ip no qual se encontra o equipamento ret = nfosock._Z8GetParmsP12ST_SCANPARMSPcs(parms, IP, nPort); System.out.println("sorType: "+parms.sortype); //Exemplo de parametro que ao ser comparado é obtido errado }
Thanks in advance,
--
Pedro
Similar Threads
-
Problem--How to create dynamic tree structure in jsp using javascript
By natu in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-11-2010, 08:11 AM -
Very strange structure
By atch in forum New To JavaReplies: 1Last Post: 02-10-2010, 11:48 AM -
Directory Structure
By rummy in forum New To JavaReplies: 1Last Post: 01-21-2010, 12:03 PM -
Use if then else structure, help
By paul in forum New To JavaReplies: 1Last Post: 08-07-2007, 05:00 AM -
Help with Structure
By Albert in forum New To JavaReplies: 1Last Post: 07-13-2007, 03:27 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks