1-10 Program Example - Omron K3HB - MANUAL 2 Manual

Digital indicators
Hide thumbs Also See for K3HB - MANUAL 2:
Table of Contents

Advertisement

Program Example

1-10 Program Example

N88Basic
This program displays the response from the K3HB on the screen when com-
mand data is entered from the keyboard.
Command data from the unit number to the number of elements must be
entered.
The program was created in N88BASIC.
1000
'----------------------------------------------------
1010
'PROGRAM: E5AR/ER Communication Sample Program(CompoWay/F)
1020
'VERSION:1.00
1030
(c)Copyright OMRON Corporation 2003
1040
All Rights Reserved
1050
'----------------------------------------------------
1060
'
1070
'======Communication port (PARITY=EVEN, DATA=7, STOP=2) ======"
1080
'
OPEN "COM:E73" AS #1
1090
1100
'
∗SENDDATA
1110
1120
'
1130
========= Communication routine==================
1140
'
1150
--------Communication data input----------
1160
INPUT "SEND DATA:",SEND$
1170
'
1180
--------If no input, jump to end routine----------
IF SEND$ = " " THEN ∗EXITSEND
1190
1200
'
1210
-------BCC calculation--------
1220
BCC = 0
1230
SEND$ = SEND$+CHR$(3)
1240
FOR I=1 TO LEN(SEND$)
1250
BCC = BCC XOR ASC(MID$(SEND$, I, 1))
1260
NEXT I
1270
BCC$ = CHR$(BCC)
1280
'
1290
------Send----------
1300
SDATA$ = CHR$(2)+SEND$+BCC$
PRINT #1, SDATA$;
1310
1320
'
1330
========= Receive routine ===========
1340
'
1350
RDATA$ = " "
1360
TIMEOUT = 0
∗RCVLOOP
1370
1380
-------No response detection-------
1390
TIMEOUT = TIMEOUT+1
IF TIMEOUT > 2000 THEN RESP$ = "No Response":GOTO ∗RCVEND
1400
IF LOC(1) = 0 THEN ∗RCVLOOP
1410
1420
'
1430
-----Check for end character (if no end character, continue reading)
1440
RDATA$ = RDATA$+INPUT$(LOC(1),#1)
IF LEN(RDATA$) <2 THEN ∗RCVLOOP
1450
IF MID$(RDATA$,LEN(RDATA$)-1,1) <> CHR$(3) THEN ∗RCVLOOP
1460
1470
RESP$ = MID$(RDATA$,2,LEN(RDATA$)-2)
∗RCVEND
1480
1490
'
1500
-------Display received data-----------
1510
PRINT "RESPONSE:";RESP$
GOTO ∗SENDDATA
1520
1530
'
∗EXITSEND
1540
1550
=========End routine==========
CLOSE #1
1560
1570
END
Section 1-10
1-23

Advertisement

Table of Contents
loading

Table of Contents