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条回答

    报告相同问题?

    悬赏问题

    • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类