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!

How to Format Data in capture loop

Status
Not open for further replies.

odubman

Technical User
Jan 16, 2003
5
US

I currently have a capture loop in place to dump a date and time stamp string into the capture stream. After that I would like to send a command (v3), which will receive data from remote device after hitting return. The data will be captured every 15 seconds. I would like to have all of this data on same line, separated by commas as follows:

Date,Time,v3,x,x,x,x (where x,x,x,x is response back from remote device)

This same format should continue on as follows:
Date,Time,v3,x,x,x,x
Date,Time,v3,x,x,x,x
Date,Time,v3,x,x,x,x
etc......

I'd rather not capture the "v3" command if possible, but it can be included if need be.

Here is my current loop:

while 1
ltimestrs $LTIME DateString TimeString
strfmt sCap "%s,%s," DateString TimeString
termwrites sCap
transmit "v3^M"
pause 15
endwhile

which provides the following output:

v327/2004,3:56:44PM,v3
x,x,x,x
v327/2004,3:56:59PM,v3
x,x,x,x

I'd like to get the response (x,x,x,x) onto the same line as the date/time strings. "v3" is also replacing "7/" on the date line for some reason.

Any help on how this loop should be modified to provide the capture format above would be appreciated.


 
Is there any reason you are using a capture file rather than grabbing the incoming data from the port and writing that to a text file you have opened? I think this method would give you a little more flexibility, rather than depending on how data is displayed in the Procomm screen. That is the most likely reason that the output from the v3 command is appearing on its own separate line, and possibly why v3 is not in the correct location?

Either way, you could use the rget command to get the responses from the remote system, which would keep that data from appearing in the terminal window. You may need to do a little testing using this approach since the system is going to echo back the v3 command you send it, so your script will need to account for this, retrieve that string from the port, and simply discard it before retrieving the next string (which should contain the results). You could then use a strfmt command as you are now (but pulling in more variables than you are now) to get all of the data into one string. If you stayed with the capture file and no other data appeared on the screen, you could use the capturestr command to write that string to the open capture file.


aspect@aspectscripting.com
 
Thanks for the info. I don't really have a preference either way (capture file or text file). I'm not very familiar with scripting so could you provide me with some code on how to do both scenarios as you describe above? That would give me a starting point and I could modify from there to get what I'm looking for.

Thanks.
 
Here is some sample code that shows how to open a text file within ASPECT:

proc main
string sLine = "this is a test"

if fopen 0 "data.txt" APPEND TEXT
fputs 0 sLine
fclose 0
endif
endproc

What this will do is open (or create, if necessary) the file data.txt in the ASPECT directory and append the value in the string variable sLine to the open file, then close the file.

You could then use rget commands to retrieve data from the port. You may need to use set aspect rgetchar to choose a different value for the character that will automatically end a rget operation (this is usually a carriage return or linefeed). You can use Procomm's monitor window to determine which is being used (look at the bottom of this message for how to turn on that window). You can also use the STRIP keyword in the rget command to automatically remove the ending linefeed or carriage return (you'll usually want to do this).

Once you have the data in one or more string variables, you can then use the strfmt command as you are now to get all that information into one string that you can then output into a text file (using fputs as above) or to your capture file (using capturestr).

Procomm's Monitor Window can be used to view the incoming and outgoing data, in both hex and ASCII format. To activate this window, select the Data | Monitor Window menu item. Resize the Monitor Window so that you can view the entire width of the window, then click back in the Procomm Plus window so that the Monitor Window does not have focus. Incoming text is displayed in red, while text you send is colored blue.

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top