总体思路:
用户使用类似https://localhost/data/ulc/ulc.html?panel=web_base_penal\basePanel_web.pnl,$token:123的网页来访问我们的服务器
token等传递给viewStar,在basePenal_we.pnl脚本中将token存储下来

当用户想切换画面时,需要调用http://localhost:8082/web_switch使用POST请求,传入一个JSON格式,再JSON格式中需要传入token,这里的token需要和上面网页设置的token相同

将这些数据进行处理,先判断token,再进行数据的处理

存储数据脚本

首先写一个pnl脚本用于监听http请求。

使用httpServer()可以指定通讯是http请求还是https请求。

使用httpConnect()可以指定1. 回调函数,2. 开放的接口,3. 一些配置文件
通过开放的接口:通过http://localhost:8082/web_switch发送请求来修改DPmessage_web的值,里面包含了外部发送的所有信息

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
26
27
28
29
const string DP_WEB_MESSAGE = "web_message.";

main()
{
httpServer(false, 8083, 0);
int result1 = httpConnect("WebSwitch", "/web_switch", "application/json");
}

string WebSwitch(dyn_string names, dyn_string values, string user, string ip, dyn_string headerName, dyn_string headerValues, int connectionIndex)
{
string _content = "";

for(int i = 1; i <= dynlen(names); i ++ )
{
_content += names[i];
}
blob content = _content;

string str;

if(bloblen(content) > 0)
{
blobGetValue(content, 0, str, bloblen(content));
// DebugTN(str);
dpSet(DP_WEB_MESSAGE, str);
}

return "";
}

问题1:WebSwitch

里面的参数,手册给的为:
string WebSwitch(dyn_string names, dyn_string values, ...)

项目中用的是
string WebSwitch(blob content, ...)

在哪里看的这个语法呢

答:【自己看手册

我输出namescontent
手册的是"7B0D0A2020202022..."
项目中是7b d a 20 20 20 20 22 ...

我试了使用手册给的函数,将dyn_string转化为string,再将string转化为blob就可以解析数据了(文档中也是用了这样的方法)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
// string WebSwtich(blob content, ...)
string WebSwitch(dyn_string names, dyn_string values, ...)
{
string _content = "";

for(int i = 1; i <= dynlen(names); i ++ )
{
_content += names[i];
}
blob content = _content;

...

}

检测数据发生变化的脚本

此pnl脚本用于监听DP中的message是否改变。如果改变了,就会将画面显示给图中蓝线黑框

这个板子的名字叫:Embedded Module,需要将最外层的板子Standard属性中的Layout *属性设置为0,并且将下面的Layout Type设置为HBox或者VBox其中一种。

再选中Embedded Module将其设置为垂直或者水平布局的一种。

dpConnect("listenning", 0, DP_POINT);

  1. "listenning":回调函数,当message改变后,会执行这个回调函数
  2. 0:执行这个函数不会调用"listenning"这个回调函数
  3. DP_POINT:需要监听的点名
1
2
3
4
5
RootPanelOnModule(需要嵌入的panelA地址,
定义panelA的名称(最好与给定的接口类型相同),
需要嵌在哪个panelB上,
panelA的一些参数是什么
);

访问的网址:https://localhost/data/ulc/ulc.html?panel=basePanel_web_2.pnl,$token=123

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
26
27

string token = "";

const string DP_POINT = "message_web.";

main()
{
token = $token;
// DebugTN(token);

dpConnect("listenning", 0, DP_POINT);
}
string getNodeFilePath(string nodeName)
{
return "test.pnl";
}
void listenning(string name, string message)
{
mapping m = jsonDecode(message);
DebugTN(m["token"]);

RootPanelOnModule(getNodeFilePath(m["node"]),
m["node"],
webModel.ModuleName,
makeDynString());
}

如果想访问

https://localhost:443/data/ulc/ulc.html?panel=web_base_penal\basePanel_web.pnl ,\$token:123

https://localhost:<端口名>/data/ulc/ulc.html?<访问的panel相对地址>,$<发送的数据>


查询各个站的信息

1
2
3
4
5
6
7
8
/*
getPt...等函数,是根据node(西一线 镇江分输站 流程图1)查询id,再根据id查询其他信息
使用getPTIndex(node)

int ptIndex = getPTIndex(node);
string path = getPTFileById(ptIndex);
mapping m = getPIParameter(node);
*/