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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with creating an array from capture file.

Status
Not open for further replies.

NeoValence

Technical User
Mar 21, 2006
35
US
hi all,

i'm working with a video generator which has a video mode query command. when the command is typed a list of 95 different video modes are displayed one mode per line in the terminal window. the captured file looks a bit like this.

63 : 1600x1200 @47.95
64 : 1600x1200 @48
65 : 1600x1200 @50
66 : 1600x1200 @59.94

ideally i would like to create an single field array of the data in the captured file. then i need to termmsg the lines of the array sequence, waitfor each of the 7 video modes i need and then use termgets to store those modes into variables to be accessed later on during the script. this is what i have thus far:

proc main

set capture query off

fopen 0 "resh.cap" CREATE TEXT ;overwrites old helpv.cap file (if any)
yield
fclose 0 ;closes the .cap file

transmit "helpv^M" ;query help for all video modes
waitfor "helpv"
if SUCCESS
capture on ;capture file mode on
set capture recordmode raw ;captures chars. as they appear in terminal
set capture file "helpv.cap" ;names capture (.cap) file
elseif FAILURE
;errormsg "Video help command not recieved!"
exit
endif
waitfor "#"
if SUCCESS
capture off
elseif FAILURE
errormsg "exiting script"
exit
endif

fopen 0 "helpv.cap" READ TEXT ; Open helpv.cap file for read only.
if SUCCESS
termmsg "resh.cap opened successfully!`r`n"
elseif FAILURE
termmsg "resh.cap open failed!"
exit
endif

can anyone help me out with this. thanks in advance.
 
I guess I'm a little unclear on what is going on in your process. It sounds like you have the data you need in the capture file, but are wanting to write that back to the terminal screen as well. Am I correct in this understanding?

To get the data in an array, you would first need to declare a 95-element string array like this:

string VideoModes[95]

Depending on how the data appears in the capture file, you would first need to identify the first video mode returned and save it to the first element of the array as such (say it is in a string called sLine which has just been read from the capture file):

VideoModes[0] = sLine

If each video mode comes one after another, you would read the next line of the file (assuming you are in a while not feof type of loop), increment an integer variable (say intvar) that was initialized to 0 prior to opening the file, and have this line which would write each video mode to its own element:

VideoModes[intvar] = sLine

 
knob,

sorry for the late reply, and the not very well thought out thread.

i'm just trying to get 8 lines from the captured file described above. instead of creating an entire array of all 95 lines of the .cap file, i think it would probably be more practical to just somehow search the file for lines containing each the 8 video modes i need, then get the data from those lines in a string to be used later on during script.

i know this task must be an easy one but, i haven't been able to figure out how to go about doing that. my initial thread was just an outline of my best guess of how to accomplish this.

thanks
 
Do you get 8 video modes at a time and then need to send a key sequence to get the next 8, or do you get all 95 video modes at once in the capture file?

The way I would do it is to look for the first video mode based on the string (I'll assume something like "01 :" would be the beginning of that line) using the strfind command. You could save that in a string variable called VideoMode_1, or use a smaller string array like outlined in my first message. You would then read the next line, getting video mode 2 and saving that line into VideoMode_2, and so on up to VideoMode_8.

 
i get all 95 modes at once.

1 : NTSC (480i)
2 : 720x480p
3 : PAL (576i)
4 : 720x575p
5 : 640x480 @59.94

"all the way upto"

88 : 2048x1080p @59.94
89 : 2K Analog@59.94
90 : 2048x1080p @50
91 : 2048x1080p @60
92 : 1920x1200p @60
93 : 875p

the terminal output varies from one device to another when entering the vid. mode query command. since this machine's firmware has been changed several times, adding a few new video modes each time.

the reason i need to do this is because the numbers to the left of the : in the capture file change depending on what new video modes have been added. so i aim to make a test script that's somewhat smart and is able to run with any of these generators no matter what firmware it's loaded with.

i'll try the strfnd command to see if i can get it to work.
in the time being do u think u could recommend a sample script to look at to help me with all of the syntax.

thanks
 
knob,

i tried it a few ways and this is what i came up with. i found that the strfind method was the most reliable way to accomplish this task.

string sNTSC, sPAL, s1024x768, s1280x1024, s1280x102460, s1600x1200, s1600x120060, s1080i

proc vmode_sel

string LineInfo ;Line from file.
string reso[110] ;local array named reso with upto 110 elements
integer i=0 ;counter
string istring
integer max = 0

termreset ;clear the terminal sb buffer
transmit "reshelp^M" ;enter imagepro video mode query command
waitfor "#" ;wait until all video modes are displayed in the terminal
if SUCCESS
sbsave FILE "C:\video_modes.txt" ;create a text file of terminal output
elseif FAILURE
errormsg "Script Error"
exit
endif
isfile "C:\video_modes.txt" ;Make sure file exists.
if SUCCESS ;if file exists
fopen 0 "C:\video_modes.txt" READ ;Open file for read.
while not feof 0 ;Loop to end of file.
fgets 0 LineInfo ;Get data at line from file
reso = lineinfo ;define current element as string
itoa i istring ;convert integer i to a string
i=i+1 ;increment integer i
endwhile
elseif FAILURE
errormsg "File video_modes.txt does not exist!"
exit
endif
max = i
fclose 0 ;Close the file.
delfile "video_modes.txt" ;deletes file

i=0
while (i++) < max
if strfind reso "NTSC"
sNTSC = reso
elseif strfind reso "PAL"
sPAL = reso
elseif strfind reso "1024x768 @59.94"
s1024x768 = reso
elseif strfind reso "1280x1024 @59.94"
s1280x1024 = reso
elseif strfind reso "1280x1024 @60"
s1280x102460 = reso
elseif strfind reso "1600x1200 @59.94"
s1600x1200 = reso
elseif strfind reso "1600x1200 @60"
s1600x120060 = reso
elseif strfind reso "1920x1080i @59.94"
;s1080i = reso
endif
endwhile
endproc

thanks again,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top