6 - 30 THE CPL PROTOCOL
Example: Written in Quick Basic;
CLS
CLOSE
OPEN “COM2:19200,N,8,1, CS0, DS0, CD0” FOR RANDOM AS #1
OPEN “HPGL.HGL” FOR OUTPUT AS #2 : ‘Open output file
PRINT #1, “QP”; 1 : ‘Query print
Start! = TIMER
WHILE ((TIMER < Start! + 1) AND (LOC(1) = 0))
WEND
IF LOC(1) > 0 THEN : ‘Sync on data
PRINT “Response = “;
DO
Byte$ = INPUT$(LOC(1),#1) :’Read each data byte
PRINT Byte$; :’Display databyte
PRINT #2, Byte$; :’Append databyte to file
Start! = TIMER
WHILE ((TIMER < Start! + 1) AND (LOC(1) = 0))
WEND
LOOP WHILE LOC(1) > 0
ELSE : ‘Error message
PRINT “No Response”
END IF
CLOSE