Re: Assigning output from LINEOUT to a variable
- From: Frank da Cruz <fdc@xxxxxxxxxxxx>
- Date: 21 Jun 2006 16:26:26 GMT
On 2006-06-20, toastyboy@xxxxxxxxxxxxxx <toastyboy@xxxxxxxxxxxxxx> wrote:
: Regarding parsing the output, here is what I would simply expect to see
: either a 1 or a 0 (depending on the state of the input) followed by a #
: on a new line.
:
: (The # is the command prompt on this device if you like)
:
: See the below extract from an interactive session:
:
: #
: #I1
: 1
: #I2
: 1
: #I3
: 1
: #I4
: 0
: #
:
: What I want is either to set the 0 or 1 as a variable and then based on
: this write out a file with the 0 or 1 in it, or (better still) write
: the 0 or 1 out to a file directly.
:
You want to send a command to this device, get back a single-character
response, and write the response to a file. This is seemingly
straightforward, but there's a bit more to it, because maybe the device echoes
what you send, and since the single-character responses really come with some
other stuff, such as carriage returns and linefeeds. What do you want to go
into your file -- a single digit, or the digit followed by carriage return
and/or linfeed?
Let's say you want to store <digit><CR><LF>. Then the above sequence
would be programmed something like this:
clear input ; start with a clean INPUT buffer
output \13 ; send a carriage return (\13) to make a prompt appear
input 5 \# ; wait 5 sec for the '#' prompt
if fail stop 1 ; make sure we got it
output I1\13 ; Send "I1" and a carriage return
; Let's assume the devices echoes "I1<CR><LF>"
input 5 I1\13\10 ; Absorb the echo
if fail ... ; Do something if the echo does not appear
clear input ; clear the input buffer again
input 5 \10 ; Input everything up to a linefeed
if fail ...
; At this point \v(input) should contain the resonse.
; Now you can write it to a file.
fopen /write \%c somefilename
if fail ...
fwrite /line \%c \ftrim(\v(input))
fclose \%c
and so on for I2, I3, and I4. I didn't show what to do on failure,
that's up to you. Maybe there is some corrective action you can take.
You can loop and try again, whatever. The statement:
fwrite /line \%c \ftrim(\v(input))
trims the CRLF from the response, and then writes it to disk in native
format for a line, which is not necesarily text terminated by CRLF.
- Frank
.
- Follow-Ups:
- Re: Assigning output from LINEOUT to a variable
- From: toastyboy
- Re: Assigning output from LINEOUT to a variable
- References:
- Assigning output from LINEOUT to a variable
- From: toastyboy
- Re: Assigning output from LINEOUT to a variable
- From: Frank da Cruz
- Re: Assigning output from LINEOUT to a variable
- From: toastyboy
- Assigning output from LINEOUT to a variable
- Prev by Date: Re: Assigning output from LINEOUT to a variable
- Next by Date: Re: Assigning output from LINEOUT to a variable
- Previous by thread: Re: Assigning output from LINEOUT to a variable
- Next by thread: Re: Assigning output from LINEOUT to a variable
- Index(es):
Relevant Pages
|
Loading