I am reading lines from a file and adding them to a ScriptGroup. Once the size of the group is 50, the code sends all the objects in the Scriptgroup to a TCPobject, then empties the Scriptgroup.
%bufferSz = 50; //50 brick lines per JSON command
%liBroup = new ScriptGroup();
while (!%f.isEOF())
{
%currL = %f.readLine();
%currL = strReplace(%currL, "\"", "\\\"");
%linesRead++;
if (%liBroup.getCount() == %bufferSz)
{
%sendCmd = "{\"cmd\": \"UPLOAD_LINES\", \"sessionID\": \"" @ %this.sessionID @ "\", \"lineCt\": \"" @ %liBroup.getCount() @ "\", \"lines\": [";
for (%i = 0; %i < %liBroup.getCount(); %i++)
{
if (%i + 1 < %liBroup.getCount()) //not the last iteration
%sendCmd = %sendCmd @ "{\"" @ %i @ "\": \"" @ %liBroup.getObject(%i) @ "\"}, ";
else
%sendCmd = %sendCmd @ "{\"" @ %i @ "\": \"" @ %liBroup.getObject(%i) @ "\"}";
}
%sendCmd = %sendCmd @ "]}";
%this.tcpObj.sendJSON(%sendCmd);
%liBroup = new ScriptGroup(); //this empties the group, by creating a new object
}
%liBroup.add(%currL);
echo("IBL client: Added line to group. %liBroup's value: " @ %liBroup);
if (%f.isEOF()) //last line
{
%sendCmd = "{\"cmd\": \"UPLOAD_LINES\", \"sessionID\": \"" @ %this.sessionID @ "\", \"lineCt\": \"" @ %liBroup.getCount() @ "\", \"lines\": [";
for (%i = 0; %i < %liBroup.getCount(); %i++)
{
if (%i + 1 < %liBroup.getCount()) //not the last iteration
%sendCmd = %sendCmd @ "{\"" @ %i @ "\": \"" @ %liBroup.getObject(%i) @ "\"}, ";
else
%sendCmd = %sendCmd @ "{\"" @ %i @ "\": \"" @ %liBroup.getObject(%i) @ "\"}";
}
%sendCmd = %sendCmd @ "]}";
%this.tcpObj.sendJSON(%sendCmd);
}
}
Then I get these console errors, every time a line is read:
Set::add:: Object "2x2F\" -80.5 -68 6.7 0 0 15 0 0 1 1 1" doesn't exist
The string inside the quotes varies depending on what brick it is.