Page 141 - Welding Robots Technology, System Issues, and Applications
P. 141
128 Welding Robots
__________________________________________________________________
MODULE server_sock
VAR socketdev server_socket;
VAR socketdev client_socket1;
VAR string receive_string;
VAR string command;
VAR string answer_string;
VAR string par_1;
VAR string par_2;
VAR num par_3;
VAR num answer_1; Declaration of variables
VAR num answer-2;
VAR num answer_3;
VAR num answer_4;
VAR string client_ip;
VAR socketstatus state;
PERS num retry_sock:=0;
PERS num working:=1; Create and bind the server socket
PROC main() and start listening for connections
WaitTime 0.1;
SocketCreate server_socket;
SocketBind server_socket, "172.16.0.89", 2004;
SocketListen server_socket;
WHILE TRUE DO
again_sock:
IF working = 1 THEN
SocketAccept server_socket, client_socket1 \ClientAddress:=client_ip;
IF retry_sock = 1 THEN
retry_sock:=0;
GOTO again_sock;
ENDIF
SocketReceive client_socket1 \Str := receive_string;
extract_info; State machine
TEST command
CASE “motor_on”:
motor_on; SocketSend client_socket1 \Str := answer_string;
CASE “motor_off”:
motor_off; SocketSend client_socket1 \Str := answer_string;
CASE “program_run”:
program_run(par_1); SocketSend client_socket1 \Str :=
answer_string;
CASE “program_run_pp”:
program_run_pp; SocketSend client_socket1 \Str := answer_string;
CASE “program_stop”:
program_stop; SocketSend client_socket1 \Str := answer_string;
CASE “program_run_pp”:
program_run_pp; SocketSend client_socket1 \Str := answer_string;