This class performs linear transformations on DataHub points. It gets loaded automatically whenever it is called by a script (because its filename is listed in AutoLoad.g). The code for the LinearXform class is in the script LinearXForm.g, found in the require folder in the Cascade DataHub or OPC DataHub distribution directory. Here's what it looks like:
class LinearXform
{
verbose;
}The verbose instance variable is a flag, which when set to t, will have the script print results to the Script Log.
method LinearXform.cbLinearXform (dst, value, mult, add)
{
if (.verbose)
princ ("xform ", dst, " = ", value, " * ", mult, " + ", add, "\n");
set (dst, value * mult + add);
}The cbLinearXform method prints the input values (if requested), and performs a one-way linear transformation on the destination point (dst).
method LinearXform.AddLinearXform (app, src, dst, mult, add, bidirectional_p?=nil)
{
app.OnChange (src, `(@self).cbLinearXform (#@dst, value, @mult, @add));
if (bidirectional_p && mult != 0)
{
allow_self_reference (src, 1);
allow_self_reference (dst, 1);
app.OnChange (dst, `(@self).cbLinearXform (#@src, value, 1/@mult,
(@-add)/(@mult)));
}
}The AddLinearXform method provides a bidirectional wrapper on the linear transformation method (.cbLinearXform). It uses the allow_self_reference function to have Gamma ignore the self-referential nature of the request. Without that function, Gamma would prevent you from referring back to the point where a change in data originated.
To carry out the bidirectional function, we need to use the quote operators # and @ together. For example, one of the parameters of the quoted .cbLinearXform method is #@src. The @ operator allows the variable src to be evaluated (in this case to the point name), but the # operator prevents the point name from being evaluated to the value of the point.
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.