Showing results 1 to 5 of 5

Thread: read variable from runtime

  1. #1
    Join Date
    24.05.2012
    Location
    Augsburg
    Posts
    30

    Unglücklich read variable from runtime

    Hi,

    i am a beginner with zenon and have Problems with reading a variable from the runtime.

    public void Macro1
    {
    int x=0;

    zenOn.IVariable yVar = this.Variables().Item("testvar1_2");

    x = (int)yVar.get_Value(0); <------does not work , x is always 0

    .....

    }

    but it does not work. The x Value is always 0

  2. #2
    Join Date
    20.08.2009
    Posts
    293

    Default AW: read variable from runtime

    Hi,

    is the variable you want to read "advised" (visible in a screen, in an online container, defined as an alarm, set to DDE active", ...)

    If not, you won't be able to read a value until the variable is advised.

    Have also look at:
    http://www.copadata.com/forums/showthread.php?t=1129
    http://www.copadata.com/forums/showthread.php?t=1074
    http://www.copadata.com/forums/showthread.php?t=1542

    Regards,
    Bernhard

  3. #3
    Join Date
    24.05.2012
    Location
    Augsburg
    Posts
    30

    Default Re: read variable from runtime

    Thanks.... it works
    i did it like this, whithout any adivising. I hope this is a good way.


    public void Macro1()
    {
    float x = 0;
    x = Convert.ToSingle(this.Variables().Item("PLCVar1").get_Value("PLCVar1"));
    this.Variables().Item("PLCVar2").set_Value(0,x);
    }

  4. #4
    Join Date
    20.08.2009
    Posts
    293

    Default AW: Re: read variable from runtime

    Quote Originally Posted by armins View Post
    Thanks.... it works
    i did it like this, whithout any adivising. I hope this is a good way.


    public void Macro1()
    {
    float x = 0;
    x = Convert.ToSingle(this.Variables().Item("PLCVar1").get_Value("PLCVar1"));
    this.Variables().Item("PLCVar2").set_Value(0,x);
    }
    If this code works, the problem was most likely with the casting of the value.

    Nevertheless, besides this the value has to be advised to be readable in VSTA.
    (Which is the case if it is shown in a screen at the time being read for example).

    Regards,
    Bernhard

  5. #5
    Join Date
    24.05.2012
    Location
    Augsburg
    Posts
    30

    Lächeln Re: AW: Re: read variable from runtime

    Quote Originally Posted by bernhardf View Post
    If this code works, the problem was most likely with the casting of the value.

    Nevertheless, besides this the value has to be advised to be readable in VSTA.
    (Which is the case if it is shown in a screen at the time being read for example).

    Regards,
    Bernhard
    Thank you Bernhard.

Similar Threads

  1. VSTA read variable value's another project!
    By dvangenderen in forum VSTA
    Replies: 5
    Last Post: 1st December 2011, 10:04
  2. Replies: 2
    Last Post: 22nd September 2011, 01:32
  3. Variable Unreadable in runtime
    By whitetaru in forum Drivers
    Replies: 6
    Last Post: 12th May 2011, 03:23
  4. Replies: 12
    Last Post: 25th November 2010, 10:54
  5. Replies: 4
    Last Post: 21st June 2010, 07:12

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •