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

How to compare a ASCII value from an instrument to a numerical value

Status
Not open for further replies.

dknechtions

Technical User
Jul 17, 2007
2
US
Hey i am a little new to Procomm and needed help comparing a voltage value out of a Sage930A to a set number of values. Here is what i have however it always gives me a -0VDC no matter what the voltage is:

string string1, string2, string3, string4, string5, string6, string7, string8
string string9, string10, response4, response5, response6, string9a, string9b, string9c, string9e
string string9d, string9f, string2a, stringMT, stringMT2, stringMN, stringSN, stringVDial
integer STEP, RGVDC, TGVDC, AMPS, MT1, MT2, MN, SN, Event
integer Choice = 2 ; Used for radio button group.
string1 = "= -"
string2 = "= -"
string2a = "= +"
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;;;;;;;;;;;;;;; verify tip to ground 0 VDC ;;;;;;;;;;;;;;;;;
TGVDCtest:
transmit "G,6,J,K,K,K"
waitquiet 4
rxflush
transmit "X"
waitfor "= +" 2
rget string2a 1 2
atoi string2a TGVDC ; Convert string to integer.
waitquiet 1
termmsg "*****************************`r`n"
termmsg "* Tip to Ground Voltage = -%d VDC*`r`n" TGVDC
termmsg "*****************************`r`n"

if TGVDC<=9 & TGVDC>=0
;usermsg "TGVDC success"
goto currtest
else
goto TGVDCtest2
endif


TGVDCtest2:
waitquiet 2
rxflush
transmit "X"
waitfor "= -" 2
rget string2 1 2
atoi string2 TGVDC ; Convert string to integer.
waitquiet 1
termmsg "*****************************`r`n"
termmsg "* Tip to Ground Voltage = -%d VDC*`r`n" TGVDC
termmsg "*****************************`r`n"

if TGVDC<=9 & TGVDC>=0
;usermsg "TGVDC success"
goto currtest
else
goto TGVDCtest3
endif

TGVDCtest3:
waitquiet 2
rxflush
transmit "X"
waitfor "= -" 2
rget string1 2 2
atoi string1 TGVDC ; Convert string to integer.
waitquiet 1
termmsg "*****************************`r`n"
termmsg "* Tip to Ground Voltage = -%d VDC*`r`n" TGVDC
termmsg "*****************************`r`n"

if TGVDC<=18 & TGVDC>=10
;usermsg "TGVDC success"
goto currtest
else
usermsg "TGVDC fail POT Test %d" STEP
dialogbox 0 0 0 100 50 11 "Choose One"
radiogroup 1 Choice ; Define radio group.
radiobutton 2 5 5 90 12 "Quit, go to next POT"
radiobutton 3 5 20 90 12 "Continue Test"
endgroup
pushbutton 4 25 35 50 15 "&Done"
enddialog
while 1
dlgevent 0 Event ; Get dialog box event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 1 ; Radio group control selected.
endcase
default ; Exit case selected.
exitwhile ; Exit the while loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
if Choice == 2 ; Evaluate radio group state.
goto NEXTPOT1
else
endif
endif

;;;;;;;;;;;;; measure current ;;;;;;;;;;;;;;;
currtest:
 
Everything looks good, without being able to test this myself.

Check to make sure that the string that you are getting from your rget is what you are expecting. Put it into a msgbox, or save it to a text file.

Be careful that there is not a CR and/or LF at the end of the string. That might mess up your conversion to integer.
 
My guess, since you are only grabbing a couple characters, is that the value coming back is not numeric and cannot be converted to an integer as mentioned toward the end of the atoi discussion in the help file. What may be happening is there is some nonprintable character coming across first, such as an escape sequence, spaces, tab, etc. for formatting purposes. Rget is just pulling the first character of that string and not getting the actual value you want.

I would start by using just rget without any string or timeout parameters, then use a usermsg command to display what comes back (rget will terminate at the first carriage return). I would recommend doing something like:

usermsg "X%sX" string1

where the X at the front and end of the displayed string will help you determine if there are any nonprintable characters coming across.

Once you know what is being sent, you can then work on breaking that down to just the values you need.

 
yes that does seem fesiable and i know i have done it before however the following works for a different part of the test:
;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
;;;;;;;; verify -56 VDC ring to ground ;;;;;;;;;;;;;;;
rxflush
transmit "X"
waitfor "= -" 2
rget string1 2 2
atoi string1 RGVDC ; Convert string to integer.
waitquiet 1
termmsg "*****************************`r`n"
termmsg "* Ring to Ground Voltage = -%d VDC*`r`n" RGVDC
termmsg "*****************************`r`n"

;usermsg "%d" RGVDC
waitquiet 2
if RGVDC<=61 & RGVDC>=33
;usermsg "POT Test %d RGVDC success" STEP
goto TGVDCtest
else
usermsg "POT Test %d RGVDC fail" STEP
dialogbox 0 0 0 100 50 11 "Choose One"
radiogroup 1 Choice ; Define radio group.
radiobutton 2 5 5 90 12 "Quit, go to next POT"
radiobutton 3 5 20 90 12 "Continue Test"
endgroup
pushbutton 4 25 35 50 15 "&Done"
enddialog
while 1
dlgevent 0 Event ; Get dialog box event.
switch Event ; Evaluate the event.
case 0 ; No event occurred.
endcase
case 1 ; Radio group control selected.
endcase
default ; Exit case selected.
exitwhile ; Exit the while loop.
endcase
endswitch
endwhile
dlgdestroy 0 CANCEL ; Destroy the dialog box.
if Choice == 2 ; Evaluate radio group state.
goto NEXTPOT1
else
endif
endif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top