cicode定制过程分析器1:添加趋势板和下面的趋势笔
我在新浪博客也写过,在这里也发一遍,新浪博客还在审核,这里可能先出来
这两天一直在用citectVBA语言编程做过程分析器的定制,使用cicode变成也可以达到同样的效果。这一片开始我试着使用cicode编程实现同样的功能。
新建一个citect2018项目,这个项目试着在空白的过程分析席上添加板和趋势笔。页面名称为mian,过程分析器编号为AN4,再放置一个按钮,用于鼠标点击的时候执行cicode脚本。
新建A1至A5五个变量,新建5个趋势变量关联A1至A5。
新建一个cicode程序,变量初始化
FUNCTION V_INI()
A1=10
A2=20
A3=30
A4=40
A5=50
END
在main打开事件中运行V_INI()函数
新建一个cicode,用户在过程分析器中添加板和趋势变量
FUNCTION paini()
//添加板和趋势笔
OBJECT pa;
OBJECT hpanes;
OBJECT hpane;
OBJECT hpens;
OBJECT hpen;
OBJECT hcursors;
OBJECT hcursor;
pa=ObjectByName("AN4");
//显示游标
hcursors=_OBJECTGetproperty(pa,"Cursors");
_ObjectCallMethod(hcursors,"Create","cursor1",500);
hcursor=_OBJECTCallMethod(hcursors,"get_item",1);
_ObjectSetProperty(hcursor,"Visible",-1);
//添加趋势板1
hpanes=_OBJECTGetProperty(pa,"Panes");
_ObjectCallMethod(hpanes,"Create","我的趋势板1");
hpane=_OBJECTCallMethod(hpanes,"get_item",1);
//在板1下面添加趋势笔1,关联趋势变量A1
hpens=_OBJECTGetproperty(hpane,"Pens");
_ObjectCallMethod(hpens,"Create",4097,3);
hpen=_OBJECTCallMethod(hPens,"get_item",1);
_ObjectSetProperty(hPen, "Name", "趋势板1下的1#趋势笔");
_ObjectSetProperty(hPen, "DataPoint", "A1");
_ObjectSetProperty(hPen, "InstantTrend", -1);
//采样频率500ms
_ObjectSetProperty(hPen, "SamplePeriod", 500)
//设置纵坐标
_ObjectCallMethod(hPen, "PutVerticalAxisSpan", 0, 100);
//设置时间跨度8小时
_ObjectCallMethod(hPen, "SetDefaultSpan", 0, 0, 8, 0, 0, 0);
_ObjectCallMethod(hPen, "ResetToDefaultSpan");
//跳转到当前
_ObjectCallMethod(hPen, "GoToNow");
//在板1下面添加趋势笔2,关联趋势变量A2
hpens=_OBJECTGetproperty(hpane,"Pens");
_ObjectCallMethod(hpens,"Create",4097,3);
hpen=_OBJECTCallMethod(hPens,"get_item",2);
_ObjectSetProperty(hPen, "Name", "趋势板1下的2#趋势笔");
_ObjectSetProperty(hPen, "DataPoint", "A2");
_ObjectSetProperty(hPen, "InstantTrend", -1);
//采样频率500ms
_ObjectSetProperty(hPen, "SamplePeriod", 500)
//设置纵坐标
_ObjectCallMethod(hPen, "PutVerticalAxisSpan", 0, 120);
//设置时间跨度8小时
_ObjectCallMethod(hPen, "SetDefaultSpan", 0, 0, 8, 0, 0, 0);
_ObjectCallMethod(hPen, "ResetToDefaultSpan");
//跳转到当前
_ObjectCallMethod(hPen, "GoToNow");
//添加趋势板2
hpanes=_OBJECTGetProperty(pa,"Panes");
_ObjectCallMethod(hpanes,"Create","我的趋势板2");
hpane=_OBJECTCallMethod(hpanes,"get_item",2);
//在板2下面添加趋势笔1,关联趋势变量A3
hpens=_OBJECTGetproperty(hpane,"Pens");
_ObjectCallMethod(hpens,"Create",4097,3);
hpen=_OBJECTCallMethod(hPens,"get_item",1);
_ObjectSetProperty(hPen, "Name", "趋势板2下的1#趋势笔");
_ObjectSetProperty(hPen, "DataPoint", "A3");
_ObjectSetProperty(hPen, "InstantTrend", -1);
//采样频率500ms
_ObjectSetProperty(hPen, "SamplePeriod", 500)
//设置纵坐标
_ObjectCallMethod(hPen, "PutVerticalAxisSpan", 0, 140);
//设置时间跨度8小时
_ObjectCallMethod(hPen, "SetDefaultSpan", 0, 0, 8, 0, 0, 0);
_ObjectCallMethod(hPen, "ResetToDefaultSpan");
//跳转到当前
_ObjectCallMethod(hPen, "GoToNow");
//在板2下面添加趋势笔2,关联趋势变量A4
hpens=_OBJECTGetproperty(hpane,"Pens");
_ObjectCallMethod(hpens,"Create",4097,3);
hpen=_OBJECTCallMethod(hPens,"get_item",2);
_ObjectSetProperty(hPen, "Name", "趋势板2下的2#趋势笔");
_ObjectSetProperty(hPen, "DataPoint", "A4");
_ObjectSetProperty(hPen, "InstantTrend", -1);
//采样频率500ms
_ObjectSetProperty(hPen, "SamplePeriod", 500)
//设置纵坐标
_ObjectCallMethod(hPen, "PutVerticalAxisSpan", 0, 160);
//设置时间跨度8小时
_ObjectCallMethod(hPen, "SetDefaultSpan", 0, 0, 8, 0, 0, 0);
_ObjectCallMethod(hPen, "ResetToDefaultSpan");
//跳转到当前
_ObjectCallMethod(hPen, "GoToNow");
//在板2下面添加趋势笔3,关联趋势变量A5
hpens=_OBJECTGetproperty(hpane,"Pens");
_ObjectCallMethod(hpens,"Create",4097,3);
hpen=_OBJECTCallMethod(hPens,"get_item",3);
_ObjectSetProperty(hPen, "Name", "趋势板2下的3#趋势笔");
_ObjectSetProperty(hPen, "DataPoint", "A5");
_ObjectSetProperty(hPen, "InstantTrend", -1);
//采样频率500ms
_ObjectSetProperty(hPen, "SamplePeriod", 500)
//设置纵坐标
_ObjectCallMethod(hPen, "PutVerticalAxisSpan", 0, 180);
//设置时间跨度8小时
_ObjectCallMethod(hPen, "SetDefaultSpan", 0, 0, 8, 0, 0, 0);
_ObjectCallMethod(hPen, "ResetToDefaultSpan");
//跳转到当前
_ObjectCallMethod(hPen, "GoToNow");
END
画面上的按钮鼠标点击事件执行这个函数。
保存、编译、运行,点击按钮,效果如下图所示
![](https://img2023.cnblogs.com/blog/2292137/202212/2292137-20221220193511559-1956190580.png)
我做这个学习联系的时候,卡在了
pa=ObjectByName("AN4");
语句,开始的时候我参照citectVBA语言,写成
pa=ObjectByName("main_AN4");
当时想的是AN4所在页面是main,编译没有错,就是出不了效果,后来试着去掉页面名称,只保留空间的编号AN4,一下子就出了效果。