private void btn_Connect_Click(object sender, EventArgs e) { EndpointWrapper wrapper; string endpointUrl; object item = UrlCB.SelectedItem; wrapper = (EndpointWrapper)item; endpointUrl = wrapper.Endpoint.EndpointUrl; m_Server.Connect(wrapper.Endpoint, true, "OpcUaClient", "SUNRISE"); UrlCB.Enabled = false; List <string> readList = new List <string>(); List <string> rest = new List <string>(); readList.Add("ns=2;s=/Channel/State/actToolLength1"); readList.Add("ns=2;s=/Channel/GeometricAxis/actToolBasePos[u1,2]"); rest = m_Server.ReadValues(readList); while (true) { rest = m_Server.ReadValues(readList); label2.Text = rest[1].ToString(); //label2.Update(); label2.Refresh(); } }
/// <summary> /// Connect to the UA server and read the namespace table. /// The connect is based on the Server URL entered in the Form /// The read of the namespace table is used to detect the namespace index /// of the namespace URI entered in the Form and used for the variables to read /// </summary> private void btnConnect_Click(object sender, EventArgs e) { // Connect to the server try { // Connect with URL from Server URL text box m_Server.Connect(txtServerUrl.Text, "none", MessageSecurityMode.None, false, "", ""); // Toggle enable flag of buttons toggleButtons(true); } catch (Exception ex) { MessageBox.Show("Connect failed:\n\n" + ex.Message); return; } // Read Namespace Table try { List <string> nodesToRead = new List <string>(); List <string> results = new List <string>(); nodesToRead.Add("ns=0;i=" + Variables.Server_NamespaceArray.ToString()); // Read the namespace array results = m_Server.ReadValues(nodesToRead); if (results.Count != 1) { throw new Exception("Reading namespace table returned unexptected result"); } // Try to find the namespace URI entered by the user string[] nameSpaceArray = results[0].Split(';'); ushort i; for (i = 0; i < nameSpaceArray.Length; i++) { if (nameSpaceArray[i] == txtNamespaceUri.Text) { m_NameSpaceIndex = i; } } // Check if the namespace was found if (m_NameSpaceIndex == 0) { throw new Exception("Namespace " + txtNamespaceUri.Text + " not found in server namespace table"); } } catch (Exception ex) { MessageBox.Show("Reading namespace table failed:\n\n" + ex.Message); } }
private int queryPLCQueueSize() { int ret = -1; List <String> retVals = myClientHelperAPI.ReadValues(PLCTransaction.getOneInputParam(opcQueryQSize)); if (retVals.Count > 0) { String firstVal = retVals.ElementAt <String>(0); ret = int.Parse(firstVal); } return(ret); }
/// <summary> /// Writes and displays the new values. /// </summary> private void UpdateCurrentValues() { try { // Prepare call to ClientAPI. List <string> nodesToRead = new List <string>(this.listView.Items.Count); List <string> readResults = new List <string>(); foreach (ListViewItem item in this.listView.Items) { // NodeIds. nodesToRead.Add(item.SubItems[1].Text); } // Call to ClientAPI. readResults = m_Server.ReadValues(nodesToRead); int i = 0; foreach (ListViewItem item in this.listView.Items) { // Update current value. item.SubItems[2].Text = readResults[i]; i++; } } catch (Exception e) { // Update status label. toolStripLabel1.Text = "An error occured."; } }
//ns=3;s="数据块_1"."bbb" /// <summary> /// 读取多个变量 /// </summary> /// <param name="Nodes">读取的地址,格式为:块名.变量名</param> /// <returns></returns> public List <string> PLC_ReadValues(List <string> Nodes) { if (m_Connected) { int i = 0; foreach (string str in Nodes) { Nodes[i] = _GetFormat(str); i++; } return(m_Server.ReadValues(Nodes)); } else { return(null); } }
/// <summary> /// 读多个变量 /// </summary> /// <param name="tag"></param> /// <returns>返回状态为GOOD的变量</returns> public IList <TagItem> Read(IList <TagItem> tag) { List <string> nodeids = new List <string>(); foreach (var item in tag) { nodeids.Add(item.GetNodeId()); } List <string> values = uAClient.ReadValues(nodeids); for (int i = 0; i < values.Count; i++) { tag[i].Value = values[i]; } return(tag); }
public List <string> ReadValues(List <String> nodeIdStrings) { return(myClientHelperAPI.ReadValues(nodeIdStrings)); }