{"id":673,"date":"2021-08-27T03:31:14","date_gmt":"2021-08-27T03:31:14","guid":{"rendered":"http:\/\/gongyikun.cn\/?p=673"},"modified":"2021-08-27T03:32:02","modified_gmt":"2021-08-27T03:32:02","slug":"abb%e6%9c%ba%e5%99%a8%e4%ba%basocket%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.gongyikun.cn\/?p=673","title":{"rendered":"ABB\u673a\u5668\u4eba||Socket\u670d\u52a1\u5668\u7a0b\u5e8f\u4ee3\u7801"},"content":{"rendered":"<p>\u7a0b\u5e8f\u4e0a\u8bbe\u7f6e\u7684\u662f\u5148\u63a5\u6536\uff0c\u7136\u540e\u5728\u53d1\u9001\u6570\u636e\u3002<\/p>\n<h3>\u4e3b\u7a0b\u5e8f<\/h3>\n<pre><code class=\"language-cpp line-numbers\">    PROC main()\n        SocketIni;\/\/ \u8c03\u7528Socket\u521d\u59cb\u5316\u5b50\u7a0b\u5e8f\n        WHILE TRUE DO\n            SocketReceiveData;\/\/  \u8c03\u7528\u63a5\u6536\u6570\u636e\u5b50\u7a0b\u5e8f\n            Start_Stop;\n            RobotState;\n            SocketSendData;\/\/ \u8c03\u7528\u53d1\u9001\u6570\u636e\u5b50\u7a0b\u5e8f\n        ENDWHILE\n<\/code><\/pre>\n<h3>Socket\u521d\u59cb\u5316<\/h3>\n<pre><code class=\"language-cpp line-numbers\">    PROC SocketIni()\n        SocketClose socketServer;!close server \n        SocketClose client_socket;!close client connection \n        Client_Ip := \"\";\n        SocketCreate socketServer;!create socket\n        SocketBind socketServer, Sever_IP_Address, Sever_Port;!bind Ip and port \n        SocketListen socketServer;\n        SocketAccept socketServer,client_socket\\ClientAddress:=Client_Ip\\Time:=WAIT_MAX;!accept client connection\n    ENDPROC\n<\/code><\/pre>\n<h3>Socket\u6570\u636e\u63a5\u6536<\/h3>\n<pre><code class=\"language-cpp line-numbers\"> PROC SocketReceiveData()\n        ReceiveData :=[0,0,0,0,0,0,0,0,0,0];\n        SocketReceive client_socket \\Data:= ReceiveData;!Receive Data \n        arrReceiveData:=ReceiveData;\n        arrSendData{3} := arrReceiveData{3};\n        arrSendData{4} := arrReceiveData{4};\n        !TPWrite ByteToStr(ReceiveData{1});\n        !WaitTime 0.1;\n        !TPWrite ByteToStr(ReceiveData{3});\n        !Start_Stop;\n        ProgramName;\n\n        ERROR\n            IF ERRNO=ERR_SOCK_CLOSED THEN\n                SocketIni;\n                RETRY;\n            ENDIF\n            IF ERRNO=ERR_SOCK_TIMEOUT THEN\n                SocketIni;\n                WaitTime 0.2;\n                RETRY;\n            ENDIF\n    ENDPROC\n<\/code><\/pre>\n<h3>Socket\u6570\u636e\u53d1\u9001<\/h3>\n<pre><code class=\"language-cpp line-numbers\">    PROC SocketSendData()\n        IF SendData{1}=0 THEN \n            WaitTime 0.2;\n            arrSendData{1}:=1;\n        ELSE\n            WaitTime 0.2;\n            arrSendData{1}:=0;\n        ENDIF\n        SendData:=arrSendData;\n        SocketSend client_socket\\Data:=SendData;\n\n     ERROR\n        IF ERRNO = ERR_SOCK_CLOSED OR ERRNO = SOCKET_LISTENING THEN\n            SocketIni;\n        RETRY;\n    ENDIF\n    ENDPROC\n<\/code><\/pre>\n<div class=\"clearfix\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\u7a0b\u5e8f\u4e0a\u8bbe\u7f6e\u7684\u662f\u5148\u63a5\u6536\uff0c\u7136\u540e\u5728\u53d1\u9001\u6570\u636e\u3002 \u4e3b\u7a0b\u5e8f PROC main() SocketIni;\/\/ \u8c03\u7528Sock [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[24],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/673"}],"collection":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=673"}],"version-history":[{"count":4,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":677,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/673\/revisions\/677"}],"wp:attachment":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}