变量的绑定
一、协议中的变量使用
协议中使用脚本
参考数据采集与监控演示项目
的demo,位置在格西测控大师的安装目录下:
X:/Geshe/GGenesis/Examples/Solutions/SCADA/SCADA/SCADA.gpj
可以看到,步骤退出时执行变量的更新:
public Int32 EndExecute(Genesis.Sequence.IStepContext context, Genesis.Sequence.IStep step)
{
if (step.Result.Status == (int)ResultStatus.Passed)
{
Int16 temperature = (Int16)step.Result.DataFields[3].Value;
DateTime time = DateTime.Now;
// 设置变量表的变量值
context.Variants["采集变量表/温度数据/时间"] = time;
context.Variants["采集变量表/温度数据/温度值"] = temperature;
}
return 0;
}
协议中对变量直接绑定
参考环境监测电子公告牌项目
的demo,位置在格西测控大师的安装目录下:
X:/Geshe/GGenesis/Examples/Solutions/SCADA/BulletinBoard/BulletinBoard.gpj
打开序列,查看协议:
打开协议内容:
查看对应变量:
二、控件的变量绑定
参考环境监测电子公告牌项目
的demo,位置在格西测控大师的安装目录下:
X:/Geshe/GGenesis/Examples/Solutions/SCADA/BulletinBoard/BulletinBoard.gpj
点击控件:
查看属性中的值:
绑定变量。
三、脚本中对变量赋值以及调用
参考变量演示项目
的demo,位置在格西测控大师的安装目录下:
X:/Geshe/GGenesis/Examples/Basics/Variants/Variants.gpj
脚本中对基本变量进行赋值和调用例子:
context.Variants["ExtendedVars/Storage/File1/日期"] = DateTime.Now;
bool v1 = (bool)context.Variants["ExtendedVars/Storage/File1/数值Bool"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Bool"] = !v1;
sbyte v2 = (sbyte)context.Variants["ExtendedVars/Storage/File1/数值SByte"].Value;
context.Variants["ExtendedVars/Storage/File1/数值SByte"] = --v2;
byte v3 = (byte)context.Variants["ExtendedVars/Storage/File1/数值Byte"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Byte"] = ++v3;
Int16 v4 = (Int16)context.Variants["ExtendedVars/Storage/File1/数值Int16"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Int16"] = --v4;
UInt16 v5 = (UInt16)context.Variants["ExtendedVars/Storage/File1/数值UInt16"].Value;
context.Variants["ExtendedVars/Storage/File1/数值UInt16"] = ++v5;
Int32 v6 = (Int32)context.Variants["ExtendedVars/Storage/File1/数值Int32"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Int32"] = --v6;
UInt32 v7 = (UInt32)context.Variants["ExtendedVars/Storage/File1/数值UInt32"].Value;
context.Variants["ExtendedVars/Storage/File1/数值UInt32"] = ++v7;
Int64 v8 = (Int64)context.Variants["ExtendedVars/Storage/File1/数值Int64"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Int64"] = --v8;
UInt64 v9 = (UInt64)context.Variants["ExtendedVars/Storage/File1/数值UInt64"].Value;
context.Variants["ExtendedVars/Storage/File1/数值UInt64"] = ++v9;
float v10 = (float)context.Variants["ExtendedVars/Storage/File1/数值Float"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Float"] = (v10 + 1.1);
double v11 = (double)context.Variants["ExtendedVars/Storage/File1/数值Double"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Double"] = (v11 + 1.1);
decimal v12 = (decimal)context.Variants["ExtendedVars/Storage/File1/数值Decimal"].Value;
context.Variants["ExtendedVars/Storage/File1/数值Decimal"] = (v12 + (decimal)1.1);
context.Variants["ExtendedVars/Storage/File1/数值String"] = DateTime.Now.ToString("HHmmss.fff");
context.Variants["ExtendedVars/Storage/File1/数值BitString"] = "0x12121234";