2012-11-22 1 views
1

내가 JNA에 초보자와 오전 포인터 매핑에 대해JNA : 포인터의 배열에 구조체 : 유효하지 않은 포인터

기본 방법에 문제에 직면 :

  • EXTERNC T_PDU_ERROR PDUStartComPrimitive (UNUM32 흐 모드, UNUM32 hCLL, T_PDU_COPT CopType, UNUM32 CoPDataSize, UNUM8
    pCopData *, * PDU_COP_CTRL_DATA pCopCtrlData 무효 pCopTag *, * UNUM32 phCoP)

JNA 방법 :

  • INT PDUStartComPrimitive (INT 흐 모드, INT hCLL, INT의 CoPType,
    CoPDataSize 바이트 [] pCoPData, PDU_COP_CTRL_DATA.ByReference에서 INT
    pCopCtrlData 포인터 pCoPTag, IntByReference phCoP) ;

기본 구조 (들) :

typedef struct{ 
UNUM32 Time; 
SNUM32 NumSendCycles; 
SNUM32 NumReceiveCycles; 
UNUM32 TempParamUpdate; 
PDU_FLAG_DATA TxFlag; 
UNUM32 NumPossibleExpectedResponses; 
PDU_EXP_RESP_DATA *pExpectedResponseArray; 
}PDU_COP_CTRL_DATA; 

typedef struct{ 
UNUM32 ResponseType; 
UNUM32 AcceptanceId; 
UNUM32 NumMaskPatternBytes; 
UNUM8 *pMaskData; 
UNUM8 *pPatternData;  
UNUM32 NumUniqueRespIds; 
UNUM32 *pUniqueRespIds; 
}PDU_EXP_RESP_DATA; 

JNA 매핑 :

public class PDU_COP_CTRL_DATA extends Structure{  
    public int time;   
    public int numSendCycles;  
    public int numReceiveCycles;   
    public int tempParamUpdate;  
    public PDU_FLAG_DATA txFlag;   
    public int numPossibleExpectedResponses;   
    public Pointer pExpectedResponseArray;  
    public static class ByReference extends PDU_COP_CTRL_DATA implements  Structure.ByReference { 
    }; 
} 

public class PDU_EXP_RESP_DATA extends Structure{   
    public int responseType;   
    public int acceptanceId; 
    public int numMaskPatternBytes; 
    public byte[] pMaskData= new byte[1]; 
    public byte[] pPatternData = new byte[1]; 
    public int numUniqueRespIds; 
    /* Array containing unique response identifiers. Only responses with a unique response identifier found in this array are considered, when trying to match them to this expected response. */ 
    public Pointer pUniqueRespIds; 
    public static class ByReference extends PDU_EXP_RESP_DATA implements Structure.ByReference { 
    }; 
} 

나는 자바에서 PDUStartComPrimitive 방법을 실행하고 underlyng DLL 로그 I 살펴있을 때 해당 PDU_COP_CTRL_DATA strucutre 필드를 참조하십시오 * pExpectedResponseArray 잘못된 * PDU_EXP_RESP_DATA 포인터가 나타납니다. 설정에

내 JNA의 코드 PDUStartComPrimitive 실행

 byte[] sendata = new byte[requestData.length()/2]; 

     int byteIndex = 0; 
     for (String byteString : requestData.split(" ")) { 
      sendata[byteIndex] = Byte.parseByte(byteString, 16); 
      byteIndex++; 
     } 
     /* Setting of the expected responses ends */ 

     PDU_COP_CTRL_DATA.ByReference objCopCtrlData = new PDU_COP_CTRL_DATA.ByReference(); 
     objCopCtrlData.numPossibleExpectedResponses = 1; 
     objCopCtrlData.numReceiveCycles = 1; 
     objCopCtrlData.numSendCycles = 1; 
     objCopCtrlData.tempParamUpdate = 0; 
     objCopCtrlData.time = 0; 


     PDU_EXP_RESP_DATA expRespStruct = new PDU_EXP_RESP_DATA(); 

     expRespStruct.acceptanceId = 0; 
     expRespStruct.numMaskPatternBytes = 1; 
     expRespStruct.numUniqueRespIds = 0; 
     expRespStruct.pUniqueRespIds = new Pointer(0); 
     expRespStruct.responseType = 0; 

     byte[] mskByte = byte int[] { 0 }; 
     byte[] patternByte = new byte[] { 0 }; 
     expRespStruct.pMaskData = mskByte; 
     expRespStruct.pPatternData = patternByte; 

     PDU_EXP_RESP_DATA[] refArr = (PDU_EXP_RESP_DATA[]) expRespStruct.toArray(1); 
     refArr[0] = expRespStruct; 

     expRespStruct.autoWrite(); 

     objCopCtrlData.pExpectedResponseArray = expRespStruct.getPointer(); 

     PDU_FLAG_DATA.ByValue objTxFlagData = new PDU_FLAG_DATA.ByValue();   
     objCopCtrlData.txFlag = objTxFlagData; 

     String strComAction = "SEND_RECV"; 
     Pointer apiTag = new NativeString(strComAction, true).getPointer(); 
     IntByReference phCop = new IntByReference(); 

     int errorCode = PDUStartComPrimitive(1, 1,0x8004, sendata.length,sendata, objCopCtrlData, apiTag, phCop); 

나는이 어쩌면 때문에 잘못된 JNA 매핑의 의심을 가지고있다. 아이디어 나 제안을 도와주세요. 감사합니다

답변

0

Structure 내의 기본 배열은 집계 (배열) 유형의 필드가되는 인라인 배열로 해석됩니다. 기본 구조는 해당 필드에 대한 포인터 유형을 나타내므로 포인터, 포인터 유형 또는 NIO 버퍼를 사용해야합니다.