.PROGRAM test()
;
; ABSTRACT:
;
; INPUTS:
;
; OUTPUTS:
;
; SIDE EFFECTS:
;
; DATA STRUCT:
;
; MISC: Program created in ACE version 3.6.3.2
;
;* Copyright (c) 2017 by {company name}
SIGNAL -2001
; WHILE NOT SWITCH(POWER) DO
; ENABLE POWER
; WAIT.EVENT , 1
; CALIBRATE
; END
DETACH () ;分离设备
SELECT ROB = 1 ;1号选择机器人
ATTACH () ;连接机器
; c = 1
; f = 1
s = 1
SPEED 1000 ALWAYS ;设置速度
;设置坐标,试验一下
SET pick = TRANS(495,-259,130,-128,177,57)
APPRO pick, 50
MOVE pick
;CALL home()
EXECUTE 3 tcp_client()
WAIT.EVENT , 0.02
WHILE TRUE DO
;pic坐标,为准备拾取的位置
APPRO pic, 50
MOVE pic
;2001软件触发,拍照
SIGNAL 2001
;等待,直到2002信号为true
WAIT SIG(2002)
;接收相机传来的坐标
SET pick = TRANS(str_data[1],str_data[2],130,-128,177,57)
;设置2002信号为false
SIGNAL -2002
SPEED 1000 ALWAYS
;靠近拾取坐标
APPRO pick, 60
;到达拾取坐标
MOVE pick
BREAK
MOVE pick
BREAK
SIGNAL 1
DEPART 80
50
CASE str_data[0] OF
VALUE 1:
GOTO 10
; VALUE 1:
; GOTO 20
; VALUE 3:
; GOTO 30
; ANY
; GOTO 50
END
10
APPRO s_p[s], 50
MOVES s_p[s]
BREAK
SIGNAL -1
s = s+1
IF s > 3 THEN
s = 1
END
GOTO 100
20
; APPRO c_p[c], 50
; MOVES c_p[c]
; BREAK
; SIGNAL -1
; c = c+1
; IF c > 3 THEN
; c = 1
; END
; GOTO 100
; 30
; APPRO f_p[f], 50
; MOVES f_p[f]
; BREAK
; SIGNAL -1
; f = f+1
; IF f > 3 THEN
; f = 1
; END
; GOTO 100
100
END
.END
tcp_client
.PROGRAM tcp_client()
;----------------------------------------------------------------------------
; ABSTRACT: Client programming example.客服户子
; NOTES: This program will continuously ask for an input string. The input
; string is displayed, the string is then sent to the server
; controller. If the string is "quit" the client program stops and
; the connection is broken. Reexecuting the program, reestablishes
; connection with the server.
;这个程序连续请求输入字符串,显示输入字符串,然后这个字符串被发送到服务器控制
;器之中。如果字符串是quit,客户程序停止,连接终止,重新执行程序,则重新连接服务器
; INPUT PARMS: None
; OUTPUT PARMS: None
;----------------------------------------------------------------------------
AUTO client_mode, lun, status, do_wait
AUTO $message, $echo, $read_str
; Initialize constants.
client_mode = 0
do_wait = 0
i3 = 1 ;
; Attach to the TCP device
ATTACH (lun, 4) "TCP"
TYPE "lun: ", lun
;type 相当于printf
status = IOSTAT(lun) ;Check status of ATTACH
IF status < 0 THEN
TYPE "Error from ATTACH: ", $ERROR(status)
GOTO 100
END
FSET (lun) "/node 'cell2' /address 172 16 196 100"
; FSET (lun) "/node 'cell2' /address 10 39 97 103"
; "cell2" is the name of the server connection as defined either in
; the default controller configuration or using a FSET instruction. A
; local port number is automatically establised, since the /LOCAL_PORT
; keyword is absent. The remote port number for the server must be
; known--1234 in this case. The buffer size is set to 1024 bytes.
FOPEN (lun, 0) "cell2 /REMOTE_PORT 9876 /BUFFER_SIZE 1024"
status = IOSTAT(lun) ;Check status of FOPEN
IF status < 0 THEN
TYPE "Error from FOPEN: ", $ERROR(status)
GOTO 100
END
; Loop until string is "quit". Send the str and read the echo from the server.
repeat_loop = TRUE
WHILE repeat_loop DO
;假如收到2001端口的IO开关信号,发送给lun一个字母m,欧姆龙视觉模块的m,是开始拍摄照片的命令
WHILE SIG(2001) DO
; WHILE i3 DO
;WAIT.EVENT 0.03
; i3 = 0 ;
WRITE (lun) "m"
;WRITE (lun) "m"
; WAIT.EVENT 0.03
; READ (lun, do_wait) $read_str
; TYPE "Received string : ", $read_str
; READ (lun, do_wait, 0) $string_var
; TYPE $string_var
i1 = 0
i2 = 0
; FOR i = 0 TO 6
; $temp = $DECODE($string_var,",",0)
; str_data[i1] = VAL($temp)
; i1 = i1+1
; END
; TYPE $string_var
; WHILE $string_var <> " " DO
READ (lun, do_wait, 0) $string_var
DO
$temp = $DECODE($string_var,",",0)
; TYPE $string_var
str_data[i2] = VAL($temp)
$temp = $DECODE($string_var,",",1)
i2 = i2+1
UNTIL $string_var == ""
; END
SIGNAL -2001
SIGNAL 2002
$inp_str = "The server has received your massege: "+$read_str
; WRITE (lun) $inp_str
IF $inp_str == "quit" THEN
repeat_loop = FALSE
END
END
END
100
FCLOSE (lun)
DETACH (lun)
FCLOSE (mlun)
DETACH (mlun)
RETURN
;SIGNAL -2001
.END
.PROGRAM tcp_server()
.PROGRAM tcp_server()
;------------------------------------------------------------------------------
; ABSTRACT: Server programming example. The server program reads any
; incoming strings, displays them on the monitor, and echoes them back
; to the client node.
; INPUT PARMS: None
; OUTPUT PARMS: None
; Program may be terminated by aborting.
;-----------------------------------------------------------------------------
AUTO handle, lun, no_wait, do_wait, server_mode, status
AUTO $in.str, $out.str, repeat_loop
; Initialize constants.
tcp.quit = FALSE
server_mode = 2
no_wait = 1
do_wait = 0
lun = 7
; Attach the TCP device (mode=4 means allocate next available LUN).
ATTACH (lun, 4) "TCP"
status = IOSTAT(lun) ;Check status of ATTACH
IF status < 0 THEN
TYPE "Error from ATTACH:", $ERROR(status)
GOTO 100
END
; Set up a socket with local port #1234, to accept 5 client
; connections, with a buffer size of 1024 bytes.
FOPEN (lun, 16) "/LOCAL_PORT 1234 /CLIENTS 5 /BUFFER_SIZE 1024"
status = IOSTAT(lun) ;Check status of ATTACH
IF status < 0 THEN
TYPE "Error from FOPEN:", $ERROR(status)
GOTO 100
END
repeat_loop = TRUE
WHILE repeat_loop DO
WAIT.EVENT , 0.01
READ (lun, handle, do_wait) $in.str
status = IOSTAT(lun)
CASE status OF
VALUE 1: ;Success--echo string back
$out.str = $in.str
TYPE "Received string: ", $out.str
WRITE (lun, handle) $out.str, /N
VALUE 100: ;New connection opened
TYPE "Newconnection established. Handle =", handle
VALUE 101: ;Connection closed
TYPE "Connection closed. Handle =", handle
FCMND (lun, 600) $INTB(handle) ; eallocates handle
status = IOSTAT(lun) ; Check status of FCMND
IF status < 0 THEN
TYPE "Error from FCMND:", $ERROR(status)
GOTO 100
END
WAIT
VALUE -526: ; No data received
ANY ; Some other error
TYPE "Error during READ: ", $ERROR(status)
GOTO 100
END
END
; Close all open client connections, and release the logical unit.
100 FCLOSE (lun)
DETACH (lun)
RETURN
.END