Fanuc Karel(基于Pascal)帮助需要
问题描述:
我的项目的任务是通过语音操纵fanuc机器人......问题出在我在机器人控制器上的karel的第二个代码中......首先,在机器人获得他的命令之后通过tcp/ip的整数形式,它以某种方式将它存储在一个缓冲区中,所以下次我开始编程它从上次会话运行命令而没有worning..and,这可能是非常危险的......所以我在卡雷尔程序BYTES_AHEAD和尝试清除端口,但它不会工作。接下来的问题是在条件循环...我试图运行多个命令,只要服务器连接使用循环REPEAT ... UNTIL ..但不会工作too.Please我需要帮助..不知道接下来什么...先谢谢大家!这是我的代码在卡雷尔...Fanuc Karel(基于Pascal)帮助需要
PROGRAM nikola
%NOLOCKGROUP
%NOPAUSE = ERROR + COMMAND + TPENABLE
VAR
i,n,tmp_int,STATUS:INTEGER
file_var:FILE
vox_str:STRING[128]
stat,n_bytes,entry,prog_index:INTEGER
FINISHED:BOOLEAN
----------------------VANJSKE RUTINE-------------------------
ROUTINE OPEN_FILE_(FILE_ : FILE; TAG_ : STRING) FROM LIB_FILE
ROUTINE CLOSE_FILE_(FILE_ : FILE; TAG_ : STRING) FROM LIB_FILE
ROUTINE WRITE_(STRING_ : STRING) FROM LIB_FILE
ROUTINE HANDSHAKING_(ID_ : STRING; TIP_: STRING) FROM LIB_FILE
--------------------------------------------------------------
BEGIN
SET_FILE_ATR(file_var, ATR_IA)
--set the server port BEFORE doing a CONNECT
SET_VAR(entry, '*SYSTEM*','$HOSTS_CFG[5].$SERVER_PORT',12350,STATUS)
stat=SET_PORT_ATR (PORT_1, ATR_READAHD,1)
--Spajanje tag-a
WRITE TPDISPLAY('Uspostava veze sa R2...',CR)
CLOSE_FILE_(file_var,'S5:')
OPEN_FILE_(file_var,'S5:')
IF IO_STATUS(file_var)<>0--inpput,output,value have to be 0 if there is connection established
THEN FINISHED=TRUE
ENDIF
REPEAT
BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
IF (n_bytes >= 1) THEN --if there is byres to be read
READ file_var(vox_str::1) --read byte by byte
stat=IO_STATUS (file_var) --status of operation
ENDIF
UNTIL stat <> 0 --continue until there is no bytes
REPEAT
FINISHED=FALSE
--Reading Command "Robovox go up"
REPEAT
BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
IF (n_bytes >= 1) THEN --if there is byres to be read
READ file_var(vox_str::1) --read byte by byte
stat=IO_STATUS (file_var) --status of operation
ENDIF
UNTIL stat <> 0 --continue until there is no bytes
--
IF (n_bytes = 0) THEN --is there is no bytes
READ file_var(vox_str::3)
ENDIF
IF UNINIT(vox_str) THEN
vox_str=''
ENDIF
IF (vox_str='120') THEN
CALL_PROG('NIK_UP',prog_index)
ENDIF
--Reading command "Robovox go down"
REPEAT
BYTES_AHEAD (file_var, n_bytes, STAT)--catching number of bytes ready to be read
IF (n_bytes >= 1) THEN --if there is byres to be read
READ file_var(vox_str::1) --read byte by byte
stat=IO_STATUS (file_var) --status of operation
ENDIF
UNTIL stat <> 0 --continue until there is ni bytes
--
IF (n_bytes = 0) THEN --if there is no bytes
READ file_var(vox_str::3)
ENDIF
IF (vox_str='130') THEN
ENDIF
CALL_PROG('NIK_DOWN',prog_index)
ENDIF
UNTIL (FINISHED=TRUE)
END nikola
答
您发布的代码很难阅读(缺乏缩进),有些看起来很奇怪(例如,接近结尾:if(vox_str ='130')then endif
因此...这是一个更多通用回复。
尝试添加代码以在开始时初始化变量并查看问题 是否消失。如果确实如此,那就意味着 未设置其中的一个或多个代码。
i:= 0; n:= 0; vox_str:=''; stat:= 0; n_bytes:= 0; entry:= 0; prog_index:= 0;
答
我使用这个程序init的缓冲区:
ROUTINE init_buffer
BEGIN
WRITE('init buffer',CR)
n_bytes=0
REPEAT
BYTES_AHEAD (file_var, n_bytes, STATUS) --Get number of bytes ready to be read
WRITE('remaining byte:',n_bytes,' STATUS ',STATUS, CR)
IF (n_bytes >= 1) THEN --there are bytes to be read
IF n_bytes>128 THEN
READ file_var(init_bufs::128)
STATUS=IO_STATUS (rs232) --get the status of the read operation
else
READ file_var(init_bufs::n_bytes)
STATUS=IO_STATUS (rs232) --get the status of the read operation
ENDIF
ENDIF
UNTIL n_bytes = 0 --continue until no more bytes are left
END init_buffer
你找出问题? – Jacob 2012-04-18 15:38:55