Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Aspect Script Help Needed

Status
Not open for further replies.

ebferro

IS-IT--Management
Mar 14, 2000
8
US
I've created the aspect script listed below. The purpose of the script is to open a capture file, wait until the phrase "Protocol Complete" comes in and then write the capture file to the hard drive with the name WP5-9 followed by the current date and time. Everything seems to be working OK but there is nothing in the capture files. None of the text is there but there are files with the names that should be there. Can anyone tell me why nothing gets stored? Thanks in advance.
Ernie

#define DEBUG 0
string fname ;first part of file name
string datefilename ;this is the date part of file name

proc main

set port baudrate 9600
set port databits 8
set port parity NONE
set port stopbits 1
set port hardflow OFF
set port softflow OFF
set modem connection "direct connect-Com1"
set terminal type ANSIBBS
clear ;clear screen
set capture autostart ON
while 1
when TARGET 0 "Protocol Complete" call write_file
endwhile
endproc

proc file_date
integer iMonth, iDay, iYear, iHour, iMin, iSec
ltimeints $LTIME iMonth iDay iYear iHour iMin iSec
strfmt dateFileName "%02d%02d%02d%02d%02d" iMonth iDay iYear iHour iMin
strcat dateFileName ".TXT"
endproc

proc Write_file
fname = "WP5-9_" ;put the first part of name here leave a space at the end
datefilename = "" ;to ensure string datefilename is empty
call file_date ;calls file_date proc
strcat fname datefilename ;this combines the two string (in this case WP5_9 YYYYMMDD)
set capture path "l:\"
set capture file fname ;sets caputure file to the file named in file_date proc
endproc
 
I believe the problem is that you have no capture ON or capture OFF statements to open and close the capture file. Set capture autostart supposedly only works for connections made through the Connection Directory, which cannot be done for direct connections, but the help file may have overlooked that particular scenario.

Also, you will want to move any set capture statements from the two subprocedures to the main procedure so that the capture file name can be created and set before receiving any data.

 
knob:
Thanks for the quick response. I've changed the script per your suggestions but I'm still having a couple of problems. It seems to be writing a text file every minute without waiting for the "Protocol Complete" phrase. The files are also still empty. The revised script is below. What am I doing wrong? It would also be nice if the files had the date and time at which they were stored. I believe the way the script is currently set up, I get a file name with the date and time at which the capture file was opened, not when the file was actually written. I can live with that problem if there's no solution but it would be nice to get the problem of not writing the file only when the target phrase is received and actually have text in the file resolved.
Thanks again.
Ernie
#define DEBUG 0
string fname ;first part of file name
string datefilename ;this is the date part of file name

proc main

set port baudrate 9600
set port databits 8
set port parity NONE
set port stopbits 1
set port hardflow OFF
set port softflow OFF
set modem connection "direct connect-Com1"
set terminal type ANSIBBS
while 1
clear ;clear screen
fname = "WP5-9_" ;put the first part of name here leave a space at the end
datefilename = "" ;to ensure string datefilename is empty
call file_date ;calls file_date proc
strcat fname datefilename ;this combines the two strings (in this case WP5_9 YYYYMMDDHHMM)
set capture path "l:\"
set capture file fname ;sets caputure file to the file named in file_date proc
capture on
when TARGET 0 "Protocol Complete" call write_file
endwhile
endproc

proc file_date
integer iMonth, iDay, iYear, iHour, iMin, iSec
ltimeints $LTIME iMonth iDay iYear iHour iMin iSec
strfmt dateFileName "%02d%02d%02d%02d%02d" iMonth iDay iYear iHour iMin
strcat dateFileName ".TXT"
endproc

proc Write_file
capture off
endproc
 
It writes a file every minute? Looks to me like it will constantly write files.

Correct me if I'm wrong, but the program will not hold at your line:

Code:
when TARGET 0 "Protocol Complete" call write_file

I believe what is happening is this, the program is constantly running, constantly overwritting files until the next minute, then it starts overwritting a new file (a new minute.)

try instead:

Code:
waitfor "Protocol Complete" forever
capture off

I don't think you need a seperate sub for one line of code, so you can drop the sub Write_file. It's usually a good idea to use subs, but in this case, it makes it harder to read.
 
Kodr:
You are absolutely correct, I think. It was constantly writing the same file until the minute changed. Then, it wrote a new file with the next minute's name and continued to overwrite that file until the minute changed again, ad infinitum.
I may have not properly defined the requirements of my program when I pusted earlier. I'm waiting for input on the serial port until I get the phrase 'Protocol Complete' but then I need to go back and continue waiting for that phrase immediately, again. I'm totally new to aspect. If I make the changes you've suggested, will it continue to go back and wait and recalculate the file name so when the next one comes in, it gets stored with a new file name?
Thanks in advance again.
 
Yes, I believe it will act as you require. Since the program pauses at the waitfor line, once that event occurs, the capture file will get closed, and the program will immeadiatly loop again.

I do see a problem now though. Depending on how quickly the "Protocol Complete" event occurs, you could overwrite your previous file if it occurs in the same minute.

One solution would be to set your capture file name to a temp file name, then after you close the capture file use "rename oldname newname" to rename the file to what you want. In this way you could check ahead of time for the existance of the same filename before renaming.

Code:
if isfile filename
     ;file exists
else
     ;file does not exist
endif
 
kodr:
Thanks for the help. I think I've got it working now.
Ernie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top