【发布时间】:2018-03-19 13:28:29
【问题描述】:
我有一个 Kepware OPC 服务器,我能够连接到我的客户端(OPC Foundation UA lib)。我在 Kepware 中创建了一个设备,并在其中创建了一个组。我想从数据库中读取 opc 标签并动态创建它们。
如何在 PLC 中动态创建带有地址的项目?
【问题讨论】:
我有一个 Kepware OPC 服务器,我能够连接到我的客户端(OPC Foundation UA lib)。我在 Kepware 中创建了一个设备,并在其中创建了一个组。我想从数据库中读取 opc 标签并动态创建它们。
如何在 PLC 中动态创建带有地址的项目?
【问题讨论】:
我可以推荐你看看 KepServerEX Configuration API。基本上,它为您提供对所有 KEPServerEX 实例的完整远程管理和配置控制。在您的情况下,您可以在从数据库中读取所需信息(例如标签名称、标签地址、标签数据类型)后,通过简单的 RESTful API 调用在设备级别动态生成标签。
请参阅this guide 了解更多信息,以启用和测试配置 API。
我还从 Kepware 的示例项目中复制了以下一段代码,以供您参考:
function createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr) {
console.log("Creating " + inputTag + " with address " + inputTagAddr);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + '/devices/' + inputDevice + '/tags',
data: '{"common.ALLTYPES_NAME":"' + inputTag + '","servermain.TAG_ADDRESS":"' + inputTagAddr + '","servermain.TAG_DATA_TYPE":' + inputTagType + '}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, status, xhr) {
console.log(inputTag + " created under " + inputDevice);
},
error: function(JSON, status, xhr) {
console.log("Creation of " + inputTag + " failed!");
}
});
}
【讨论】:
在 Kepware 配置中,只有某些驱动程序能够动态创建标签。例如,大多数 Allen-Bradley 套件可以动态搜索和添加标签,而 Modbus 等较低级别的驱动程序则不能。所以它总是取决于 Kepware 中的设备使用什么驱动程序。要查找每个驱动程序的单独配置手册,请在此处搜索:
https://www.kepware.com/en-us/products/kepserverex/product-search/
【讨论】: