1. 升级SmartWeb后台及页面程序至2019-04-19以后的版本。
2. 在SmartWeb中添加参数配置项:
配置WEB参数:参考《MsgProxy消息代理配置》
【备注1:】配置websocket服务,如果有多个服务用分号隔开
KEY:dms.message.proxy.server.host
值:192.222.30.43:12000;192.222.30.44:12000
【备注2:】有些现场没有配置消息客户端,需要先配上
KEY:dms.msg.proxy.consumer.enabled
值:1
可以配在“短信消息处理服务”中,也可以配置在“smartweb-扩展参数”中,如下图(二选一):
3. 仿照文件 $SMARTSYS_HOME/data/pic/demo/demo_statistics.svg 进行编写javascript脚本
var g_BusMsgTimerID = -1; //定时器ID
var TIMER_LENGTH = 1000; //定时器时长:毫秒
//入口函数
function begin()
{
Hmi.changeLang();
//关联信号和槽函数
pushButton.clicked.connect(YK_SuccessRate);
pushButton_1.clicked.connect(YX_AccuracyRate);
pushButton_2.clicked.connect(RTU_CoverRate);
pushButton_3.clicked.connect(RTU_RtOnlineRate);
//注册监听消息
MsgMng.enableAutoRecv(false);
MsgMng.subTopic("MT_RESPONSE_STATISTICS_RESULT");
//开启定时器
g_BusMsgTimerID = setInterval(OnTime, 1000);
}
function YK_SuccessRate()
{
label.text = "结果:查询中...";
var request_info = {};
request_info.request_id = 1; //请求编号,多次请求建议使用不同的编号
request_info.kpi_type = "YK_SuccessRate"; //请求类型
request_info.area_resp = 501; //责任区ID
//下面是定制化条件:遥控成功率只支持时间范围查询
//request_info.time_range = "2019-01-01 00:00:00, 2019-04-01 00:00:00";
var retCode = MsgMng.sendMsg("MT_QUERY_STATISTICS_RESULT", request_info);
if (retCode < 0)
alert(Tr.tr("发送请求开始消息失败,retCode")+"=" + retCode);
}
function YX_AccuracyRate()
{
label_1.text = "结果:查询中...";
var request_info = {};
request_info.request_id = 2; //请求编号,多次请求建议使用不同的编号
request_info.kpi_type = "YX_AccuRacyRate"; //请求类型
request_info.area_resp = 501; //责任区ID
//下面是定制化条件:遥信正确率只支持时间范围查询
request_info.time_range = "2019-01-01 00:00:00, 2019-04-01 00:00:00";
var retCode = MsgMng.sendMsg("MT_QUERY_STATISTICS_RESULT", request_info);
if (retCode < 0)
alert(Tr.tr("发送请求开始消息失败,retCode")+"=" + retCode);
}
function RTU_CoverRate()
{
label_2.text = "结果:查询中...";
var request_info = {};
request_info.request_id = 3; //请求编号,多次请求建议使用不同的编号
request_info.kpi_type = "RTU_CoverRate"; //请求类型
request_info.area_resp = 271; //责任区ID
var retCode = MsgMng.sendMsg("MT_QUERY_STATISTICS_RESULT", request_info);
if (retCode < 0)
alert(Tr.tr("发送请求开始消息失败,retCode")+"=" + retCode);
}
function RTU_RtOnlineRate()
{
label_3.text = "结果:查询中...";
var request_info = {};
request_info.request_id = 4; //请求编号,多次请求建议使用不同的编号
request_info.kpi_type = "RTU_RtOnlineRate"; //请求类型
request_info.area_resp = 271; //责任区ID
request_info.comm_type = null; //通讯方式(对应值见菜单表)
request_info.manu_fac = null; //终端厂家(对应值见菜单表)
request_info.is_transmit = null; //生命周期(对应值见菜单表)
var retCode = MsgMng.sendMsg("MT_QUERY_STATISTICS_RESULT", request_info);
if (retCode < 0)
alert(Tr.tr("发送请求开始消息失败,retCode")+"=" + retCode);
}
//定时器
function OnTime()
{
var response_info = MsgMng.recvMsg();
if(!response_info) return;
if(!response_info.name) return;
if(response_info.name.indexOf("MT_QUERY_STATISTICS_RESULT") >= 0)
alert("MT_QUERY_STATISTICS_RESULT");
if(response_info.name.indexOf("MT_RESPONSE_STATISTICS_RESULT") >= 0)
{
var msg_content = JSON.parse(response_info.buf);
if (Number(msg_content.requestId) == 1)
label.text = "结果:" + msg_content.resultValue;
else if (Number(msg_content.requestId) == 2)
label_1.text = "结果:" + msg_content.resultValue;
else if (Number(msg_content.requestId) == 3)
label_2.text = "结果:" + msg_content.resultValue;
else if (Number(msg_content.requestId) == 4)
label_3.text = "结果:" + msg_content.resultValue;
else if (Number(msg_content.requestId) == 5)
label_4.text = "结果:" + msg_content.resultValue;
}
}
4. 至此本区HMI应能取到指标
5. 配置消息跨区穿透(参考文章:《跨区消息穿透定义》)
正向添加消息类型(real态):MT_QUERY_STATISTICS_RESULT=0
反向添加消息类型(real态):MT_RESPONSE_STATISTICS_RESULT=0