一些提高自动化率的指令

1. 地址相关

1
2
3
//依据HWIO计算IW QW地址
#tempAIw := RD_ADDR(LADDR := #Interface_panel.AI_HW_IO, PIADDR => #AI_rdaddr.piadder, PICount => #AI_rdaddr.picount, PQADDR => #AI_rdaddr.temppiadder, PQCount => #AI_rdaddr.temppicount);
#tempAQw := RD_ADDR(LADDR := #Interface_panel.AQ_HW_IO, PIADDR => #AQ_rdaddr.temppqadder, PICount => #AQ_rdaddr.temppqcount, PQADDR => #AQ_rdaddr.pqadder, PQCount => #AQ_rdaddr.pqcount);
1
2
3
4
5
6
7
8
//将IW值赋值给中间变量
//PEEK默认读取一个BYTE的地址长度,可以_选择长度
#params_AI4ST.CurrentDigitalvalue := PEEK_WORD(area := 16#81, dbNumber := 0, byteOffset := #AI_rdaddr.piadder);
//将中间变量赋值给QW,POKE根据Value的地址长度赋值(程序内部应该判断了TypeOf(#Value)来指定长度)
POKE(area := 16#82,
dbNumber := 0,
byteOffset := #AQ_rdaddr.pqadder,
value := #params_AQ2ST.CurrentDigitalvalue);

2. 序列化和反序列化

1
2
3
4
//序列化,结构变BYTE或者CHAR数组(不能是其他类型)
#ser1 := Serialize(SRC_VARIABLE := "_ralrm".ra.out.status, DEST_ARRAY => "_ralrm".status, POS := #dpos);
//反序列化,ARRAY [*] of BYTE 或者 CHAR 变成结构
#deser1 := Deserialize(SRC_ARRAY := "_ralrm".ra.out.ti, DEST_VARIABLE => "_ralrm".ti_buffer, POS := #dpos_1

3. 设备状态,网络禁用指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
REGION get device status 
//st1
//use or disable IO device
//mode=0:find device status
//mode=1:use mode=2:disable
"_GlobleDB_Manual".State.D_ACT.hw_device := 262;
"_GlobleDB_Manual".State.D_ACT.TmpWord := D_ACT_DP(REQ := "_GlobleDB_Manual".State.D_ACT.req, MODE := "_GlobleDB_Manual".State.D_ACT.mode, LADDR := "_GlobleDB_Manual".State.D_ACT.hw_device, BUSY => "_GlobleDB_Manual".State.D_ACT.busy);

//st2
//device status
//mode=2,IO/DP error
//state: device number in condfiguration view
//258: all the status in system.
"_GlobleDB_Manual".State.Device.io_sys := 258;
"_GlobleDB_Manual".State.Device.mode := 2;
"_GlobleDB_Manual".State.Device.TmpWord := DeviceStates(LADDR := "_GlobleDB_Manual".State.Device.io_sys, MODE := "_GlobleDB_Manual".State.Device.mode, STATE := "_GlobleDB_Manual".State.Device.state);

//st3
//module status
//mode=2 module error
"_GlobleDB_Manual".State.Module.TmpWord := ModuleStates(LADDR := "_GlobleDB_Manual".State.Module.io_device, MODE := "_GlobleDB_Manual".State.Module.mode, STATE := "_GlobleDB_Manual".State.Module.state);

//st4
//io_pn status
END_REGION

4. 模拟量缩放和取消缩放

1
2
3
4
5
6
7
8
9
//OUT = [((FLOAT (IN) – K1)/(K2–K1)) * (HI_LIM–LO_LIM)] + LO_LIM
//Current channel,十进制数变模拟量
#ScalePara1.HI_LIM := 20.0;
#ScalePara1.LO_LIM := -20.0;
#ScalePara1.BIP := 1;
#tempScaleInt := SCALE(IN := "AIchannel1", HI_LIM := #ScalePara1.HI_LIM, LO_LIM := #ScalePara1.LO_LIM, BIPOLAR := #ScalePara1.BIP, OUT => "TEST_DB".AImodule.channel1);

//UNSCALE,模拟量转换成十进制数
#tempUNScaleWord := UNSCALE(IN := #repeataccur.ana_value, HI_LIM := 10.0, LO_LIM := -10.0, BIPOLAR := 1, OUT => #repeataccur.di_value);

5. 组合序列和序列解析

1
2
3
4
5
6
7
8
//SCATTER,解析
SCATTER(IN := #SourceWord,
OUT => #DestinationArray);

//GATHER,组合
GATHER(IN := #SourceArray,
OUT => #DestinationWord);

6. 交换

1
2
3
4
5
6
// 观察输出bit交换规律
"Tag_Result" := SWAP("Tag_Value");

>>> Tag_Value:0000 1111 0101 0101
>>> Tag_Result:0101 0101 0000 1111


一些提高自动化率的指令
http://example.com/2024/07/21/一些提高自动化率的指令/
作者
xiao cuncun
发布于
2024年7月21日
许可协议