ABB Robot Socket Client Code (Send_p1ge0n_message)

!this proc sends a message with p1ge0n
PROC Send_p1ge0n_message(string message)
    !change this to the IP address of the computer running p1ge0n software
    CONST string IP_address_of_p1ge0n_computer:="192.168.1.51";
    !change this to the port the p1ge0n software is listening on
    CONST num p1ge0n_port:=51015;

    VAR num retry_no:=0;
    VAR socketdev p1ge0n_socket;
    SocketCreate p1ge0n_socket;
    SocketConnect p1ge0n_socket,IP_address_of_p1ge0n_computer,p1ge0n_port;
    SocketSend p1ge0n_socket\Str:=message;

    SocketClose p1ge0n_socket;
ERROR
    IF ERRNO=ERR_SOCK_TIMEOUT THEN
        IF retry_no<3 THEN
            WaitTime 1;
            retry_no:=retry_no+1;
            RETRY;
        ELSE
            SocketClose p1ge0n_socket;
            RETURN ;
        ENDIF
    ENDIF
    IF ERRNO=ERR_SOCK_CLOSED THEN
        IF retry_no<3 THEN
            WaitTime 1;
            SocketCreate p1ge0n_socket;
            retry_no:=retry_no+1;
            RETRY;
        ELSE
            SocketClose p1ge0n_socket;
            RETURN ;
        ENDIF
    ENDIF
    IF ERRNO=ERR_SOCK_NET_UNREACH THEN
        IF retry_no<3 THEN
            WaitTime 1;
            retry_no:=retry_no+1;
            RETRY;
        ELSE
            SocketClose p1ge0n_socket;
            RETURN ;
        ENDIF
    ENDIF
ENDPROC

1 Comment

Comments are closed