匯川AM401的TCP客戶端通訊

CSF践行發表於2024-07-31
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遮蔽掃碼槍;

相關文章