Write Data: The Set Module
Tags that write data to a driver tag must have a subroutine module named "Set". This module will perform 3 actions:
- Check that the value to be written is valid. Do not write an invalid value.
- Scale or invert the value for the PLC according to the tag's scaling parameters.
- Ensure that the value is sent to all workstations in the network with a call to the RPCManager's Send function.
The return value from the Write() function will be the object value of the write module launched. When this value becomes invalid, the caller can assume that the write is complete. Note that, for a client machine on a network, this value will always be invalid.
The following example is taken from the Analog Control tag:
< {======================== AnalogOutput\Set ==========================} { This subroutine writes a value to SitePoint. The parameter is the } { value to write, which may be inverted before writing. } { } {====================================================================} Set ( NewValue { Value to write to the SitePoint }; ) [ WriteObj { Object value of launched write }; WriteValue { Actual value written }; ] Set [ If 1; [ NewValue = PickValid(Limit(NewValue, ScaledMin, ScaledMax), NewValue); SaveValue = Value = NewValue; {**** Don't bother to write to the PLC if the value is invalid *****} IfThen (Valid(Value), WriteValue = PickValid(Scale(NewValue, ScaledMin, ScaledMax, UnscaledMin, UnscaledMax), NewValue); WriteObj = SitePoint\Driver\Write(Address, 1, &WriteValue); ); {***** Send the value to everybody *****} \RPCManager\Send(SitePoint\Driver\RPCService { service }, \LocalGUID { GUID },\RPC_ACCEPT_FILTER {mode cut-off }, 1 { server }, Invalid { machine }, 1 { clients }, 0 { locally }, 1 { recursive }, "SetValue" { module }, "RPCManager" { scope }, Root { queue data }, Invalid { InputSessionID }, { Parameters: } \LocalGUID, Concat("VTSDB\", Name), "Value", Value); Return(WriteObj); ] ] { End of AnalogOutput\Set } >