Variable Constructor

<< 点击显示目录 >>

主页  PVI通信 > PVI帮助信息 > PVI Services > BR.AN.Namespace > BR.AN.PviServices > Variable Class > Variable Constructor >

Variable Constructor

BR.AN.PviServices .NET


Initializes a new instance of the variable class to get connected to a local variable on the plc.

[Visual Basic]

Public Overloads Sub New( _

  ByVal task As Task, _

  ByVal name As String _

)

[C#]

Variable(

  Task task,

  string name

);

Parameters

task

Task-object

name

variable name

Remarks

This instance will be automatically added to the parents variable collection. For this reason its necessary to check this collection for already existing objects.

Exceptions

Exception Type

Condition

ArgumentException

Variable object already exists.

Example

// Task already connected
// Getting local variable list from the task on the plc
task.Variables.Upload();
task.Variables.Uploaded += new PviEventHandler(Variables_Uploaded);
...
...
private void Variables_Uploaded(object sender, PviEventArgs e)
{
    Variable myVar=null;
    // Creating new variable "var_01" and get connected to it
    if ( cpu.Variables.ContainsKey("var_01") )
        myVar = task.Variables["var_01"];        // Variable already exists
    else
        myVar = new Variable(task,"var_01");    // Variable not exist -> create
    myTask.Connect();
}

See Also

Variable Class | BR.AN.PviServices Namespace | Variable Constructor Overload List


Generated from assembly BR.AN.PviServices [8.1.0.4]