汇川AM401的TCP客户端通信
VAR_GLOBAL
abySendData_0 := [76, 79, 78, 13]; abyReciveData_0 : ARRAY[0..19] OF BYTE; strReciveData_0 : STRING(20); x触发扫码 : BOOL;
x屏蔽扫码枪 :BOOL; END_VAR
//发送触发 IF MEP(CLK:=x触发扫码 AND NOT x屏蔽扫码枪,M:=rise11) THEN //MEP代表取上升沿 FOR i:=0 TO 19 BY 1 DO abyReciveData_0[i]:=0; END_FOR abySendData_0[0]:=16#4C; abySendData_0[1]:=16#4F; abySendData_0[2]:=16#4E; abySendData_0[3]:=16#0D; END_IF //连接服务器 TCP_Client_0( xEnable:= TCP_Client_0.xActive OR Clock_1HZ, strIpAddrDst:= '192.168.1.22', // uiPortDst:= 9004, udiTimeOut:= 500000, xDone=> , xBusy=> , xError=> , dwErrorID=> , xActive=> , hConnection=> ); //发送 TCP_Send_0( xExecute:= x开始发送_0 AND TCP_Client_0.xActive, hConnection:= TCP_Client_0.hConnection, uiSize:= SIZEOF(abySendData_0), pbyData:= ADR(abySendData_0), udiTimeOut:= 500000, xDone=> , xBusy=> , xError=> , dwErrorID=> ); x开始发送_0 R=TCP_Send_0.xDone; //接收 TCP_Receive_0( xEnable:= TCP_Client_0.xActive, hConnection:= TCP_Client_0.hConnection, uiSize:= SIZEOF(abyReciveData_0), pbyData:= ADR(abyReciveData_0), xDone=> , xBusy=> , xError=> , dwErrorID=> , xReady=> , uiCount=> ); AryToString(In:= abyReciveData_0[0], Size:= 20, Out=> strReciveData_0); //异常检测 E_扫码枪1通信断开:=NOT TCP_Client_0.xActive AND NOT x屏蔽扫码枪;