Limit-Checking Received Data using ASCII Protocol
Technical Note 1064
Applicable Model(s)
OIT Models
Title
Limit-Checking Received Data using ASCII Protocol
Date
10/23/2023
Rev
00
P/N
0907-1064
The idea behind Limit Checking is to compare a value with an Upper Limit and a Lower Limit. If the value is outside of these limits, display an error message and ask for the value again. This document presents some sample BASIC code that can be used to limit-check numeric data received from a Maple Systems OIT configured with STEPware.
Listed below is BASIC code to perform Limit Checking. Not all controllers will support the commands and structure listed below. The Engineer will need to determine if the code will work as listed; or what modifications are necessary.
NOTE: Normally, a PRINT statement automatically appends a Carriage Return after a the data in the statement is printed. In the code below, some PRINT statements are followed by a semicolon (;). This causes the PRINT statement to NOT add a Carriage Return to the printed data. It is common in BASIC for the semicolon to work like this; however, it may not be supported in special versions of BASIC used in some controllers.
100 LOLIM = 10 ‘ minimum value
110 HILIM = 1000 ‘ maximum value
‘ set the cursor position to 1,1
‘ and display the current value (note the semicolon)
120 PRINT CHR(27);”x11″;CHR(2);
‘ VALUE contains the value to be modified
130 PRINT “Current Value: ”;STR(VALUE)
‘ set the cursor position to 1,2 and ask for the new value
‘ (note the semicolon)
140 PRINT CHR(27);”x12″;CHR(2); ‘ set cursor to col 1, line 2
150 PRINT “Enter New Value ”;
160 INPUT NEWDATA
‘ the data from the OIT comes in as a String;
‘ so convert it to a number
170 NEWVAL = VAL(NEWDATA)
‘ check new value against the lo limit,
‘ and jump to the Out-Of-Range-Data handler if necessary
180 IF NEWVAL < LOLIM THEN GOTO 210
‘ check new value against the hi limit, ‘ and jump to the Out-Of-Range-Data handler if necessary 190 IF NEWVAL > HILIM THEN GOTO 210
‘ data is OK, skip Out-Of-Range-Data handler
200 GOTO 290
‘ ** Start of the Out-Of-Range-Data handler **
210 PRINT CHR(27);”g1″;CHR(2); ‘ sound a 1-sec beep
220 PRINT CHR(27);CHR(255);CHR(2);
‘ clear the screen
‘ show valid range
‘ we want a carriage return, no semi-colon
230 PRINT “Range is:”
240 PRINT CHR(27);”x12″;CHR(2); ‘ set cursor to col 1, line 2
250 PRINT STR(LOLIM);” To “;STR(HILIM)
‘ wait a bit, then get new data
260 DELAY(1500) ‘ wait for 1500 msec
270 PRINT CHR(27);CHR(255);CHR(2);
‘ clear the screen
280 GOTO 120 ‘ enter data again
‘ ** End of the Out-Of-Range-Data handler **
‘ save the limit-checked new value
‘ and proceed with the rest of the program
290 VALUE = NEWVAL
‘ rest of program follows
If the controller supports it, this code could be implemented as a Subroutine. Before the
subroutine is called, set HILIM, LOLIM, and VALUE to the appropriate values. After the
subroutine returns, set the variable being changed to VALUE.
If implemented as a Subroutine, lines 100 and 110 would not be necessary, as the Low and High
limits would be set before the subroutine is called.