﻿<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://www.plcopen.org/xml/tc6_0200">
  <fileHeader companyName="" productName="IndraLogic" productVersion="indralogic" creationDateTime="2023-10-25T15:27:37.2781441" />
  <contentHeader name="IndraLogic.project" modificationDateTime="2023-10-25T13:51:22.9191571">
    <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_Diagnosis_1V03" pouType="functionBlock">
        <interface>
          <inputVars>
            <variable name="FunctionalOutput">
              <type>
                <pointer>
                  <baseType>
                    <array>
                      <dimension lower="0" upper="4" />
                      <baseType>
                        <BYTE />
                      </baseType>
                    </array>
                  </baseType>
                </pointer>
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Adress of beginning Functional Outputs of SAFEX_C.1x, e.g. FunctionalOutput:= ADR(%IB40),</xhtml>
              </documentation>
            </variable>
            <variable name="FieldbusType">
              <type>
                <BOOL />
              </type>
              <initialValue>
                <simpleValue value="FALSE" />
              </initialValue>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Ethercat = false,  ProfiNet = true</xhtml>
              </documentation>
            </variable>
          </inputVars>
          <outputVars>
            <variable name="Mode">
              <type>
                <BYTE />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> includes the power up sequence 1=STARTUP; 2=SENDCONFIG; 3=STARTUP BUS; 4=RUN; 5=STOP; 6=ERROR; 7=ALARM; 8=RUN INTERN</xhtml>
              </documentation>
            </variable>
            <variable name="FatalError">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> importants Bits also as Bools</xhtml>
              </documentation>
            </variable>
            <variable name="Alarm">
              <type>
                <BOOL />
              </type>
            </variable>
            <variable name="RunIntern">
              <type>
                <BOOL />
              </type>
            </variable>
            <variable name="Run">
              <type>
                <BOOL />
              </type>
            </variable>
            <variable name="LiveCounter">
              <type>
                <BYTE />
              </type>
            </variable>
            <variable name="ErrorCode">
              <type>
                <INT />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Errorcode </xhtml>
              </documentation>
            </variable>
            <variable name="AdditionalErrorDiag">
              <type>
                <DWORD />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Bit0 = Pin I0.0 ............ Bit31 = Pin I0.31 in case of SAFEX-C.12 Bit16 - Bit31 has no meaning because just 16 Inputs are availible</xhtml>
              </documentation>
            </variable>
            <variable name="AdditionalErrorInfo">
              <type>
                <string />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> Information which Pins are in failure as string</xhtml>
              </documentation>
            </variable>
            <variable name="CommunicationOK">
              <type>
                <BOOL />
              </type>
              <documentation>
                <xhtml xmlns="http://www.w3.org/1999/xhtml"> must be TRUE when communication is OK</xhtml>
              </documentation>
            </variable>
          </outputVars>
          <localVars>
            <variable name="arFunctionalOutput">
              <type>
                <array>
                  <dimension lower="0" upper="4" />
                  <baseType>
                    <BYTE />
                  </baseType>
                </array>
              </type>
            </variable>
            <variable name="AdditionalError">
              <type>
                <BOOL />
              </type>
            </variable>
            <variable name="wTempHigh">
              <type>
                <WORD />
              </type>
            </variable>
            <variable name="TOF_LiveCounter">
              <type>
                <derived name="TOF" />
              </type>
            </variable>
            <variable name="byLiveCounterOld">
              <type>
                <BYTE />
              </type>
            </variable>
            <variable name="bLiveBit">
              <type>
                <BOOL />
              </type>
            </variable>
            <variable name="byOffset">
              <type>
                <BYTE />
              </type>
            </variable>
            <variable name="dwAdditionalDiagnostic">
              <type>
                <DWORD />
              </type>
            </variable>
            <variable name="pAdditionalDiagnostic">
              <type>
                <pointer>
                  <baseType>
                    <DWORD />
                  </baseType>
                </pointer>
              </type>
            </variable>
            <variable name="dwMask">
              <type>
                <DWORD />
              </type>
              <initialValue>
                <simpleValue value="1" />
              </initialValue>
            </variable>
            <variable name="i">
              <type>
                <INT />
              </type>
            </variable>
            <variable name="strPins">
              <type>
                <string />
              </type>
              <initialValue>
                <simpleValue value="', Pin I0.'" />
              </initialValue>
            </variable>
            <variable name="strResult">
              <type>
                <string />
              </type>
            </variable>
          </localVars>
          <documentation>
            <xhtml xmlns="http://www.w3.org/1999/xhtml">---------------------------------------------------------------------------------------------------------------------------------------
Short description:
This Functionblock reads the diagnostic information from ctrlX SAFETY SAFEX-C.1x and monitored status and errors. 
Version: 1.03	
Name: 	DC-AE/STS2 Dirk Asendorf
Date:	2023.10.25	
Company:	Bosch-Rexroth AG
---------------------------------------------------------------------------------------------------------------------------------------
Target: 	XMxx (ProfiNet), ctrlX CORE (EtherCat, Profinet)
Needs: 	SAFEX Firmware &gt; 1.0.1.28 / FPGA 211
			ctrlx SAFETY Engineering &gt; 1.7.1.8239
			ProfiNet 
History
---------------------------------------------------------------------------------------------------------------------------------------
Dirk Asendorf | 25.10.2023 | Version 1V03
- reduce the Array declaration  FunctionalOutput to just 5 Bytes: POINTER TO ARRAY[0..4] OF BYTE because a conflict with variables in I/O Mapping at
  16Bytes from SAFEX-C
---------------------------------------------------------------------------------------------------------------------------------------
Dirk Asendorf | 19.09.2023 | Version 1V02
 - Remove Output Stop, because if the SAFEX is stopped no no new datas arrived
 - Change datatvpe of ErrorCode to int
 - In case of no communication set all outputs to false
---------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------------
Dirk Asendorf | 16.11.2022 | Version 1V01
Included now a additional error diagnostic for time monitored inputs

---------------------------------------------------------------------------------------------------------------------------------------
Functional Description:
</xhtml>
          </documentation>
        </interface>
        <body>
          <ST>
            <xhtml xmlns="http://www.w3.org/1999/xhtml">IF FieldbusType THEN
	byOffset:= 12;	// ProfiNet
ELSE
	byOffset:= 19;	// Ethercat
END_IF

arFunctionalOutput:= FunctionalOutput^;
 

pAdditionalDiagnostic:= FunctionalOutput + byOffset;
dwAdditionalDiagnostic:= pAdditionalDiagnostic^;

IF (arFunctionalOutput[1] = 1) AND (arFunctionalOutput[2] = 0)  THEN
	AdditionalError:= TRUE;
	AdditionalErrorDiag:= dwAdditionalDiagnostic;
ELSE
	AdditionalError:= FALSE;
	AdditionalErrorDiag:= 0;
END_IF



Mode:= 			arFunctionalOutput[0] AND 2#00001111;
LiveCounter:=	arFunctionalOutput[0] AND 2#11100000;

IF (byLiveCounterOld &lt;&gt; LiveCounter) THEN
	bLiveBit:= TRUE;
ELSE
	bLiveBit:= FALSE;
END_IF

byLiveCounterOld:= LiveCounter;

IF Mode = 4 AND CommunicationOK THEN
	Run:= TRUE;
ELSE
	Run:= FALSE;
END_IF

IF Mode = 6 AND CommunicationOK  THEN
	FatalError:= TRUE;
ELSE
	FatalError:= FALSE;
END_IF

IF Mode = 7 AND CommunicationOK  THEN
	Alarm:= TRUE;
ELSE
	Alarm:= FALSE;
END_IF

IF Mode = 8 AND CommunicationOK  THEN
	RunIntern:= TRUE;
ELSE
	RunIntern:= FALSE;				
END_IF

IF Alarm THEN
	;
END_IF


wTempHigh:= arFunctionalOutput[4];	
ErrorCode:= arFunctionalOutput[3] OR SHL(wTempHigh,8);

IF AdditionalError THEN
	dwMask:= 1;
	strResult:='Time Monitored Input ';	
	FOR i:= 0 TO 31 DO
		IF (dwAdditionalDiagnostic AND dwMask) = dwMask THEN
			strResult:= concat(strResult, concat(strPins,INT_TO_STRING(i)));
		END_IF
		
		dwMask:= SHL(dwMask,1);
		
	END_FOR
ELSE
	strResult:='';	
END_IF
	
AdditionalErrorInfo:= strResult;	

TOF_LiveCounter(IN:= bLiveBit, PT:= T#200MS, Q=&gt; CommunicationOK, ET=&gt; );</xhtml>
          </ST>
        </body>
        <addData>
          <data name="http://www.3s-software.com/plcopenxml/objectid" handleUnknown="discard">
            <ObjectId>6b1388dc-0cac-4b4b-bb9b-3ec999e59046</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_Diagnosis_1V03" ObjectId="6b1388dc-0cac-4b4b-bb9b-3ec999e59046" />
      </ProjectStructure>
    </data>
  </addData>
</project>