AGG Software Forums
November 21, 2024, 07:16:40 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome on our forum!
 
   Home   Help Search Login Register  

Pages: [1]
  Print  
Author Topic: Getting started with the scripting module  (Read 29052 times)
mccallum4004
Jr. Member
**

Karma: +0/-0
Posts: 15


View Profile
« on: June 23, 2010, 12:58:05 AM »

From the parser, I generate a DATA string.  This string is really an array of two byte short integers.  In the expressions module, I can get the integer value correctly sent over DDE if I use the expression DATAi = WORDTOSTR(SUBSTR(DATA,2*i+1,2)).  However, I am not really interested in the individual data points but would like to calculate a result from the whole array and send that.  So I have tried using the scripting module.

I'm getting an error message (very vague - "There is an error in the script") when I try to run a script.  I have some experience with Pascal and C++ but not scripting versions.  There is little detail in the help file for the scripting module.  Is the argument for cos, for example, in degrees or radians?  In particular, how does one get a variable from the parser into the script.  I would like to turn DATA into word dist[141].  From there, I think I can calculate the RESULT value that I want.  Then can I send the result out via DDE just by calling the scripting variable as I did the expression variable?

Logged
Arthur Grasin
Tech. Support
Administrator
Hero Member
*****

Karma: +0/-0
Posts: 806



View Profile WWW
« Reply #1 on: June 23, 2010, 09:52:22 AM »

Please, look aе samples. You can find samples in the "program folder\plugins\scriptexec\Samples" folder. Retrieving a parser variable (Pascal script):

Code:
var sName1:string = 'DATA';
     sName2:string = 'RESULT';
     data: string;
     res: double;
begin
// checks that a variable is stored before
if IsVariableStored(sName1) then
 // retrieves a stored variable
 data := PopVariable(sName1)
else
 data := '';

 // calculate your result here....

 // adds or changes a variable in a data packet
 SetVariable(sName2, res);
 // stores a value between script executions (if necessary)
 PushVariable(sName2, res);

end.
Logged
mccallum4004
Jr. Member
**

Karma: +0/-0
Posts: 15


View Profile
« Reply #2 on: June 23, 2010, 06:56:46 PM »

As I understand it, when using scripting, the connection between the parser and the data export modules is the stack used by PushVariable and PopVariable.  Is that correct?

I have tried to get my data string into an integer array using

dist := StrToInt(Copy(data,2*i-1,2));

but I think this line is what is generating the error message 'is not a valid integer value' when the script runs.  This is the same error message I got when I was trying to parse directly into integers rather than using the string type in the parser.

I had also tried typecasting directly Copy(data,2*i-1,2):Integer; but got an error with that.
Logged
Arthur Grasin
Tech. Support
Administrator
Hero Member
*****

Karma: +0/-0
Posts: 806



View Profile WWW
« Reply #3 on: June 23, 2010, 07:14:22 PM »

I suppose that "dist" and "i" are not declared in the "var" section.

Code:
var sName1:string = 'DATA';
     sName2:string = 'RESULT';
     data: string;
     dist: string;
     i: integer;
     res: double;
begin
...

Could you post your full script? I'll verify it.
Logged
mccallum4004
Jr. Member
**

Karma: +0/-0
Posts: 15


View Profile
« Reply #4 on: June 23, 2010, 08:31:02 PM »

They are declared.  They are both integers.  It is tough to get a copy of the script because my operating computer is out in the field and not connected to the internet.  I will be out for a couple of hours soon but basically my script is

var sname1:string = 'DATA'  //the string from the parser
var data:string;
var dist:array[141] of word;
var i: integer;

begin
  // get data as per sample
  data := PopVariable(sname1);  //question - do I need the redundancy of variables here?
  // try to create an integer array
  for i := 1 to 141 do
    dist := StrtoInt(Copy(data,2*i-1,2));

//continue calculating ...


Logged
Arthur Grasin
Tech. Support
Administrator
Hero Member
*****

Karma: +0/-0
Posts: 806



View Profile WWW
« Reply #5 on: June 23, 2010, 09:05:17 PM »

The working script is below. I've modified your conversion routine.

Code:
var

sname1:string = 'DATA_PACKET';  //the name of the parser item
data:string;
dist:array[1..141] of word;
i,j: integer;
begin
  // get data from the parser item
  data := GetVariable(sname1);
  // try to create an integer array
  i := 1; j := 1;
  while (i<length(data))and(j<=141) do
   begin
    dist[j] := ord(data[i])+$100*ord(data[i+1]);
    //SetVariable('VAL'+IntToStr(j), dist[j]); // export value
    j := j + 1;
    i := i + 2;
   end;

//continue calculating ...
end.

I think that this code

Code:
StrtoInt(Copy(data,2*i-1,2));

can't get a WORD value in any case.
Logged
mccallum4004
Jr. Member
**

Karma: +0/-0
Posts: 15


View Profile
« Reply #6 on: June 24, 2010, 12:20:58 AM »

Thanks.  I'll try that this afternoon.  I wouldn't have thought to use the Ord() function - just like I didn't expect to parse the original binary stream as a "string,"  which is what worked when using the expressions module and I've kept that.
Logged
mccallum4004
Jr. Member
**

Karma: +0/-0
Posts: 15


View Profile
« Reply #7 on: June 25, 2010, 03:01:21 AM »

Thanks.  That worked great.  Another question: My cosine conversion doesn't seem to give me the right numbers.  Your help file doesn't say whether the argument should be in radians or degrees and the expressions help file says that the cos function is the cosecant, rather than the cosine.  Could this be correct? 

By the time you get this, I may have figured it out by trial and error.  The program has worked flawlessly but the documentation is hardly useable.  If it hadn't been for the support here, I wouldn't be using this program.
Logged
Arthur Grasin
Tech. Support
Administrator
Hero Member
*****

Karma: +0/-0
Posts: 806



View Profile WWW
« Reply #8 on: June 25, 2010, 09:05:44 AM »

Cos(X) - Cos returns the cosine of the angle X. X is a real-type expression that represents an angle in radians.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines