compared with
Version 3 by Darren Fraser
on Jul 02, 2008 22:03.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (28)

View Page History
{toc:outline=true|printable=false|style=none|indent=20px}
h1. Referencing the Scx automation interface
Using the automation interface with C# is very similar to using it within VB, apart from the obvious syntax differences between the two languages.

# When C# is running, select Project - Add Reference
# Select the COM tab
# Scroll down until you find the _"Scx V6 Automation Interface_" entry
# Select OK. _You will see the entry added to the References section in the solution explorer (by default on the right hand side of the screen)_.
# Use the following code to connect to the server and create an internal analog point.

{code}
{panel}
string sSystem = "MAIN";
string sUid = "Eng";
string sPwd= "";
// Define the server object and create a new instance of it
ScxV6DbClient.ScxV6Server objServer = new ScxV6DbClient.ScxV6Server();
// Connect to the server
objServer.Connect(sSystem, sUid, sPwd);
// Define the object and create a new internal analog point
ScxV6DbClient.ScxV6Object obj = objServer.CreateObject("CPointAlgManual", "$Root");
{panel}
{code}

Note: You can download the free *Visual C# 2005 Express Edition* (along with other languages) from the Microsoft website. This can be used for commercial software development (see http://msdn.microsoft.com/vstudio/express/support/faq/ point 4).
// Define the server object and create a new instance of it
ScxV6DbClient.ScxV6Server objServer = new ScxV6DbClient.ScxV6Server();

// Connect to the server
objServer.Connect(sSystem, sUid, sPwd);

// Define the object and create a new internal analog point
ScxV6DbClient.ScxV6Object obj = objServer.CreateObject("CPointAlgManual", "$Root");
{code}
Note: You can download the free Visual C# 2005 Express Edition (along with other languages) from the Microsoft website. This can be used for commercial software development (see [http://msdn.microsoft.com/vstudio/express/support/faq/] point 4).

h1. Accessing properties/methods directly
Using Obj.Interface.CurrentValue for example, like you would from VB won't work from C#.
This is because "Interface" is a vanilla IDispatch so you need to use late binding.

**In VB.Net the compiler will do the plumbing for you automatically*
* In C# you currently need to use reflection manually, as below.
Using Obj.Interface.CurrentValue for example, like you would from VB won't work from C#. This is because "Interface" is a vanilla IDispatch so you need to use late binding.

In VB.Net the compiler will do the plumbing for you automatically. In C# you currently need to use reflection manually, as shown in the example below.
{code}
{panel}
// Get object
ScxV6DbClient.ScxV6Object O = S.FindObject( "New Analogue Point" );
// The line below doesn't because Interface is declared in the IDL as a vanilla IDispatch, instead we need to use late-binding via Relection
// O.Interface.LoadDataValues( Values, Times, Qualities );
{panel}

{panel}
// Instead, use relection:
// Get the Historic aggregate
object Historic = O.Interface.GetType().InvokeMember( "Historic", System.Reflection.BindingFlags.GetProperty, null,O.Interface,null );
// Invoke the LoadDataValues method
if ( Historic != null )
Historic.GetType().InvokeMember( "LoadDataValues", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new object[] { Values, Times, Qualities } );
{panel}
{code}

// The line below doesn't work because Interface is declared in the IDL as a vanilla IDispatch, instead we need to use late-binding via Reflection
// O.Interface.LoadDataValues( Values, Times, Qualities );
{panel}
[JIRA entry PDEV-189|http://jirasvr:8091/browse/PDEV-189]
// Instead, use reflection:
// Get the Historic aggregate
object Historic = O.Interface.GetType().InvokeMember( "Historic", System.Reflection.BindingFlags.GetProperty, null,O.Interface,null );
{panel}
Category:Automation Interface|C
// Invoke the LoadDataValues method
if ( Historic != null )
Historic.GetType().InvokeMember( "LoadDataValues", System.Reflection.BindingFlags.InvokeMethod, null, Historic, new object[] { Values, Times, Qualities } );
{code}