Problem with script
Problem with script
- Subject: Problem with script
- From: Chuck Coleman <email@hidden>
- Date: Tue, 18 Sep 2001 12:44:21 -0700
The following script keeps coming up with a dialog box after the timeout
which stalls the script unless there is some user interaction to either edit
the script of continue another attempt.
I want this script to run and keep trying till it connects with the program
it is intended to connect with.
Any suggestions or comments would be appreciated.
--the local database of values and control parameters
-- This is the CMST : Command and Measurement Status Table
-- Elements are channels 1-8 of the Weeder analog input board
-- Fields are:
-- name: string name of unit in XTension database
-- value: current raw count value of unit
-- SC : significant change value in raw counts
-- SF : scaling factor (processed data = (raw * scaling factor) +Bias)
-- Bias: offset value +/-
-- port_conn : Channels set to FALSE will be ignored
property CMST : {,
{name:"TEMP 1", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:true}, ,
{name:"TEMP 2", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 3", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 4", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 5", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 6", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 7", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false},
,
{name:"TEMP 8", +class cdat;:0, SC:2, SF:0.1, Bias:0, port_conn:false} ,
}
property c : 0
property n : 0
property p : 0
property first_time : true
property mpHandle : ""
property Sample : ""
property dataPoll : "AS"
property old_delimiters : AppleScript's text item delimiters
--change the following line for the proper settings for the weeder analog
board serial port :
property weederConfig : ,
"Baud 9600 DataBits 8 Parity None StopBits 1 Port \"weeder\" Handshake
None HoldConnection False RemindDisconnect False"
--
on run
set first_time to true
--clear the CMST to force update on first data
repeat with c from 1 to number of items in CMST
set +class cdat; of item c of CMST to 0
tell application "XTension"
+event xtenSetV; (name of item c of CMST) given +class vall;:0
end tell
end repeat
try --this will make sure that we get an error dialog if something
occurs
--First we gotta get the port handle, and configure the port for the
weeder
set mpHandle to +event commInit;
+event commSetc; mpHandle given +class cStr;:weederConfig
-- open the serial port and flush the receive buffer
+event commopen; mpHandle
--and flush the serial buffer--assuring alignment.
set spResponse to +event commReed; mpHandle given +class numC;:1000
ignoring application responses
tell application "Acrobat Reader 4.0"
+event xtenlogm; "Weeder now monitoring temperatures"
end tell
end ignoring
on error errMsg number errNum
display dialog "Got an error on startup: " & errMsg & errNum
+event commclos; mpHandle
+event commDisp; mpHandle
end try
end run
--
--repeat as frequently as specified in the 'return' item at the
end...(seconds)
on idle
try
+event commsend; mpHandle given +class data;:dataPoll & return
set rawResponse to +event commReed; mpHandle given +class numC;:64
--
-- UN-comment the following lines only when DEBUGGING
-- ignoring application responses
-- tell application "XTension"
-- write log "Weeder Reading tempature values:." &
rawResponse
-- end tell
-- end ignoring
set spResponse to ""
set n to ((number of characters in rawResponse) - 1)
repeat with c from 2 to n
set spResponse to spResponse & item c of rawResponse
end repeat
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set Sample to the text items of spResponse
set AppleScript's text item delimiters to old_delimiters
repeat with c from 1 to (number of items in Sample) -- For each of
the measurements,
set x to item c of Sample as integer
-- IF the channel is 'enabled'
if (port_conn of item c of CMST) then
-- If the value of the 'channel' is 'significantly changed'
then
if first_time or (x > (+class cdat; of item c of CMST) + (SC
of item c of CMST) ,
or x < (+class cdat; of item c of CMST) - (SC of item c
of CMST)) then
--Now process the raw data into meaningful units
(rounding here)
set p to ((round x * (SF of item c of CMST)) + (Bias of
item c of CMST)) as integer
-- And put the new 'raw' value into the local database
set +class cdat; of item c of CMST to p
--Now tell XTension to put the value in the database
ignoring application responses
tell application "Acrobat Reader 4.0"
+event xtenSetV; (name of item c of CMST) given
+class vall;:p
end tell
end ignoring
end if
end if
end repeat
set first_time to false
on error errMsg number errNum
set packet to +event commReed; mpHandle given +class numC;:1000 --
just to flush
ignoring application responses
tell application "Acrobat Reader 4.0"
+event xtenlogm; "The weeder got an error : " & errMsg
end tell
end ignoring
return 60 -- maybe wait longer before trying again ?
end try
return 300 -- Return in five minutes. This is the sample rate ...
end idle
on quit
+event commclos; mpHandle
+event commDisp; mpHandle
continue quit
end quit