T2 port 12-34 – Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 224

Advertising
background image

Chapter
Call Routines 0–68

12

12 -34

Use this routine to retrieve the current character in the 255 character, PRT2
port receive buffer and convert it to its decimal representation. The PRT2
port receives data your device transmits and stores it in this buffer.

You can use the GET# statement (page 11 -12) in place of CALL 35.

Input and Output Arguments

This routine has no input arguments and one output argument. If there is
not a character in the PRT2 receive buffer, the output argument is 0 (null).
If there is a character, the output argument is the ASCII value of that
character.

Important: A 0 (null) is a valid character in some communication
protocols. Use CALL 36 to determine the actual number of characters in
the buffer.

Syntax

CALL 35

POP

ASCII value of character

Example

>10 CALL 35

>20 POP X

>30 IF X = 0 THEN GOTO 10

>40 PRINT CHR(X)

This program shows how to read a number from the PRT2 port. A device
connected to the PRT2 port sends the number, followed by the character
“r” (e.g. 51r). The “r” indicates the end of the number. The BASIC
module unpacks the characters and combines them to form the number 51
and the character “r”.

>10 REM THIS PROGRAM DEMONSTRATES HOW TO READ A NUMBER FROM THE

>20 REM PRT2 PORT. A DEVICE CONNECTED TO THE PRT2 PORT

>30 REM SENDS THE NUMBER AS A SERIES OF ASCII CHARACTERS,

>40 REM FOLLOWED BY THE CHARACTER R. R INDICATES END OF THE NUMBER.

>50 T=0 : REM T WILL HOLD THE NUMBER RECEIVED FROM THE REMOTE DEVICE.

>60 CALL 35 : POP X : REM GET A CHARACTER FROM THE PRT2 PORT

>70 REM IF THE CHARACTER IS A VALID DIGIT, ADD IT TO T

>80 IF (X>=48).AND.(X<=57)T=(T*10)+(X-48)

>90 IF X=114 GOTO 110 : REM CHARACTER 114 IS A LOWER CASE R

>100 GOTO 60

>110 PRINT “THE NUMBER IS”, T

CALL 35: Retrieve Numeric
Input Character from PRT2
Port

Advertising