我收藏的链接(44)
Java通过jnative调用pi实时数据库dll
Java通过jnative调用pi实时数据库dll
JNative : Java to native interface,This library allows developers to access native libraries (DLL and lib.so) from java. You do NOT need to compile a line of C/C++ to use it: it's dynamic !! Now Win32 DLL and shared libraries are usable with Java ;)
PI System, the world's leading highly-scalable and secure infrastructure for the management of real-time data and events
import org.xvolks.jnative.JNative;
import java.text.SimpleDateFormat;
import org.xvolks.jnative.Type;
import org.xvolks.jnative.exceptions.NativeException;
import org.xvolks.jnative.pointers.Pointer;
import org.xvolks.jnative.pointers.memory.HeapMemoryBlock;
import org.xvolks.jnative.pointers.memory.MemoryBlock;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
/**
* Java通过jnative调用pi实时数据库dll类库piapi32.dll获取tag标签数据
* <a href="http://itindex.net">http://itindex.net</a>
*/
public class PIClientUtil {
private static PIClientUtil piClientUtil=new PIClientUtil();
public static void main(String[] args) throws Exception {
PIClientUtil.getPIClientUtil().getTagValue("SCADA#ME-60331");
PIClientUtil.getPIClientUtil().getTagValue("SCADA#ME-60332");
PIClientUtil.getPIClientUtil().getTagValue("SCADA#ME-60333");
PIClientUtil.getPIClientUtil().getTagValue("SCADA#ME-60334");
PIClientUtil.getPIClientUtil().getTagValue("SCADA#ME-60335");
}
public static PIClientUtil getPIClientUtil(){
return piClientUtil;
}
private PIClientUtil() {
try {
MemoryBlock[] tim = new MemoryBlock[3];
tim[0] = MemoryBlockFactory.createMemoryBlock(8);
Pointer[] timed = new Pointer[100];
timed[0] = new Pointer(tim[0]);
tim[1] = MemoryBlockFactory.createMemoryBlock(8);
timed[99] = new Pointer(tim[1]);
MemoryBlock mm = MemoryBlockFactory.createMemoryBlock(4);
Pointer count1 = new Pointer(mm);
count1.setIntAt(0, 100);
int[] pt = { 17999, 18000, 18001 };
float[] rvals = new float[3];
int[] istats = new int[3];
System.out.println(System.currentTimeMillis());
// *********************连接PI数据库**************************//
// **********************************************************//
JNative messageBox = new JNative("piapi32.dll", "piut_setservernode");
messageBox.setRetVal(Type.INT);
messageBox.setParameter(0, Type.STRING, "88.148.76.208");
messageBox.invoke();
System.out.println("piut_setservernode:"+messageBox.getRetValAsInt());
// ***********************获取时间点**************************//
// **********************************************************//
String tt = "07-Aug-17 18:00:00 ";
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, timed[0]);
messageBox.invoke();
System.out.println(messageBox.getRetValAsInt());
System.out.println(timed[0].getAsInt(0));
messageBox = new JNative("piapi32.dll", "pitm_parsetime");
messageBox.setRetVal(Type.INT);
messageBox.setParameter(0, Type.STRING, "+10h ");
messageBox.setParameter(1, Type.INT, " " + timed[0].getAsInt(0));
messageBox.setParameter(2, timed[99]);
messageBox.invoke();
System.out.println(messageBox.getRetValAsInt());
System.out.println(timed[99].getAsInt(0));
} catch (NativeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 获取tag最新值,可能需要线程同步synchronized
* @param tagName
* @return
*/
public float getTagValue(String tagName){
try {
JNative messageBox = new JNative("piapi32.dll", "pipt_findpoint");
messageBox.setRetVal(Type.INT);
messageBox.setParameter(0, Type.STRING, tagName);
Pointer p=new Pointer(new HeapMemoryBlock(1024));
messageBox.setParameter(1, p);
messageBox.invoke();
System.out.println("pipt_findpoint:"+messageBox.getRetValAsInt());
int ptId=p.getAsInt(0);
messageBox = new JNative("piapi32.dll", "pisn_getsnapshot");
messageBox.setRetVal(Type.INT);
messageBox.setParameter(0, Type.INT, "" + ptId);
Pointer pp=new Pointer(new HeapMemoryBlock(1024));
messageBox.setParameter(1, pp);
messageBox.setParameter(2, new Pointer(new HeapMemoryBlock(1024)));
messageBox.setParameter(3, new Pointer(new HeapMemoryBlock(1024)));
messageBox.invoke();
System.out.println(tagName+"retValue:"+messageBox.getRetVal());
System.out.println(tagName+"tagValue:"+pp.getAsFloat(0));
return pp.getAsFloat(0);
} catch (NativeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 0;
}
}
我热爱的canon卡农音乐
下面的来自维基百科:
卡农(canon)是一种音乐谱曲技法,和赋格一样是复调音乐的写作技法之一,也是利用对位法的模仿技法。卡农同时也指以此种技法创作出来的音乐作品,比如巴赫的《五首卡农变奏曲》。
卡农的所有声部虽然都模仿一个声部,但不同高度的声部依一定间隔进入,造成一种此起彼伏,连绵不断的效果,轮唱也是一种卡农。在卡农中,最先出现的旋律是导句,以后模仿的是答句。
根据各声部高度不同的音程差,可分为同度卡农,五度卡农,四度卡农等;根据间隔的时间长短,可分为一小节卡农,两小节卡农等;此外还有伴奏卡农,转位卡农,逆行卡农,反行卡农等各种手法。
相关历史
- 卡农(canon)起源于意大利与法国,约出现于十三、十四世纪。
- 卡农的名称最早作“caccia”,古法语作“canon”,故一般认为其称谓来源于古法语,意思是“依靠”。(此说存疑,维基英文版的相关词条说古法语的“canon”意为“learned”——博学的,学术的。疑是误将learned写成leaned,leaned意为“依靠”。)
- (这一古法语的“canon”从语源上说来自于德文的“kanon”,意为“规律、法则”,因此一般认为卡农的原意为“规则”。)
- 卡农曲在十五世纪上半期至十六世纪中期(尼德兰乐派(Netherland School)时期)迎来了它的黄金岁月。
代表作(卡农曲)
今天我们最熟悉的卡农作品乃是帕赫贝尔(Johann Pachelbel)的《D大调卡农》(Canon in D Major),也称作《帕赫贝尔的卡农》(Pachelbel's Canon)。
此曲一般的演奏法是以大提琴启奏,三把小提琴间隔八拍先后加入。小提琴全部拉奏完全相同旋律,前后仅三段不同的旋律,每段仅两小节的旋律供重复拉奏;大提琴从头到尾也仅有两小节,重复达二十八次之多。这段音乐虽然不断回旋往复,但其旋律之美不让人觉得单调,反而感觉动听悦耳。
影响
- 韩国电影《我的野蛮女友》中采用了此曲的改编版—乔治·温斯顿(George Winston)的音乐专辑《December》中的《帕赫贝尔的卡农变奏曲》(Variations on the Canon by Pachelbel),更使之风靡一时。
- 动画Kanon京都版的第14话亦有使用此曲,并在第24话用此曲解释标题
试听不同版本的canon: