Communication protocols
PROGRAMMING MANUAL
166
Revi
si
on 3.0
' In the STARTUP program
' Setting RS232 port for the vision system
SETCOM(38400,8,1,0,1,0)
' In the application program
loop:
' Trigger, rising edge in virtual system
WAIT UNTIL IN(30)=0
WAIT UNTIL IN(30)=1
' Clear screen
PRINT CHR(27);"[2J"
' Clear buffer
GOSUB clear_buffer
' Send command to the serial port according to VR(10)
IF vision_command=v_measure THEN
PRINT #1, "M"
PRINT ">> M"
ELSEIF vision_command=v_date THEN
PRINT #1, "DATE"
PRINT ">> DATE"
ELSEIF vision_command=v_scene THEN
PRINT #1,"SCENE ";scene_n
PRINT ">> SCENE"
ENDIF
'Check response
GOSUB read_buffer
GOTO loop
read buffer:
count=0
resp_status=0
k=-1
TICKS=5000
REPEAT
IF KEY#1 THEN
count=count+1
GET#1, k
'PRINT k;count
TABLE(count,k)
'PRINT count
ENDIF
UNTIL TICKS<0 'OR k=13
PRINT "Received ";count[0];" characters"
FOR i=1 TO count
IF TABLE(i)<>13 THEN
PRINT CHR(TABLE(i))
ELSE
PRINT "'cr'"
ENDIF
NEXT i
IF TICKS<0 THEN
PRINT "Timeout in the communication with the F500"
resp_status=3
ELSEIF TABLE(count-2)=79 AND TABLE(count-1)=75 THEN
PRINT "Response OK"
resp_status=1
ELSE
PRINT "Response Uncorrect"
resp_status=2
ENDIF
PRINT "Response Status is :";resp_status[0]
RETURN
clear_buffer:
PRINT "Clearing..."
WHILE KEY#1
GET#1,k
PRINT k
WEND
PRINT "Cleared!!"
RETURN
I52E-EN-03.book Seite 166 Freitag, 29. Juni 2007 11:55 11