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 global Variable on the plc.

[Visual Basic]

Public Overloads Sub New( _

  ByVal cpu As Cpu, _

  ByVal name As String _

)

[C#]

Variable(

  Cpu cpu,

  string name

);

Parameters

cpu

Cpu-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

// CPU already connected
// Getting global variable list from the plc
cpu.Variables.Upload();
cpu.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 = cpu.Variables["var_01"];        // Variable already exists
    else
        myVar = new Variable(cpu,"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]