Skip to main content

WEBfactory 2010

Working with WFServerClient Interface

Abstract

Check out this article and learn how to work with the WFServer Client interface and which are the available management options.

This section shows how to add a WFServerClient instance to read or write signals from any other connector or OPC server.

Adding WFServerClient instance to Form1

Similar to WFServerConnector, we add the WFServerClient instance to Form1.cs:

public partial class Form1 : Form1
{
	WFServerConnector wfsc;
	WFServerClient wfsClient;
	public Form1()
	{
		
	}
}
Creating WFServerClient instance

The instance is then created within the constructor of Form1:

public Form1()
{
	InitializeComponent();

	wfsc = new WFServerConnector("SampleConnector1");
	wfsc.WriteAsyncRequest += new WFWriteAsyncRequestEventHandler(wfsc_WriteAsyncRequest);

	int result;
	int returnValue = wfsc.CreateSignal("IOBuffer1", out result);

	if (returnValue != 0)
	{
		MessageBox.Show("CreateSignal returned: " + WFErrorCodes.ToErrorString(returnValue));
		return;
	}

	returnValue = wfsc.UpdateSignal("IOBuffer1", 7, out result);
	
	if (returnValue != 0)
	{
		MessageBox.Show("UpdateSignal returned: " + WFErrorCodes.ToErrorString(returnValue));
		return;
	}

	wfsClient = new WFServerClient();
}

Now we can access this helper class like our wfsc variable.

Accessing WFServerClient instance
  1. Add a button to the Form1:

  2. Double click the button inside the form and Visual Studio will jump to the code view:

    private void button1_Click(object sender, EventArgs e)
    {
    
    }
  3. Now we add the code to read a WEBfactory 2010 signal:

    private void button1_Click(object sender, EventArgs e)
    {
    	if (wfsClient != null)
    	{
    		object val;
    		wfsClient.ReadSignal("Setpoint 1", out val);
    
    		if (val == nul) val = "<null>";
    		MessageBox.Show(val.ToString());
    	}
    
    }

    This test assumes to have the Demo project database as active database in WEBfactory 2010Studio.

    You can also define a VChannel called “Setpoint 1" to your current Studio project.

With a running WEBfactory 2010 server, you should get a MessageBox with the current value of Setpont 1.