R
Rob Richardson
Greetings!
I am trying to port an application written in Python into JavaScript
so it can be invoked from a web page. The JavaScript will be self-
contained in the page; no Internet communication is involved.
My script includes the following class:
function PlcRegister(theOpcGroup, theTagName, theHandle)
{
var Value = 0;
var OpcItem; // not used for now
var OpcGroup;
var ServerHandle;
var TagName;
this.OpcGroup = theOpcGroup;
this.TagName = theTagName; // not used, but we might as well store
it in case we want it.
this.Read = Read;
this.Write = Write;
alert ("Creating PlcRegister object for tag " + theTagName);
// this.ServerHandle = opclibAddTagToGroup(theOpcGroup, theTagName,
theHandle);
this.ServerHandle = opclibAddTagToGroup(this.OpcGroup, this.TagName,
theHandle);
alert ("Tag " + this.TagName + " has server handle " +
this.ServerHandle);
function Read()
{
if (this.OpcGroup == undefined)
{
alert ("Trying to reading tag " + this.TagName + " before OPC group
is specified.");
}
this.Value = opclibReadTag(this.OpcGroup, this.ServerHandle, 2);
return this.Value;
}
function Write(value)
{
this.Value = value;
opclibWriteTag(this.OpcGroup, this.ServerHandle, value);
}
}
I have a second class that includes the following:
function RecipeDef(MaxTempSegments, MaxAtmosSegments, theBaseId,
theChargeNumber)
{
this.TGasStpts = new Array(); // 2 Registers Temperature Track -
GasStpts and Duration
this.TDurations = new Array();
this.ATypes = new Array(); // 4 Registers Atmosphere Track -
Type, Setpoint, Duration, Sign
this.AGasStpts = new Array();
this.ADurations = new Array();
this.ASigns = new Array();
function BuildRecipe()
{
for (Index = 0; Index < this.TempSegmentCount; Index++)
{
alert ("Temperature segment loop index: " + Index);
// Temperature Track
OpcTag = TagPrefix + "TTSeg[" + Index.toString() + "]Temp";
alert ("Trying to build temp seg tag point " + OpcTag);
tempTag = new PlcRegister(RecipeOpcGroup, OpcTag, nHandle);
alert ("This operation creates a reference, not a copy!");
///////////////////// The following line
fails! /////////////////////////////////////////////////////////////////
this.TGasStpts[Index] = tempTag;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
alert ("Reference set.");
nHandle = nHandle + 1;
OpcTag = TagPrefix + "TTSeg[" + Index.toString() + "]Time";
alert ("Trying to build temp seg tag point " + OpcTag);
this.TDurations[Index] = new PlcRegister(RecipeOpcGroup, OpcTag,
nHandle);
nHandle = nHandle + 1;
}
}
}
When my script tries to reference an element of the TGasStpts array,
it fails with an "Object expected" error. Why is it doing that? I
think, from the little reading that I've done, it shouldn't be
necessary to explicitly create an array element. The act of setting
it equal to a newly created object will create the element. Is that
wrong?
Thank you very much!
RobR
I am trying to port an application written in Python into JavaScript
so it can be invoked from a web page. The JavaScript will be self-
contained in the page; no Internet communication is involved.
My script includes the following class:
function PlcRegister(theOpcGroup, theTagName, theHandle)
{
var Value = 0;
var OpcItem; // not used for now
var OpcGroup;
var ServerHandle;
var TagName;
this.OpcGroup = theOpcGroup;
this.TagName = theTagName; // not used, but we might as well store
it in case we want it.
this.Read = Read;
this.Write = Write;
alert ("Creating PlcRegister object for tag " + theTagName);
// this.ServerHandle = opclibAddTagToGroup(theOpcGroup, theTagName,
theHandle);
this.ServerHandle = opclibAddTagToGroup(this.OpcGroup, this.TagName,
theHandle);
alert ("Tag " + this.TagName + " has server handle " +
this.ServerHandle);
function Read()
{
if (this.OpcGroup == undefined)
{
alert ("Trying to reading tag " + this.TagName + " before OPC group
is specified.");
}
this.Value = opclibReadTag(this.OpcGroup, this.ServerHandle, 2);
return this.Value;
}
function Write(value)
{
this.Value = value;
opclibWriteTag(this.OpcGroup, this.ServerHandle, value);
}
}
I have a second class that includes the following:
function RecipeDef(MaxTempSegments, MaxAtmosSegments, theBaseId,
theChargeNumber)
{
this.TGasStpts = new Array(); // 2 Registers Temperature Track -
GasStpts and Duration
this.TDurations = new Array();
this.ATypes = new Array(); // 4 Registers Atmosphere Track -
Type, Setpoint, Duration, Sign
this.AGasStpts = new Array();
this.ADurations = new Array();
this.ASigns = new Array();
function BuildRecipe()
{
for (Index = 0; Index < this.TempSegmentCount; Index++)
{
alert ("Temperature segment loop index: " + Index);
// Temperature Track
OpcTag = TagPrefix + "TTSeg[" + Index.toString() + "]Temp";
alert ("Trying to build temp seg tag point " + OpcTag);
tempTag = new PlcRegister(RecipeOpcGroup, OpcTag, nHandle);
alert ("This operation creates a reference, not a copy!");
///////////////////// The following line
fails! /////////////////////////////////////////////////////////////////
this.TGasStpts[Index] = tempTag;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
alert ("Reference set.");
nHandle = nHandle + 1;
OpcTag = TagPrefix + "TTSeg[" + Index.toString() + "]Time";
alert ("Trying to build temp seg tag point " + OpcTag);
this.TDurations[Index] = new PlcRegister(RecipeOpcGroup, OpcTag,
nHandle);
nHandle = nHandle + 1;
}
}
}
When my script tries to reference an element of the TGasStpts array,
it fails with an "Object expected" error. Why is it doing that? I
think, from the little reading that I've done, it shouldn't be
necessary to explicitly create an array element. The act of setting
it equal to a newly created object will create the element. Is that
wrong?
Thank you very much!
RobR