Page 142 - Welding Robots Technology, System Issues, and Applications
P. 142

Robotic Welding: System Issues  129

                                    CASE “system_state”:
                                        system_state; SocketSend client_socket1 \Str := answer_string;
                                    CASE “variable_read”:
                                        variable_read(par_1, par_2); SocketSend client_socket1 \Str :=
                                        answer_string;
                                    CASE “variable_write”:
                                        variable_write(par_1, par_2, par_3); SocketSend client_socket1
                                        \Str := answer_string;
                                    CASE “io_read”:
                                        io_read(par_1, par_2); SocketSend client_socket1 \Str :=
                                        answer_string;
                                    CASE “io_write”:
                                        io_read(par_1, par_2, par_3); SocketSend client_socket1 \Str :=
                                        answer_string;
                                    DEFAULT:
                                        SocketSend client_socket1 \Str := -9999;
                                ENDTEST
                                SocketClose client_socket1;
                               ELSE                                  Ignore connections if server
                                WaitTime 0.1;                        is disabled
                                SocketClose client_socket1;
                               ENDIF
                             ENDWHILE
                             ERROR                                         Retry socket listen if
                             SocketClose client_socket1;                   socket timed out
                             retry_sock:=1;
                             TRYNEXT;
                             UNDO
                             SocketClose server_socket;
                             SocketClose client_socket1;
                           ENDPROC
                           ENDMODULE
                           __________________________________________________________________

                                        Figure 4.12. TCP/IP socket server RAPID code [43][44]

                           This server was placed on the controller running as an extra-task, i.e., the robot has
                           a main task, where the foreground applications are running, and a second task used
                           to communicate with the external computer: to receive commands and exchange
                           information.

                           Third step  – write the client program: any TCP/IP  socket server  should be
                           capable of receiving and accepting connections from client applications, receive
                           and process commands, and deliver the obtained results. The following example
                           (Figure 4.13) is a simple TCP/IP socket client program coded using the Microsoft
                           Visual Basic .NET 2003 developing suite.
   137   138   139   140   141   142   143   144   145   146   147