java读取PI数据库测点值
JNative messageBox = new JNative("piapi32.dll", "pitm_parsetime"); messageBox.setRetVal(Type.INT); messageBox.setParameter(0, Type.STRING, tt); messageBox.setParameter(1, Type.INT, "0"); messageBox.setParameter(2, pointer); messageBox.invoke(); if(0 == messageBox.getRetValAsInt()){ System.out.println("执行成功,getPiTime结果是:"+ pointer.getAsInt(0)); return pointer.getAsInt(0); }else{ System.out.println("执行失败"); return 0; } } catch (NativeException e) { e.printStackTrace(); return 0; } catch (IllegalAccessException e) { e.printStackTrace(); return 0; } } /** * 将整数转换为时间,同上方法互逆 * @param time * @return */ public String getTimeFromInt(int time){ try { Pointer pointer = new Pointer(MemoryBlockFactory.createMemoryBlock(8)); JNative messageBox = new JNative("piapi32.dll", "pitm_formtime"); messageBox.setRetVal(Type.INT); messageBox.setParameter(0, Type.INT,this.getPiTime("")+""); messageBox
.setParameter(1, pointer); messageBox.setParameter(2,19); messageBox.invoke();