我的项目的任务是操纵fanuc机器人的voice...the问题是在我的第二个代码在机器人controller...first上的karel,在机器人得到他的命令后,在tcp/ip的整数形式,以某种方式存储在一个缓冲区中,所以下次我启动程序它运行从上一次会话没有worning..and的命令,这可以是非常dangerous...so我在karel过程BYTES_AHEAD中找到,并试图清除端口,但它不会work.Next问题是在条件循环...我已经尝试运行一个以上的命令,只要有服务器连接与循环REPEAT...UNTIL..but将不会工作too.Please我需要帮助..不知道什么做next...thank你们大家提前!这是我的代码在karel...
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发布于 2012-10-08 22:01:04
我使用这个例程初始化缓冲区:
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发布于 2011-05-21 05:40:30
你发布的代码很难阅读(没有缩进),有些看起来很奇怪(例如,接近尾部: if (vox_str = '130') then endif
So...this是一种更通用的回复。
尝试添加代码以在开始时初始化变量,并查看问题是否消失。如果是这样,这意味着代码中有一些路径没有设置其中的一个或多个。
I := 0;n := 0;vox_str := '';stat := 0;n_bytes := 0;entry := 0;prog_index := 0;
您可能还想阅读http://www.allegro.com/papers/htpp.html
https://stackoverflow.com/questions/4887331
复制相似问题