citect2018R2过程分析器趋势笔标签加上工程单位显示
这两天在家里学习练习了CITECT2018R2上过程分析器趋势笔标签上显示出工程单位,在新浪博客记录过一次,在这里也记录一下。
建立一个unity程序,有两个变量,分别是流量和浓度,建立的过程不在这里记录。新建citect2018R2项目,配置IO设备指向unity模拟器,建立变量和趋势变量,过程也不在这里记录/
新建画面trend1,放置过程分析器,编号为AN4,配置板和趋势笔,指向citect趋势变量。
新建过程分析器初始化的程序
Sub PAIni() '趋势控件初始化,现时显示游标、数据板命名、趋势笔命名,标签位置规范排列
Dim pa As Object
Dim hPanes As Object
Dim hPane As Object
Dim hPens As Object
Dim hPen As Object
Dim hCursor As Object
Dim value1,value2
Dim asLocal As Boolean
Dim cursorTime As Date
Dim milli As Integer
Dim cursorValue As String
Dim result1
asLocal = -1 '取本地时间
Set pa=trend1_AN4'趋势控件
Set hCursor=pa.cursors.create("游标处的数值",500)
hCursor.visible=true
Set hPanes=pa.Panes
Set hPane=hPanes.item(1)
hPane.Name="趋势笔标签自定义单位练习"
Set hPens=hPane.Pens
Set hPen=hPens.item(1)
hCursor.PenlabelX(hPen)=100
hCursor.PenlabelY(hPen)=40
hPen.Name="流量1"
hCursor.PenLabelHeight(hPen)=100
hCursor.PenLabelWidth(hPen)=150
hPen.VerticalAxisLabelType=35
Set hPen=hPens.item(2)
hCursor.PenlabelX(hPen)=300
hCursor.PenlabelY(hPen)=40
hPen.Name="浓度1"
hCursor.PenLabelHeight(hPen)=100
hCursor.PenLabelWidth(hPen)=150
hPen.VerticalAxisLabelType=35
End Sub
上面的脚本中
hCursor.PenLabelHeight(hPen)=100
hCursor.PenLabelWidth(hPen)=150
用于设置标签的大小
hPen.VerticalAxisLabelType=35
用于设置标签的单位是用于自定义文本
在trend1画面的“进入画面时”事件写下面的cicode脚本
VbCallReturn(VbCallRun(vbcallopen("PAIni")))
新建过程分析器游标移动事件的脚本
Sub trend1_AN4_CursorMoved(cursor As Object, position As Integer)
Dim pa As Object
Dim hPanes As Object
Dim hPane As Object
Dim hPens As Object
Dim hPen As Object
Dim hCursors As Object
Dim hcursor As Object
Dim asLocal As Boolean
Dim cursorTime As Date
Dim milli As Integer
Dim cursorValue As String
asLocal = -1 '取本地时间
Set pa=trend1_AN4'趋势控件
Set hCursors=pa.cursors
Set hcursor=hCursors.item(1)
Set hPanes=pa.Panes
Set hPane=hPanes.item(1)
Set hPens=hPane.Pens
Set hPen=hPens.item(1)
hcursor.GetValue hpen,asLocal, cursorTime, milli, cursorValue
hPen.SetVerticalAxisLabelValue cursorValue, cursorValue & " m3/h"
Set hPen=hPens.item(2)
hcursor.GetValue hpen,asLocal, cursorTime, milli, cursorValue
hPen.SetVerticalAxisLabelValue cursorValue, cursorValue & " mg/m3"
End Sub
这里面主要是取游标处的数值,然后进行字符串替换来显示定制的标签单位。.GetValue和.SetVerticalAxisLabelValue很关键。
保存、编译、设置计算机向导,将trend1设置为起始画面,运行项目程序,拖拽游标就可以看到游标显示工程量单位
![](https://img2023.cnblogs.com/blog/2292137/202309/2292137-20230903112909365-1255675387.png)
这个练习的项目程序已经上传到了网盘,地址是
链接:https://pan.baidu.com/s/1RXD8kHY7ByRTZTEZEfcDDA
提取码:1234
基于unity 13.1和citect2018R2做的练习
新浪博客那里分成两篇介绍,这里合成一篇了。