OPC .Net client server toolkits for OPC DA, HDA, AE, XML-DA      Advanced
         OPC .Net client server toolkits for OPC DA, HDA, AE, XML-DA
Online Tools
- OPC Error Lookup
* privacy and security Guaranteed  
Background Server Access Sample Application Login  

Background Server Access Sample Code

The following C# code is a complete Windows application that shows the current values of three items, two simple values and one array value.
The sample is a high quality application that uses the OPCDA.NET background server access classes. It catches and reports all possibly occuring server handling errors.
All server access is done in background threads. The application doesn't become unresponsive due to server access issues.

using System;
using System.Windows.Forms;
using OPCDA.NET;

namespace  Sample
   public partial class Form1 : Form
      public Form1()

      BGServer BGSrv = null;

      private void Form1_Load( object sender, EventArgse)
         BGSrv = new BGServer(this);
         BGSrv.GeneralError += new OnBGGeneralError(srv_GeneralError);
         BGSrv.Connect("Advosol.SimDAServer.1", null, new OnBGSrvConnected(OnServerConnected));

      private void OnServerConnected(BGException ex, object tag)
         if (ex != null) // unsuccessful
            MessageBox.Show(ex.Message, "Server Connect Error");
         else // successfully connected, create a databind object
            BGSrv.AddDataBind( "DB1", 500, null, new OnBGSrvAddDataBind( OnNewdataBind ) );

      private void OnNewdataBind( BGException ex, BGDataBind db1, objecttag )
         if( ex != null ) // unsuccessful
            MessageBox.Show(ex.Message, "DataBind Error");
         else // DataBind successfully created
            // Bind controls to OPC items.
            db1.Subscribe( "SimulatedData.Signal", this.checkBox1, null, null );
            db1.Subscribe( "Dynamic.Analog Types.Double[]", this.listBox1, 3, new DataBindFormat("F2"), null, null );
            db1.Subscribe( "SimulatedData.Sine", this.textBox1, null, null );

      private void srv_GeneralError(string info, BGException ex, object tag)
         string txt;
         if ((tag != null) && (tag.GetType() == typeof(string))) 
            txt = info + " (" + tag.ToString() + ") : " + ex.Message;
         else    // no or unknown data in tag
            txt = info + " : " + ex.Message;
         MessageBox.Show( txt, "Server Access Error" );
      private void btnClose_Click(object sender, EventArgs e)
home | contact us | return policy | privacy policy | security policy | Copyright © 2018 Advosol Inc. All Rights Reserved.