xueyudouble 2019-03-07 15:53
浏览 377

求助Java调用jna如何模拟这个结构体

原生结构体如下:

typedef struct iodbpmc {
short type_a ; /* Kind of PMC address /
short type_d ; /
Type of the PMC data /
short datano_s ; /
Start PMC address number /
short datano_e ; /
End PMC address number /
union {
char cdata[N] ;/
The PMC data(byte type) /
short idata[N] ;/
(word type) /
long ldata[N] ;/
(long type) /
} u ; /
N is the number of written data */
} IODBPMC ;

java 模拟如下:
public class IODBPMC extends Structure {

public short type_a; // Kind of PMC address
public short type_d; // Type of the PMC data
public short datano_s; // Start PMC address number
public short datano_e; // End PMC address number
public union u  ;

public static class ByReference extends IODBPMC implements Structure.ByReference {
}

public static class ByValue extends IODBPMC implements Structure.ByValue {
}

public static class union extends Union {
    public byte[] cdata = new byte[5];
    public short[] idata = new short[5] ;
    public NativeLong[] ldata = new NativeLong[5]; 

    public static class ByReference extends union implements Union.ByReference {
    }

    public static class ByValue extends union implements Union.ByValue {
    }
    protected List<String> getFieldOrder() {

        return Arrays.asList(new String[] { "cdata", "idata", "ldata" });
    }
}

protected List<String> getFieldOrder() {

    return Arrays.asList(new String[] { "type_a", "type_d", "datano_s", "datano_e", "u" });
}

}

测试结果智能写入0,使用C#写的小程序就能完成写入

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 一道python难题
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试
    • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
    • ¥15 教务系统账号被盗号如何追溯设备
    • ¥20 delta降尺度方法,未来数据怎么降尺度