﻿<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://www.plcopen.org/xml/tc6_0200">
  <fileHeader companyName="Rexroth" productName="ctrlX PLC Engineering" productVersion="ctrlX PLC 2.6.0" creationDateTime="2024-07-01T11:01:46.3558562" />
  <contentHeader name="Test_2_FSoE_Master_PLC.project" modificationDateTime="2024-07-01T10:59:47.2738049">
    <coordinateInfo>
      <fbd>
        <scaling x="1" y="1" />
      </fbd>
      <ld>
        <scaling x="1" y="1" />
      </ld>
      <sfc>
        <scaling x="1" y="1" />
      </sfc>
    </coordinateInfo>
    <addData>
      <data name="http://www.3s-software.com/plcopenxml/projectinformation" handleUnknown="implementation">
        <ProjectInformation />
      </data>
    </addData>
  </contentHeader>
  <types>
    <dataTypes />
    <pous>
      <pou name="SAFEX_FSoE_Diagnosis_1V05" pouType="functionBlock">
        <interface>
          <inputVars>
            <variable name="EtherCAT_State_OP">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml">Enable FSoE requires an EtherCAT status OP</xhtml>
              </documentation>
            </variable>
            <variable name="byFSoE_Slave_CMD">
              <type>
                <BYTE />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-Master Connection x Adress of FSoE_SlaveCommand</xhtml>
              </documentation>
            </variable>
            <variable name="byFSoE_Slave_DATA1">
              <type>
                <BYTE />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-Master Connection x Adress of FSoE_Slave_DATA1</xhtml>
              </documentation>
            </variable>
            <variable name="wFSoE_Slave_CRC">
              <type>
                <WORD />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-Master Connection x Adress of FSoE_Slave_CRC</xhtml>
              </documentation>
            </variable>
            <variable name="bReset">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Reset Logbook</xhtml>
              </documentation>
            </variable>
          </inputVars>
          <outputVars>
            <variable name="bFSoE_OK">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE is OK no error </xhtml>
              </documentation>
            </variable>
            <variable name="bFSoE_Error">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-Error activ </xhtml>
              </documentation>
            </variable>
            <variable name="strError">
              <type>
                <string />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE Errortext</xhtml>
              </documentation>
            </variable>
            <variable name="uiFSoE_ErrorCounter">
              <type>
                <UINT />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-Error Counter</xhtml>
              </documentation>
            </variable>
            <variable name="diFSoE_CycleTime">
              <type>
                <DINT />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> FSoE-CycleTime in ms</xhtml>
              </documentation>
            </variable>
          </outputVars>
          <localVars>
            <variable name="wFSoE_Slave_CRC_OLD">
              <type>
                <WORD />
              </type>
            </variable>
            <variable name="R_TRIG_FSoE_Error">
              <type>
                <derived name="R_TRIG" />
              </type>
            </variable>
            <variable name="R_TRIG_CRC_Change">
              <type>
                <derived name="R_TRIG" />
              </type>
            </variable>
            <variable name="tTime">
              <type>
                <TIME />
              </type>
            </variable>
            <variable name="tTimeOld">
              <type>
                <TIME />
              </type>
            </variable>
            <variable name="dtDateTime">
              <type>
                <DT />
              </type>
            </variable>
            <variable name="strErrorOld">
              <type>
                <string />
              </type>
            </variable>
            <variable name="arErrorLogReset">
              <type>
                <array>
                  <dimension lower="0" upper="30" />
                  <baseType>
                    <string />
                  </baseType>
                </array>
              </type>
            </variable>
            <variable name="arErrorLogDateTimeReset">
              <type>
                <array>
                  <dimension lower="0" upper="30" />
                  <baseType>
                    <DT />
                  </baseType>
                </array>
              </type>
            </variable>
            <variable name="R_TRIG_ErrorChange">
              <type>
                <derived name="R_TRIG" />
              </type>
            </variable>
          </localVars>
          <localVars retain="true">
            <variable name="arErrorLog">
              <type>
                <array>
                  <dimension lower="0" upper="30" />
                  <baseType>
                    <string />
                  </baseType>
                </array>
              </type>
            </variable>
            <variable name="arErrorLogDateTime">
              <type>
                <array>
                  <dimension lower="0" upper="30" />
                  <baseType>
                    <DT />
                  </baseType>
                </array>
              </type>
            </variable>
            <variable name="uiIndex">
              <type>
                <UINT />
              </type>
            </variable>
          </localVars>
          <documentation>
            <xhtml xmlns="http://www.w3.org/1999/xhtml">---------------------------------------------------------------------------------------------------------------------------------------
Short description:
The function block can be used to perform an error analysis of FSoE communication 
Version: 1.05	
Name: 	DC-AE/STS2 Dirk Asendorf
Date:	2024.07.01	
Company:	Bosch-Rexroth AG
---------------------------------------------------------------------------------------------------------------------------------------
Target: 	ctrlX CORE (EtherCat)
Needs: 	SAFEX Firmware &gt; 1.0.1.28 / FPGA 211
			ctrlx SAFETY Engineering &gt; 1.7.1.8239
			EtherCAT 
History
---------------------------------------------------------------------------------------------------------------------------------------
Dirk Asendorf | 01.07.2024 | Version 1V05
- New Function FSoE CycleTime measurement 
- New Function Logbook with TimeStamps

Dirk Asendorf | 25.03.2024 | Version 1V04
- recreation

---------------------------------------------------------------------------------------------------------------------------------------
 Functional Description:
 The function block can be used to perform an error analysis of FSoE communication between an FSoE master and an FSoE slave in the PLC. 
 The function block monitors the command of an FSoE connection. If the command has the value 54, the following data is correct. 
 If the command has the value 42, the following data contains an error code.
---------------------------------------------------------------------------------------------------------------------------------------</xhtml>
          </documentation>
        </interface>
        <body>
          <ST>
            <xhtml xmlns="http://www.w3.org/1999/xhtml">IF EtherCAT_State_OP THEN	// FSoE requires an EtherCAT status OP
	R_TRIG_FSoE_Error(CLK:= bFSoE_Error, Q=&gt; );

	R_TRIG_CRC_Change(CLK:=wFSoE_Slave_CRC_OLD &lt;&gt; wFSoE_Slave_CRC , Q=&gt; );	

	R_TRIG_ErrorChange(CLK:= strErrorOld &lt;&gt; strError, Q=&gt; );
	
	dtDateTime:= IL_DateAndTime(TRUE);
	
	IF R_TRIG_CRC_Change.Q THEN
		tTime:= TIME();
		diFSoE_CycleTime:= TO_DINT(tTime - tTimeOld);
	END_IF
 
	IF R_TRIG_FSoE_Error.Q OR R_TRIG_ErrorChange.q THEN
		arErrorLog[uiIndex]:= 			strError;
		arErrorLogDateTime[uiIndex]:= 	dtDateTime;
		IF uiIndex &lt; 30 THEN
			uiIndex:= uiIndex + 1;
		ELSE	
			uiIndex:= 0;
		END_IF
	END_IF
	
	IF byFSoE_Slave_CMD = 42 THEN		// FSoE command 42 means FSoE error

		CASE byFSoE_Slave_DATA1 OF
			0:	strError:= 'Local reset or acknowledgement of a RESET command';
			1:	strError:= 'Unexpected command (INVALID_CMD)';
			2:	strError:= 'Unknown command (UNKNOWN_CMD)';
			3:	strError:= 'Invalid connection ID (INVALID_CONNID)';
			4:	strError:= 'CRC error (INVALID_CRC)';
			5:	strError:= 'Watchdog has expired (WD_EXPIRED)';
			6:	strError:= 'Invalid FSoE Slave Address (INVALID_ADDRESS)';
			7:	strError:= 'Invalid safety data (INVALID_DATA)';
			8:	strError:= 'Invalid communication parameter length (INVALID_COMMPARALEN)';
			9:	strError:= 'Invalid communication parameter data (INVALID_COMPARA)';
			10:	strError:= 'Invalid application parameter length (INVALID_USERPARALEN)';
			11:	strError:= 'Invalid application parameter data (INVALID_USERPARA)';	
		END_CASE

		bFSoE_Error:= 	TRUE;
		bFSoE_OK:= 		FALSE;

	ELSIF byFSoE_Slave_CMD = 54 THEN    //FSoE is OK
		bFSoE_Error:= 	FALSE;
		bFSoE_OK:= 		TRUE;
		strError:= '';
	END_IF

	IF R_TRIG_FSoE_Error.Q THEN
		uiFSoE_ErrorCounter:= uiFSoE_ErrorCounter + 1;
	END_IF
	
	IF bReset THEN
		uiFSoE_ErrorCounter:= 	0;
		arErrorLog:= 			arErrorLogReset;
		arErrorLogDateTime:= 	arErrorLogDateTimeReset;
		uiIndex:=				0;
		
	END_IF
	
	wFSoE_Slave_CRC_OLD:= 	wFSoE_Slave_CRC;
	tTimeOld:= 				tTime;
	strErrorOld:=			strError;
END_IF
</xhtml>
          </ST>
        </body>
        <addData>
          <data name="http://www.3s-software.com/plcopenxml/objectid" handleUnknown="discard">
            <ObjectId>db8cc508-ad9a-47cb-aeac-be73b1142a4c</ObjectId>
          </data>
        </addData>
      </pou>
    </pous>
  </types>
  <instances>
    <configurations />
  </instances>
  <addData>
    <data name="http://www.3s-software.com/plcopenxml/projectstructure" handleUnknown="discard">
      <ProjectStructure>
        <Object Name="SAFEX_FSoE_Diagnosis_1V05" ObjectId="db8cc508-ad9a-47cb-aeac-be73b1142a4c" />
      </ProjectStructure>
    </data>
  </addData>
</project>