我正在创建一个连接到 OPC 服务器并读取标签属性的 MATLAB 应用程序。MATLAB 文档告诉我,我可以添加一个组,添加标签项,然后读取值:
grp = addgroup(da, 'ExRead');
itm = additem(grp, 'Tag.Argument');
问题是我不知道标签参数,在我的应用程序中,用户正在弹出菜单中选择一个可用标签,并且该值被写入一个字符串,但是当我调用时:
val = get(handles.popupmenu1, 'Value'); // Ask for Value selected item
string_val = get(handles.popupmenu1, 'String'); // Ask for string
stringName = string_val{val}; // Ask for string corresponding to the specified value
set(handles.text1, 'String', stringName); // Display the selected tag
item1 = additem(Group1, stringName); // Add the selected string to a global group "Group1"
read1 = read(Group1, item1); // Read the value
set(handles.text11, 'String', read1); // Display the value
但是当我运行代码时,MATLAB 会产生错误。我想问题是item1 = additem(Group1, stringName);
在所有 MATLAB 文档示例中,我看到类似item1 = additem(Group1, 'adres.adres.1');
这应该解释为什么我无法将任何数据添加到Group1
.
但是如何将项目添加到必须由用户指定/选择的标签组?