Define methods in C#

You can define methods and OPC UA methods in C#.

Method

Within a NetLogic, you can define a new method (for example,
Foo
) by using the following syntax:
public void Foo() { // Code to run }
TIP: You can define multiple methods within a class.

OPC UA method

OPC UA methods:
  • Can be referenced at design time.
  • Are callable at runtime.
To define an OPC UA method, add
[ExportMethod]
before the method. See the following example.
[ExportMethod]
public void Foo() { // Code to run }
For more information, see Create an OPC UA method.

Method arguments

You define method arguments in round brackets
()
after the method name.
An OPC UA method can have any number of input and output arguments.
IMPORTANT: If you edit the arguments of a method associated with an event in
FactoryTalk Optix Studio
, you must associate the method again.
To define an input argument:
  • Indicate the data type between the round brackets followed by the argument name.
  • Separate each argument with a comma.
In the following example, two integer input arguments,
speed
and
rpm
, are declared:
public void Foo(
int speed
,
int rpm
) { // Code to run }
To define an output argument:
  • Indicate the keyword
    out
    followed by the data type and argument name between the round brackets.
  • Separate each argument with a comma.
  • Assign the values to the output arguments.
In the following example, two output arguments are defined,
result
and
motorSpeed
, of string and integer types respectively:
public void Foo(
out string result
,
out int motorSpeed
) { result= "Ok"; motorSpeed = motor.speed; }
You can define both input and output arguments for the same method. In the following example, two input and two output arguments are defined:
public void Foo(
int speed
,
int rpm
,
out string result
,
out int motorSpeed
) { result = "Ok"; motorSpeed = motor.speed; }
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.