beautypg.com

Vr2c.bas – Xylem STORM 3 Basic Programming manual User Manual

Page 47

background image

45

Example Programs

REM Communicate with and retrieve data from an RS-232 sensor

SerialNum$ = “450065”

SETPORT 9600,8,None,1,None,0,0

OPEN “RS-232 COM” AS #4

PRINT #4 “\r” REM Wake up sensor

SLEEP 0.100 REM Wait for sensor to fully wake up

REM COMMAND FORMAT: *SSSSSS.P#CC,command\r

REM SSSSSS = serial number of device (passed in)

REM P = 0

REM CC = decimal summation of SSSSSS and P

SerialNumLength = LEN(SerialNum$)

SerialNumSum = 0

SerialNumChar = 1

WHILE (SerialNumLength > 0)

SerialNumSum = SerialNumSum + VAL(MID$(SerialNum$, SerialNumChar, 1))

SerialNumChar = SerialNumChar + 1

SerialNumLength = SerialNumLength - 1

WEND

IF (SerialNumSum < 10) THEN

SerialNumSum$ = “0” + STR$(SerialNumSum)

ELSE

SerialNumSum$ = STR$(SerialNumSum)

END IF

PRINT #4 “*”, SerialNum$, “.0#”, SerialNumSum$, “,RTMNOW\r”

INPUT #4 “\r” 5000, ack$

REM retrieve the acknowledgement

INPUT #4 “\r” 5000, status$

REM retrieve the status line

INPUT #4 “>” 20000, reply$

CLOSE #4

REM Remove initial from reply

NLPosition = INSTR(reply$, “\n”)

IF (NLPosition < 3) THEN

reply$ = MID$(reply$, NLPosition + 1)

END IF

REM Remove the trailing greater than symbol and from reply

GTPosition = INSTR(reply$, “>”)

IF (GTPosition > 0) THEN

reply$ = MID$(reply$, 1, GTPosition - 3)

END IF

IF (LEN(reply$) > 5) THEN

OPEN “VR2CData.csv” FOR APPENDING AS #3

PRINT #3, reply$

CLOSE #3

END IF

VR2C.bas