我想知道如何在Java中使用该结构

时间:2019-05-31 01:59:09

标签: java c jna

这是结构:

struct CheckInInfoV2 {
    int BuildingID;// Building id,ranges between 1 ~ 99
    int FloorID;// Floor no.,ranges between 1~99
    int RoomID;// Room id,ranges between 1~99
    int ReportLost; // Substitute flag,1 is yes,0 is no
    int End_Year; // expiry year
    int End_Mon; // expiry month
    int End_Day; // expiry day of month
    int End_Hour; // expiry hour
    int End_Min; // expiry minute
    int SeqNo; // uses to return the sequence number of this check in
    int GroupMask; // Connect mask for public door
    int Reserved1; // Reserved, fills as 0x00
    int SubRoomID; // Sub Branch id from 0~7, fills as 0x0F for Sub Branch(Main)
    int NumOfBreakfasts; // Number of breakfasts
    int BuildingID4ConnectRoom1; // Building id of Connect Room(1)
    int FloorID4ConnectRoom1; // Floor no. of Connect Room(1)
    int RoomID4ConnectRoom1; // Room id of Connect Room(1)
    int BuildingID4ConnectRoom2; // Building id of Connect Room(2)
    int FloorID4ConnectRoom2; // Floor no. of Connect Room(2)
    int RoomID4ConnectRoom2; // Room id of Connect Room(2)
}

这是C函数:

int CheckInV2(const char * PortName, const int Sector, const char * RemoteAddr, const int   RemotePort, const char * UserName, const char * Password, const CheckInInfoV2 * pInfo);

我将其更改为Java。

public class CheckInInfoV2 {
int BuildingID;// Building id,ranges between 1 ~ 99
int FloorID;// Floor no.,ranges between 1~99
int RoomID;// Room id,ranges between 1~99
int ReportLost; // Substitute flag,1 is yes,0 is no
int End_Year; // expiry year
int End_Mon; // expiry month
int End_Day; // expiry day of month
int End_Hour3; // expiry hour
int End_Min3; // expiry minute
int SeqNo; // uses to return the sequence number of this check in
int GroupMask; // Connect mask for door
int Reserved1; // Reserved, fills as 0x00
int SubRoomID; // Sub Branch id from 0~7, fills as 0x0F for Sub Branch(Main)
int NumOfBreakfasts; // Number of breakfasts
int BuildingID4ConnectRoom1; // Building id of Connect Room(1)
int FloorID4ConnectRoom1; // Floor no. of Connect Room(1)
int RoomID4ConnectRoom1; // Room id of Connect Room(1)
int BuildingID4ConnectRoom2; // Building id of Connect Room(2)
int FloorID4ConnectRoom2; // Floor no. of Connect Room(2)
int RoomID4ConnectRoom2; // Room id of Connect Room(2)

public CheckInInfoV2(int buildingID, int floorID, int roomID, int reportLost, int end_Year, int end_Mon,
        int end_Day, int end_Hour3, int end_Min3, int seqNo, int groupMask, int reserved1, int subRoomID,
        int numOfBreakfasts, int buildingID4ConnectRoom1, int floorID4ConnectRoom1, int roomID4ConnectRoom1,
        int buildingID4ConnectRoom2, int floorID4ConnectRoom2, int roomID4ConnectRoom2) {
    super();
    BuildingID = buildingID;
    FloorID = floorID;
    RoomID = roomID;
    ReportLost = reportLost;
    End_Year = end_Year;
    End_Mon = end_Mon;
    End_Day = end_Day;
    End_Hour3 = end_Hour3;
    End_Min3 = end_Min3;
    SeqNo = seqNo;
    GroupMask = groupMask;
    Reserved1 = reserved1;
    SubRoomID = subRoomID;
    NumOfBreakfasts = numOfBreakfasts;
    BuildingID4ConnectRoom1 = buildingID4ConnectRoom1;
    FloorID4ConnectRoom1 = floorID4ConnectRoom1;
    RoomID4ConnectRoom1 = roomID4ConnectRoom1;
    BuildingID4ConnectRoom2 = buildingID4ConnectRoom2;
    FloorID4ConnectRoom2 = floorID4ConnectRoom2;
    RoomID4ConnectRoom2 = roomID4ConnectRoom2;
}
public CheckInInfoV2() {

}
public int getBuildingID() {
    return BuildingID;
}

public void setBuildingID(int buildingID) {
    BuildingID = buildingID;
}

public int getFloorID() {
    return FloorID;
}

public void setFloorID(int floorID) {
    FloorID = floorID;
}

public int getRoomID() {
    return RoomID;
}

public void setRoomID(int roomID) {
    RoomID = roomID;
}

public int getReportLost() {
    return ReportLost;
}

public void setReportLost(int reportLost) {
    ReportLost = reportLost;
}

public int getEnd_Year() {
    return End_Year;
}

public void setEnd_Year(int end_Year) {
    End_Year = end_Year;
}

public int getEnd_Mon() {
    return End_Mon;
}

public void setEnd_Mon(int end_Mon) {
    End_Mon = end_Mon;
}

public int getEnd_Day() {
    return End_Day;
}

public void setEnd_Day(int end_Day) {
    End_Day = end_Day;
}

public int getEnd_Hour3() {
    return End_Hour3;
}

public void setEnd_Hour3(int end_Hour3) {
    End_Hour3 = end_Hour3;
}

public int getEnd_Min3() {
    return End_Min3;
}

public void setEnd_Min3(int end_Min3) {
    End_Min3 = end_Min3;
}

public int getSeqNo() {
    return SeqNo;
}

public void setSeqNo(int seqNo) {
    SeqNo = seqNo;
}

public int getGroupMask() {
    return GroupMask;
}

public void setGroupMask(int groupMask) {
    GroupMask = groupMask;
}

public int getReserved1() {
    return Reserved1;
}

public void setReserved1(int reserved1) {
    Reserved1 = reserved1;
}

public int getSubRoomID() {
    return SubRoomID;
}

public void setSubRoomID(int subRoomID) {
    SubRoomID = subRoomID;
}

public int getNumOfBreakfasts() {
    return NumOfBreakfasts;
}

public void setNumOfBreakfasts(int numOfBreakfasts) {
    NumOfBreakfasts = numOfBreakfasts;
}

public int getBuildingID4ConnectRoom1() {
    return BuildingID4ConnectRoom1;
}

public void setBuildingID4ConnectRoom1(int buildingID4ConnectRoom1) {
    BuildingID4ConnectRoom1 = buildingID4ConnectRoom1;
}

public int getFloorID4ConnectRoom1() {
    return FloorID4ConnectRoom1;
}

public void setFloorID4ConnectRoom1(int floorID4ConnectRoom1) {
    FloorID4ConnectRoom1 = floorID4ConnectRoom1;
}

public int getRoomID4ConnectRoom1() {
    return RoomID4ConnectRoom1;
}

public void setRoomID4ConnectRoom1(int roomID4ConnectRoom1) {
    RoomID4ConnectRoom1 = roomID4ConnectRoom1;
}

public int getBuildingID4ConnectRoom2() {
    return BuildingID4ConnectRoom2;
}

public void setBuildingID4ConnectRoom2(int buildingID4ConnectRoom2) {
    BuildingID4ConnectRoom2 = buildingID4ConnectRoom2;
}

public int getFloorID4ConnectRoom2() {
    return FloorID4ConnectRoom2;
}

public void setFloorID4ConnectRoom2(int floorID4ConnectRoom2) {
    FloorID4ConnectRoom2 = floorID4ConnectRoom2;
}

public int getRoomID4ConnectRoom2() {
    return RoomID4ConnectRoom2;
}

public void setRoomID4ConnectRoom2(int roomID4ConnectRoom2) {
    RoomID4ConnectRoom2 = roomID4ConnectRoom2;
}


}

package loadex;

import com.sun.jna.Library;
import com.sun.jna.Native;

public class LoadDLLTest {

    public interface Test extends Library{
        public int V2ClearCard(String portName, int sector);
        public int V2ReadCard(String portName, int sector, int[] a);
        public int CheckInV2(String portName, int sector, String remoteAddr, int remotePort, String userName, String pw, int[] a);
        public int CheckInV2(String portName, int sector, String remoteAddr, int remotePort, String userName, String pw, V2CardInfo a);
        public int ClearCard(String portName, int sector);
    }

    static {
        System.loadLibrary("nspr4");
        System.loadLibrary("libwinpthread-1");
        System.loadLibrary("libstdc++-6");
        System.loadLibrary("libprotobuf-9");
        System.loadLibrary("libgcc_s_sjlj-1");
        System.loadLibrary("libDriver_Common");
        System.loadLibrary("libDriverWrapper");
        System.loadLibrary("libDriver_M1");
        System.loadLibrary("libDriver_Common-0");
        System.loadLibrary("libDriver_M1");     
        System.loadLibrary("libDriver_T5557-0");
        System.loadLibrary("libprotobuf-7");
    }

    public static void main(String[] args) throws Exception  {


        Test test = (Test)Native.loadLibrary("libDriver_M1", Test.class);

        V2CardInfo v2CardInfo = new V2CardInfo();
        int [] intArray1 = {
                1,1,1,1,2,1,0,0,0,1,
                1,1,1,1,1,1,1,1,1,1,
                1,1,1,1,1,1,1,1,1,1};
        int [] intArray2 = {
                1, 1, 1, 1, 2019, 5, 30, 10 ,10 ,1
                ,1,1,1,1,1,1,1,1,1,1};
        System.out.println(test.CheckInV2("COM4", 1, ip, port, "admin", "1", intArray2));
        System.out.println(test.CheckInV2("COM4", 1, ip, port, "admin", "1", v2CardInfo));


    }
}

第一笔订单成功。 但是第二个命令失败了。 失败的原因是

Exception in thread "main" java.lang.IllegalArgumentException: Unsupported archive type loadex.CheckInInfoV2 at parameter 6 of function CheckInV2 

我该如何解决?

0 个答案:

没有答案