美文网首页
台达DVP15MC与AS228T进行Socket通信测试程序

台达DVP15MC与AS228T进行Socket通信测试程序

作者: TomatoTor | 来源:发表于2019-12-10 10:53 被阅读0次

    DVP15MC部分

    通过LAN2端口与AS228T进行Socket通信

    变量声明

    范围 名称 地址 数据类型
    VAR Socket_Manage ETH_Socket_Manage
    VAR Socket_Config ETH_Socket_Config
    VAR Socket_Open ETH_Socket_Open
    VAR Socket_Send ETH_Socket_Send
    VAR Socket_Receive ETH_Socket_Receive
    VAR Socket_Close ETH_Socket_Close
    VAR Socket_Status ETH_Socket_Status
    VAR UsiSocketSendBufferData %MB12000 USINT
    VAR UsiSocketReceiveBufferData %MB12200 USINT
    VAR bSocketSendExecute BOOL
    VAR bSocketSendAbort BOOL
    VAR bSocketReceiveExecute BOOL
    VAR bSocketReceiveAbort BOOL
    VAR bSocketManageEnable BOOL
    VAR bInit BOOL
    VAR ArSocketSFData %MB12000 ARRAY[1..200] OF USINT
    VAR ArSocketRFData %MB12200 ARRAY[1..200] OF USINT

    程序编写

    //初始化 将MODBUS TCP数据初始化写入发送缓冲区
    IF EDGEPOS(bInit) THEN
        ArSocketSFData[1]  := 16#00 ;
        ArSocketSFData[2]  := 16#00 ;
        ArSocketSFData[3]  := 16#00 ;
        ArSocketSFData[4]  := 16#00 ;
        ArSocketSFData[5]  := 16#00 ;
        ArSocketSFData[6]  := 16#0b ;
        ArSocketSFData[7]  := 16#00 ;
        ArSocketSFData[8]  := 16#10 ;
        ArSocketSFData[9]  := 16#10 ;
        ArSocketSFData[10] := 16#00 ;
        ArSocketSFData[11] := 16#00 ;
        ArSocketSFData[12] := 16#02 ;
        ArSocketSFData[13] := 16#04 ;
        ArSocketSFData[14] := 16#aa ;
        ArSocketSFData[15] := 16#bb ;
        ArSocketSFData[16] := 16#cc ;
        ArSocketSFData[17] := 16#dd ;
        bInit              := FALSE ;
    END_IF;
    
    //管理
    Socket_Manage(Enable:= TRUE,EnableSocket:= bSocketManageEnable);
    //配置
    Socket_Config(Execute:= Socket_Manage.SocketReady,
        SocketNum:= 1,
        Protocol_Type:= 0, //0:Socket UDP ;1:Socket TCP
        RemoteIP_segment1:= 192,
        RemoteIP_segment2:= 168,
        RemoteIP_segment3:= 5,
        RemoteIP_segment4:= 10,
        Remote_port:= 502,
        Local_port:= 502,
        LinkKeeptime:= 30,
        //Done=> ,
        //Busy=> ,
        //Error=> ,
        //ErrorID=> 
        );
    //打开
    Socket_Open(Execute:= Socket_Config.Done,
        SocketNum:= 1,
        OpenMode:= TRUE, //TRUE:客户端模式; FALSE:服务器模式
        //Done=> ,
        //Busy=> ,
        //Error=> ,
        //ErrorID=> 
        );
    //发送
    Socket_Send(Execute:= bSocketSendExecute,
        Abort:= bSocketSendAbort,
        SocketNum:= 1,
        CyclicRun:= FALSE,//TRUE:周期发送数据;FALSE:仅发送一笔数据
        CycleTime:= 100,
        Send_Buffer_Address:= UsiSocketSendBufferData,
        Send_Length:= 200,
        //Done=> ,
        //Sent=> ,
        //Sending=> ,
        //Busy=> ,
        //Active=> ,
        //Aborted=> ,
        //Error=> ,
        //ErrorID=> 
        );  
    //接收    
    Socket_Receive(Execute:= bSocketReceiveExecute,
        Abort:= bSocketReceiveAbort,
        SocketNum:= 1,
        ReceiveMode:= 1,//0:持续接收数据;1:只接受一笔数据
        DataSaveMode:= 1,//0:拼接模式;1:覆盖模式
        Receive_Buffer_Address:= UsiSocketReceiveBufferData,
        Receive_Length:= 200,
        //Done=> ,
        //Received=> ,
        //Receiving=> ,
        //Received_Length=> ,
        //Busy=> ,
        //Active=> ,
        //Aborted=> ,
        //Error=> ,
        //ErrorID=> 
        );
    //关闭
    Socket_Close(Execute:= Socket_Receive.Done,
        SocketNum:= 1,
        //Done=> ,
        //Busy=> ,
        //Error=> ,
        //ErrorID=> 
        );
    //状态
    Socket_Status(Enable:= TRUE,
        SocketNum:= 1,
        //Valid=> ,
        //Conected=> ,
        //Received=> ,
        //Closed=> ,
        //Send=> ,
        //Opening=> ,
        //Receiving=> ,
        //Closing=> ,
        //Sending=> ,
        //Error=> ,
        //ErrorID=> 
        );
    

    Log:
    2019-12-10 发布本文

    相关文章

      网友评论

          本文标题:台达DVP15MC与AS228T进行Socket通信测试程序

          本文链接:https://www.haomeiwen.com/subject/lsxigctx.html