12.4..3.1    BWSPOOL

Description:   Sends a text message from a script to the BWSPOOL.EXE message window.

Syntax:

Tcl:              BWSPOOL "textstring"

                        BWSPOOL  $variable

                        BWSPOOL  {textstring1 textstring2 $variable1 $variable2}

 

JScript  :       BWSPOOL("textstring");

                        BWSPOOL(variable);

                        BWSPOOL("textstring1" + " textstring2" + variable1 + variable2);

 

VB Script:     BWSPOOL "textstring"

                        BWSPOOL  variable

                        BWSPOOL  "textstring1" &  "textstring2" & variable1 & variable2

Arguments:    Textstring  

Returns:         Sends a text to the BWSPOOL.EXE message window.

 

See Also:       catch

BWSPOOL can be used to send text messages from a script to a message spooler window (BWSPOOL.exe).  It can be inserted into a script to send a simple text message or the intermentiate value of a stirng.

Use BWSPOOL with a  "catch command" to trap errors. Use a "calling" script to call the script to be debugged as in the example below. The "calling script" catches any errors returned by the script you want debugged. To see this error, you should use the catch (Tcl), On Error (VB Script), or try catch (JScript) commands.  Note that ACTION commands do not return errors other than syntax.

Warning - if an error occurs before the BWSPOOL command, then no message is sent to the message spooler window because the script fails and BWSPOOL never runs.  

BWSPOOL.exe can be used to debug both local scripts (screen scripts) and global scripts.  BWSPOOL.exe resides on both the Clients and SCADA nodes.  BWSPOOL.exe can receive messages locally (either from VIEW, ViewDAQ or the SCADA node kernel.  Remote Clients can only debug local scripts running in a BGR in the local web browser (i.e. clients can not debug global scripts running on a remote SCADA node).

BWSPOOL.exe can be found at

drive:\WebAccess\Client\bwspool.exe
drive:\WebAccess\Node\bwspool.exe
 

The BWSPOOL.exe must be run by the user (i.e. by double-clicking on it or Right click -> Open) or called using the WINEXEC.

This example wants to debug a script names arctan.scr. Two BWSPOOL commands are inserted, the first to make sure the script runs, then second to see if it runs to completion. The name of the script is also included in the message so we know where the message is coming from.

arctan.scr

BWSPOOL {- arctan.scr step 1 -}

set x [expr [GETVAL slope]/100]

set y [expr atan($x)]

SETVAL arctan=$y

SETVAL degrees=[expr $y/0.0175]

# SETVAL degrees=[expr $y/0]

SETVAL radians=$y

SETVAL radians=$ynot

SETVAL degrees=[expr $y*180/3.14159265]

BWSPOOL {- arctan.scr last line -}

To get the most out of this tcl script, we use the catch command to catch any error generate by the arctan.scr. We do this by using a calling script to call arctan.scr. The example uses a script named Debugarct.scr to call arctan and catch any error messages. Note that both scripts can send messages to the message spooler (BWSPOOL.exe).

Debugarct.scr

catch {SCREXEC arctan.scr} err

BWSPOOL [concat debugactan.scr $err {- -}]

 

The output of the BWSPOOL.exe after several runs or catching and correcting errors looks like:

 

Example error messages returned by catch include:

invalid command name "SETVALUE"

divide by zero

binding tag invalid

can't read "ynot": no such variable.

 

 

Examples:     

# Tcl

BWSPOOL {- arctan.scr step 1 -}

BWSPOOL $err

BWSPOOL [concat debugactan.scr $err {- -}]

BWSPOOL "[GETVAL TestScriptname] ... File not found."

BWSPOOL "\r\n"  # print carriage return and line feed

 

// JScript

BWSPOOL("Try to run ");

BWSPOOL(filespec);

BWSPOOL("\r\n");  // print carriage return and line feed

 

Rem VB Script

BWSPOOL "Error # " & CStr(Err.Number) & " " & Err.Description

rem print carriage return and line feed

BWSPOOL VbCrLf

BWSPOOL "No reported errors "

BWSPOOL filespec

BWSPOOL VbCrLf

 

Debug Tcl Script Example:

# DebugTclScript.scr - a Tcl script

# Open Message spooler window

WINEXEC BWSPOOL.EXE

# Exit if it calls itself, it will loop endlessly

# trim blank characters

set scriptname [string trim [GETVAL TestScriptname]]

BWSPOOL "Requested script is "

BWSPOOL $scriptname

BWSPOOL "\r\n" #print Carriage return and line feed

if {$scriptname == "DebugTclScript.scr"} then {

 BWSPOOL "don't call itself. Will create an endless loop."

 return

}

# Run the script put errors in err

catch "SCREXEC [GETVAL TestScriptname]" err

  

if {[file exists [GETVAL TestScriptname]]} then {

   #figure out if blank - No errors

   set msglength [string length $err]

   if {$msglength <= 0} then {

   set err "No reported errors."

   }

   BWSPOOL $err

 } else {

 BWSPOOL "[GETVAL TestScriptname] ... File not found."

 }

BWSPOOL "\r\n"

 

Debug JScript Example:

// DebugJScript.js - a JScript

// open the spooler window to print the file

WINEXEC("BWSPOOL.EXE");

BWSPOOL("\r\n");  //print a carriage return and line feed

var e, fso, f, s, filespec, ForReading;

ForReading = 1, s = "", e = "No reported errors.";

// get the name of the file to run from a text tag

   filespec = GETVAL("TestScriptname");

// Run the script and catch any errors.

try {

     SCREXEC(filespec);

     BWSPOOL("Try to run ");

     BWSPOOL(filespec);

     BWSPOOL("\r\n");

     // Test if it exists

      s = filespec;

      fso = new ActiveXObject("Scripting.FileSystemObject");

      if (fso.FileExists(filespec)) {

        s += " found.";

      }

      else

      {

         s += " file not found.";

         e = " file not found.";

      }   

     BWSPOOL(s);

     BWSPOOL("\r\n");

} catch (e) {

     // print any errors

     BWSPOOL(e);

} finally {

}

if (e == "No reported errors.")

 BWSPOOL(e);

 

Debug VB Script Example:

Rem DebugVBScript.vbs - a VB Script

Rem to print errors of other VB scripts.

Dim fso, filespec, msg

 Set fso = CreateObject("Scripting.FileSystemObject")

 filespec = GETVAL("TestScriptName")

On Error Resume Next

SCREXEC filespec

WINEXEC "BWSPOOL.EXE"

   If (fso.FileExists(filespec)) Then

      msg = filespec & " exists."

      BWSPOOL msg

      BWSPOOL VbCrLf

      If Err.Number <> 0 Then

        rem print error number and description

        BWSPOOL "Error # " & CStr(Err.Number) & " " & Err.Description

        SETVAL "ERROR=" & CStr(Err.Number) & " " & Err.Description

        rem print carriage return and line feed

        BWSPOOL VbCrLf

      Else

        BWSPOOL "No reported errors "

        BWSPOOL filespec

        BWSPOOL VbCrLf

      End If

   Else

      msg = filespec & " doesn't exist."

      rem print carriage return and line feed

      BWSPOOL msg

       BWSPOOL VbCrLf

   End If

 

Print  a file - Tcl Script Example 2:

# Tcl Script - viewFile.scr

WINEXEC bwspool.exe

set filename1 [GETVAL texttag]

BWSPOOL "File requested is: "

BWSPOOL $filename1

 BWSPOOL "\r\n"

set linefromfile "ViewScript initialized."

# Try not to create the file if it does not exist. User r option. Not a+

set fileid [open $filename1 r]

set returncount 0

seek $fileid 0 start

while {$returncount != -1} {

 set returncount [gets $fileid linefromfile]

 BWSPOOL $linefromfile

 BWSPOOL "\r\n"

}

close $fileid

Print  File - JScript Example 2:

/* ViewFile.js - a JScript

open the spooler window to print the file */

WINEXEC("BWSPOOL.EXE");

BWSPOOL("\r\n");  //print a carriage return and line feed

var fso, f, s, filespec, ForReading;

ForReading = 1, s = "";

// get the name of the file to read from a text tag

   filespec = GETVAL("TestScriptname");

BWSPOOL("requested file is: ");

BWSPOOL(filespec);

BWSPOOL("\r\n");

// open the file and read each line

   fso = new ActiveXObject("Scripting.FileSystemObject");

   f = fso.OpenTextFile(filespec, ForReading, false);

   while (!f.AtEndOfStream)

   {

      s = f.ReadLine( );

      BWSPOOL(s);

      BWSPOOL("\r\n");

   }

   f.Close( );

Print File - VB Script example 2:

Rem - ViewFile.vbs - reads an entire text file.

Dim fso2, theFile, retstring

filename2 = GETVAL("Texttag")

WINEXEC "BWSPOOL.EXE"

BWSPOOL "Requested file is " & filename2 & VbCrLf

Const ForReading = 1

Set fso2 = CreateObject("Scripting.FileSystemObject")

Set theFile = fso2.OpenTextFile(filename2, ForReading, False)

   Do While theFile.AtEndOfStream <> True

      retstring = theFile.ReadLine

      BWSPOOL retstring & VbCrLf

   Loop

BWSPOOL VbCrLf

theFile.Close