/// <summary> /// Called when an asynchronous read request completes. /// </summary> private void OnReadComplete(object clientHandle, OpcDa::ItemValueResult[] results) { try { if (InvokeRequired) { BeginInvoke(new OpcDa::ReadCompleteEventHandler(OnReadComplete), new object[] { clientHandle, results }); return; } if (!m_handle.Equals(clientHandle)) { return; } ResultsCTRL.Initialize(m_subscription.Server, null, results); m_request = null; m_results = results; OkBTN.Enabled = true; CancelBTN.Enabled = true; GoBTN.Visible = true; StopBTN.Visible = false; } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// Executes a read request for the current set if items. /// </summary> private void DoRead() { try { // read from server. OpcDa::Item[] items = ItemsCTRL.GetItems(); if (items.Length == 0) { return; } OpcDa::ItemValueResult[] results = null; if (m_subscription != null) { if (m_synchronous) { results = m_subscription.Read(items); } else { results = new AsyncRequestDlg().ShowDialog(m_subscription, items); if (results == null) { return; } } } else { // add dummy client handles to test that they get returned properly. foreach (OpcDa::Item item in items) { item.ClientHandle = item.ItemName; } results = m_server.Read(items); } // save results. m_values = results; BackBTN.Enabled = true; NextBTN.Enabled = false; CancelBTN.Visible = false; DoneBTN.Visible = true; OptionsBTN.Visible = false; ItemsCTRL.Visible = false; ResultsCTRL.Visible = true; // display results. ResultsCTRL.Initialize(m_server, (m_subscription != null) ? m_subscription.Locale : m_server.Locale, results); } catch (Exception e) { MessageBox.Show(e.Message); } }
/// <summary> /// Executes a write request for the current set if items. /// </summary> private void DoWrite() { try { // get the selected items OpcDa::ItemValue[] items = ItemsCTRL.GetItems(); // write to server. Opc.IdentifiedResult[] results = null; if (m_subscription != null) { if (m_synchronous) { results = m_subscription.Write(items); } else { results = new AsyncRequestDlg().ShowDialog(m_subscription, items); if (results == null) { return; } } } else { // add dummy client handles to test that they get returned properly. foreach (OpcDa::ItemValue item in items) { item.ClientHandle = item.ItemName; } results = m_server.Write(items); } // create a list of item value results. ArrayList values = new ArrayList(); for (int ii = 0; ii < items.Length; ii++) { OpcDa::ItemValueResult value = new OpcDa::ItemValueResult(items[ii]); value.ItemName = results[ii].ItemName; value.ItemPath = results[ii].ItemPath; value.ClientHandle = results[ii].ClientHandle; value.ServerHandle = results[ii].ServerHandle; value.ResultID = results[ii].ResultID; value.DiagnosticInfo = results[ii].DiagnosticInfo; values.Add(value); } // save results. m_values = (OpcDa::ItemValueResult[])values.ToArray(typeof(OpcDa::ItemValueResult)); BackBTN.Enabled = true; NextBTN.Enabled = false; CancelBTN.Visible = false; DoneBTN.Visible = true; OptionsBTN.Visible = false; ItemsCTRL.Visible = false; ResultsCTRL.Visible = true; // display results. ResultsCTRL.Initialize(m_server, (m_subscription != null) ? m_subscription.Locale : m_server.Locale, m_values); } catch (Exception e) { MessageBox.Show(e.Message); } }