A - 41
Appendices
NX-series Communications Interface Units User’s Manual (W540)
A-4 Programming Samples
A
A-4-4 Programming Sample 3: Receiving Data
// Initialize program status using establishing communications as the trigger.
InitialRequestTrigger_R_TRIG_instance(
E001_NX_Unit_I_O_Data_Active_Status_125[1],
InitialRequestTrigger);
IF( InitialRequestTrigger = TRUE ) THEN
RcvInitialize := FALSE;//Initialize.
END_IF;
//See if I/O communications are enabled and if Input SID was updated.
IF ( ( E001_NX_Unit_I_O_Data_Active_Status_125[1] = TRUE )
AND ( N1_Ch1_Input_SID_Response <> N1_Ch1_Input_SID) ) THEN
IF ((N1_Ch1_Receive_Data_Error_Flag = TRUE ) //Process (1)
OR (RcvError = TRUE))THEN
//If a receive data error is detected,
//skip the receive data until the end of the serial data is detected.
RcvSize := UINT#0;
RcvError := TRUE;
//Set the Input SID Response.
N1_Ch1_Input_SID_Response := N1_Ch1_Input_SID;
ELSIF ((N1_Ch1_Receive_Data_Flag = TRUE ) OR // Process (2)
(N1_Ch1_Receive_Last_Data_Flag = TRUE )) THEN
//When there is no receive data error and there is input data
IF( RcvInitialize=FALSE) THEN
//Initialize reception process.
RcvSize := UINT#0;
RcvInitialize := TRUE;
RcvDone:=FALSE;
END_IF;
//Get receive data.
//Set the RcvDat array to the following size: Maximum receive data
//size [bytes] + Input divided data size [bytes]
AryMove(N1_Ch1_Input_Data_01[0], RcvDat[RcvSize], UINT#4);
AryMove(N1_Ch1_Input_Data_02[0], RcvDat[RcvSize+4], UINT#4);
AryMove(N1_Ch1_Input_Data_03[0], RcvDat[RcvSize+8], UINT#4);
AryMove(N1_Ch1_Input_Data_04[0], RcvDat[RcvSize+12], UINT#4);
AryMove(N1_Ch1_Input_Data_05[0], RcvDat[RcvSize+16], UINT#4);
RcvSize:=RcvSize+N1_Ch1_Input_Data_Length;
//Set the Input SID Response.
N1_Ch1_Input_SID_Response := N1_Ch1_Input_SID;
END_IF;
// Check for final data. // Process (3)
IF (N1_Ch1_Receive_Last_Data_Flag = TRUE ) THEN
IF( RcvError = FALSE ) THEN
//If there is no reception error and the final data is obtained
RcvDone:=TRUE; //End reception.
END_IF;
RcvError := FALSE;
RcvInitialize := FALSE;
END_IF;
END_IF;
ST Program