• Not Answered

DeltaV Live - How to use OnWrite function of a variable

I am trying to migrate a DeltaV operate event type scheduler. But I am stuck on OnWrite function, which I think i can't go further anymore after research and GSC call (GSC suggested to use timer which worked but I don't like).

I first created a variable Number1, animation of this variable DLSYS.Read("CM/COLOR.CV")

then I entered the script of onWrite as below, which gave me the error message : "A function whose declared type is neiter 'void' nor 'any' must return a value"

// let newValue=DLSYS.CondReadAsync("CM/COLOR.CV").Value

    let newValue=DLSYS.Read("CM/COLOR.CV").Value

    if (newValue==1)

    {ENV.RunAsync(GL.Library.X_GREEN_S, "green.txt")}

    else if (newValue==2)

    {ENV.RunAsync(GL.Library.X_RED_B, "red.txt")}

How to solve this problem?  Any suggest is appreciated.

6 Replies

  • OnWrite needs to return the value to be written.

    What are you trying to get done?
  • OnWrite needs to return the value to be written.

    What are you trying to get done?
  • In reply to Matt Stoner:

    I am trying to run different exe files according to the value of this variable "number1", and this variable is getting the value from control module CM, parameter COLOR.
    For the test purpose, I run notepad.exe instead, and open different txt files according to the value of variable.
  • In reply to shen:

    As Matt said, you need to finish the script to return the new value from the CM/COLOR.CV. This will set your number1 variable equal to the parameter.

    The error is that you are not returning a value, and the value to return is the new cm color numver

    Andre Dicaire

  • In reply to Andre Dicaire:

    Can you please tell me what's the script to return the new value from the CM/COLOR.CV?

    apparently, my script is not correct : let newValue=DLSYS.Read("CM/COLOR.CV").Value

    I thought that "set number1 variable equal to the parameter" is achieved by using animation script of variable Number1: DLSYS.Read("CM/COLOR.CV").

    I also though the script in OnWrite is the script like deltav operate event schedule action script. Any example?

  • In reply to shen:

    put "return newValue;" as the last line of your script