MAIN.TcPOU 5.43 KB
<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.11">
  <POU Name="MAIN" Id="{968875a9-52a2-46cd-ac4e-792ab91256f6}" SpecialFunc="None">
    <Declaration><![CDATA[PROGRAM MAIN
VAR
	bSamplingStart	: BOOL := False;
	nAcuNodeId		: INT := 1;
	iSeq 			: INT;
	nIncCtr			: INT;
	nFirstAcuIndex	: UINT;
	i01Sec:DINT := 0;
	currSync0Count:UINT;
	lastSync0Count:UINT := 0;
	diffSync0:INT := -1;
	
	AcquisitionBlockBuffer			:	 ARRAY [0..nFifoSize] OF stAcquisitionBlock;		(*  Put one Acq Block into fifo buffer *)
	fbBufferAccess	: FB_DataFifo;
		
END_VAR
]]></Declaration>
    <Implementation>
      <ST><![CDATA[//IF NOT bSamplingStart THEN
//	ADSLOGSTR(
//				msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_LOG,
//				msgFmtStr   := 'SYNC0 not correct %s', 
//				strArg      := '55'
//			);
//END_IF

//IF bSamplingStart THEN
	currSync0Count := AcquisitionData[nAcuNodeId].ECAT_SYNC0_Counter;

	IF diffSync0 < 0 THEN
		lastSync0Count := currSync0Count;
		diffSync0 := 1;
//		ADSLOGSTR(
//				msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_MSGBOX,
//				msgFmtStr   := 'Start testing', 
//				strArg      := ''
//			); 
	ELSE
		
		IF diffSync0 <> 1 THEN
			 ADSLOGSTR(
				msgCtrlMask := ADSLOG_MSGTYPE_WARN OR ADSLOG_MSGTYPE_MSGBOX,
				msgFmtStr   := 'SYNC0 not correct %s', 
				strArg      := INT_TO_STRING(diffSync0)
			);      
		END_IF
		
	END_IF

//END_IF


diffSync0 := currSync0Count - lastSync0Count;
lastSync0Count := currSync0Count;


CASE iSeq OF 
0:
	IF bSamplingStart THEN
		iSeq := iSeq + 1;
	END_IF
1:	
	(* reserve for init process *)
	fbBufferAccess.bClearFifo := TRUE;
	IF fbBufferAccess.bFifoEmpty THEN		(* Makesure no data in buffer in inital phase *)
		fbBufferAccess.bClearFifo := FALSE;
		iSeq := 10;
	END_IF
10:	(*  Cyclic Acquisition *)
	nIncCtr := nIncCtr + 1;					(*   Generate a dummy data  *)
	AcquisitionData[nAcuNodeId].ECAT_IRQ_Counter := nIncCtr;
	AcquisitionData[nAcuNodeId].nDcTimeStamp := UInt64Add64( F_GetCurDcTickTime(), EC_DCTIME_DELTA_OFFSET);	(* Shift time from GMT+0 to Current time Zone *)
	
	AcquisitionBlock[nAcuNodeId].DataBlock[nFirstAcuIndex] := AcquisitionData[nAcuNodeId];
	nFirstAcuIndex := nFirstAcuIndex + 1;
	
	IF nFirstAcuIndex > nAcquisitionBlock THEN
		nFirstAcuIndex := 0 ;				(* Block collect finish , put into buffer *)
		fbBufferAccess.bPutData := TRUE;
		
		IF i01Sec < 10 THEN
			i01Sec := i01Sec + 1;
		ELSE
			i01Sec := 0;
			//fbBufferAccess.bFifoFull := FALSE;
		END_IF
		
		IF NOT(bSamplingStart) THEN
			iSeq := 20;			(* Stop Acquisition *)
		END_IF
	END_IF

20:	(* Should call close file process *)
	iSeq := 0;
END_CASE


fbBufferAccess(bPutData:= , 
	bGetData:= , 
	bClearFifo:= , 
	pPutData:= ADR(AcquisitionBlock[nAcuNodeId]), 
	pGetData:= ADR(PRG_DatFileCreat.DatAcqBlock), 
	nDataLen:= SIZEOF(AcquisitionBlock[nAcuNodeId]), 
	pFifoMemory:= ADR(AcquisitionBlockBuffer), 
	nFifoSize:= nFifoSize, 
	bFifoEmpty=> , 
	bFifoFull=> , 
	iFifoSizeLeft=> );


IF fbBufferAccess.bPutData THEN
	fbBufferAccess.bPutData := FALSE;
END_IF; 	
	
IF fbBufferAccess.bGetData THEN
	fbBufferAccess.bGetData := FALSE;
END_IF

PRG_DatFileCreat();



]]></ST>
    </Implementation>
    <LineIds Name="MAIN">
      <LineId Id="334" Count="5" />
      <LineId Id="329" Count="0" />
      <LineId Id="327" Count="0" />
      <LineId Id="287" Count="0" />
      <LineId Id="291" Count="3" />
      <LineId Id="357" Count="0" />
      <LineId Id="295" Count="2" />
      <LineId Id="356" Count="0" />
      <LineId Id="299" Count="10" />
      <LineId Id="288" Count="0" />
      <LineId Id="290" Count="0" />
      <LineId Id="289" Count="0" />
      <LineId Id="245" Count="0" />
      <LineId Id="267" Count="0" />
      <LineId Id="241" Count="0" />
      <LineId Id="237" Count="1" />
      <LineId Id="29" Count="0" />
      <LineId Id="35" Count="0" />
      <LineId Id="45" Count="0" />
      <LineId Id="62" Count="0" />
      <LineId Id="67" Count="1" />
      <LineId Id="61" Count="0" />
      <LineId Id="49" Count="0" />
      <LineId Id="110" Count="1" />
      <LineId Id="113" Count="0" />
      <LineId Id="69" Count="0" />
      <LineId Id="112" Count="0" />
      <LineId Id="51" Count="0" />
      <LineId Id="121" Count="0" />
      <LineId Id="72" Count="0" />
      <LineId Id="167" Count="0" />
      <LineId Id="234" Count="0" />
      <LineId Id="119" Count="0" />
      <LineId Id="52" Count="0" />
      <LineId Id="75" Count="0" />
      <LineId Id="53" Count="0" />
      <LineId Id="76" Count="0" />
      <LineId Id="84" Count="0" />
      <LineId Id="211" Count="1" />
      <LineId Id="214" Count="0" />
      <LineId Id="216" Count="1" />
      <LineId Id="219" Count="0" />
      <LineId Id="215" Count="0" />
      <LineId Id="88" Count="0" />
      <LineId Id="78" Count="0" />
      <LineId Id="81" Count="1" />
      <LineId Id="77" Count="0" />
      <LineId Id="56" Count="2" />
      <LineId Id="46" Count="0" />
      <LineId Id="30" Count="1" />
      <LineId Id="18" Count="0" />
      <LineId Id="20" Count="8" />
      <LineId Id="2" Count="0" />
      <LineId Id="97" Count="1" />
      <LineId Id="90" Count="0" />
      <LineId Id="103" Count="0" />
      <LineId Id="99" Count="0" />
      <LineId Id="94" Count="0" />
      <LineId Id="92" Count="0" />
      <LineId Id="108" Count="0" />
      <LineId Id="106" Count="0" />
      <LineId Id="117" Count="1" />
      <LineId Id="182" Count="1" />
      <LineId Id="175" Count="0" />
      <LineId Id="114" Count="0" />
    </LineIds>
  </POU>
</TcPlcObject>