序号 | 应用 |
1 | 客户端实例化 |
private OpcUaClient opcUaClient = new OpcUaClient(); await opcUaClient.ConnectServer("opc.tcp://118.24.36.220:62547/DataAccessServer"); opcUaClient.Disconnect(); | |
2 | 节点读取操作 |
string value = opcUaClient.ReadNode<string>("ns=2;s=Machines/Machine A/Name"); float value = opcUaClient.ReadNode<float>("ns=2;s=Machines/Machine B/TestValueFloat"); | |
3 | 类型未知节点读取操作 |
Opc.Ua.DataValue value = opcUaClient.ReadNode("ns=2;s=Robots/RobotA/RobotMode") | |
4 | 数据订阅 |
private void button2_Click( object sender, EventArgs e ) { // sub OpcUaClient.AddSubscription( "A", "ns=2;s=Machines/Machine B/TestValueFloat", SubCallback ); } private void SubCallback(string key, MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs args ) { if (InvokeRequired) { Invoke( new Action<string, MonitoredItem, MonitoredItemNotificationEventArgs>( SubCallback ), key, monitoredItem, args ); return; } if (key == "A") { // 如果有多个的订阅值都关联了当前的方法,可以通过key和monitoredItem来区分 MonitoredItemNotification notification = args.NotificationValue as MonitoredItemNotification; if (notification != null) { textBox3.Text = notification.Value.WrappedValue.Value.ToString( ); } } } |