// EHPASTIdent02_ProToF.inc
// Description: Identification Check for PROFIBUS PA - SIMATIC PDM >= V6.00
// Copyright (C) Siemens AG (1999-2004). All Rights Reserved.
// $Revision:   2.00  $
// $Date: Apr 27 2005 $


#ifndef SIPASTIDENT02_INC_INCLUDED
#define SIPASTIDENT02_INC_INCLUDED

#include "Manufacturer_List.h"



#define	ID_CHECK_ABORT				0
#define	ID_CHECK_SUCCESS			1

#define	ID_CHECK_WRITABLE			0
#define	ID_CHECK_WRITE_PROTECTED	1

#define	ID_MAX_BLOCK_NUM			32

#define	ID_FC_ERROR					3000




// enable WriteProtection check
#define ENABLE_WRITEPROTECTIONCHECK

// Additional ITEMS for Options Menu 
// #define DEBUG_OPTION1	OfflineDialog_DebugDeviceIdentification





#define VALID_ID_TRANS_BLOCK(num)			\
		IF (num < id_num_of_trans_blocks)	\
		{									\
			TRUE;							\
		}									\
		ELSE								\
		{									\
			FALSE;							\
		}

#define VALID_ID_FUNC_BLOCK(num)			\
		IF (num < id_num_of_func_blocks)	\
		{									\
			TRUE;							\
		}									\
		ELSE								\
		{									\
			FALSE;							\
		}





#define READ_DEVICE_IDENTIFICATION										\
		iResult = ID_FC_ERROR;											\
		while (iResult >= ID_FC_ERROR)									\
		{																\
			iResult = ReadCommand(read_id_phys_blk);					\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(read_id_phys_manufacturer_id);	\
			if (iResult < ID_FC_ERROR)									\
				iResult = ReadCommand(read_id_trans_blk);				\
			if (iResult < ID_FC_ERROR)									\
				iResult = ReadCommand(read_id_phys_serial_num);			\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(read_id_phys_tag_desc);			\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(read_id_phys_software_rev);		\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(read_id_phys_device_id);			\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(PHYS_BlkDeviceRevision_1);		\
			if ( iResult < ID_FC_ERROR )								\
				iResult = ReadCommand(PHYS_BlkDeviceRevisionCompatibility_1);\
																		\
			if (iResult >= ID_FC_ERROR)									\
			{															\
				if (id_Method_In_SilentMode == 0)						\
					ACKNOWLEDGE([IdentCheckCommProblem]);				\
				else													\
					process_abort();									\
			}															\
		}																\


#define TRACE_DEVICE_IDENTIFICATION																				\
		sz0 = id_phys_software_rev;																				\
		sz1 = id_phys_serial_num;																				\
		sz2 = id_phys_tag_desc;																					\
		sz3 = id_phys_device_id;																				\
		get_variable_string(id_phys_manufacturer_id, szManufacturer) ;											\
		szTrace = "Device found: "																				\
					+ sz3																						\
					+ "; PhysParentClass = "			+ itoa(ivar_value(id_phys_blk_parent_class))			\
					+ "; Profile rev = "				+ itoa(ivar_value(id_phys_blk_profile_rev) / 256)		\
					+ "."								+ itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		\
					+ "; TransParentClass = "			+ itoa(ivar_value(id_trans_blk_parent_class))			\
					+ "; Software revision = "			+ sz0													\
					+ "; Manufacturer = "				+ itoa(ivar_value(id_phys_manufacturer_id))				\
					+ "(" + szManufacturer + ")"																\
					+ "; SerialNumber =  "				+ sz1													\
					+ "; TAG = "						+ sz2;													\
		_TRACE(szTrace);								


#define FUNCTION_CHECK_DEVICE_CLASS														\
		if ((id_phys_blk_parent_class	!= ivar_value(PHYS_BlkParentClass_1))	||		\
			(id_trans_blk_parent_class	!= ivar_value(id_trans_blk_parent_class)))		\
		{																				\
			char szPhysBlkClass[] ;														\
			char szTransBlkClass[] ;													\
			char szIdPhysBlkClass[] ;													\
			char szIdTransBlkClass[] ;													\
			get_variable_string(PHYS_BlkParentClass_1, szPhysBlkClass) ;				\
			get_variable_string(id_trans_blk_parent_class, szTransBlkClass) ;				\
			get_variable_string(id_phys_blk_parent_class, szIdPhysBlkClass) ;			\
			get_variable_string(id_trans_blk_parent_class, szIdTransBlkClass) ;			\
																						\
			sz = [DeviceTypeMismatch] + "\r\n\r\n"										\
			+ [device_expected] + "\r\n    "											\
			+ szPhysBlkClass + ", "														\
			+ szTransBlkClass															\
			+ "\r\n\r\n"																\
			+ [device_found] + "\r\n    "												\
			+ szIdPhysBlkClass + ", "													\
			+ szIdTransBlkClass + "\r\n    "											\
			+ [phys_device_man_id] + " = "												\
			+ szManufacturer + "\r\n    "												\
			+ [phys_device_id] + " = "													\
			+ id_phys_device_id															\
			+ "\r\n    "																\
			+ [blk_profile_rev]	+ " = "													\
			+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 							\
			+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)			 		\
			+ "\r\n    "																\
			+ [tag_desc] + " = "														\
			+ id_phys_tag_desc															\
			+ "\r\n\r\n"																\
			+ [no_communication_possible] ;												\
																						\
			if( id_Method_In_SilentMode == 0 )											\
			{																			\
				PUT_MESSAGE(sz);														\
			}																			\
			else																		\
			{																			\
				LOG_MESSAGE(0, sz);									\
			}																			\
																						\
			id_status = ID_CHECK_ABORT;													\
		}



#define FUNCTION_CHECK_SERIAL_NUMBER													\
	sz1 = strtrim(sz1);																	\
	if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))						\
	{																					\
		if( (strtrim(id_phys_serial_num) != sz1) || (strtrim(id_phys_device_id) != strtrim(PHYS_DeviceId_1)) )			\
		{																				\
			sz = [mismatch_identcheck] + "\r\n    "										\
			+ [phys_device_ser_num] + "\r\n\r\n"										\
			+ [device_expected] + "\r\n    "											\
			+ [phys_device_id] + " = "													\
			+ PHYS_DeviceId_1															\
			+ "\r\n    "																\
			+ [phys_device_ser_num] + " = "												\
			+ sz1																		\
			+ "\r\n\r\n"																\
			+ [device_found] + "\r\n    "												\
			+ [phys_device_man_id] + " = "												\
			+ szManufacturer + "\r\n    "												\
			+ [phys_device_id] + " = "													\
			+ id_phys_device_id															\
			+ "\r\n    "																\
			+ [phys_device_ser_num] + " = "												\
			+ id_phys_serial_num														\
			+ "\r\n    "																\
			+ [tag_desc] + " = "														\
			+ id_phys_tag_desc															\
			+ "\r\n\r\n"																\
			+ [continue_anyway] ;														\
																						\
			if( id_Method_In_SilentMode == 0 )											\
			{																			\
				ACKNOWLEDGE(sz);														\
			}																			\
			else																		\
			{																			\
				LOG_MESSAGE(0, sz);	\
			}																			\
		}																				\
	}																					




#define FUNCTION_CHECK_PROFILE_REV													\
		if( id_phys_blk_profile_rev != CHECK_PROFILE_REV )							\
		{																			\
			get_variable_string(id_phys_manufacturer_id, szManufacturer) ;			\
			sz = [mismatch_identcheck] + "\r\n    "									\
			+ [blk_profile_rev] + "\r\n\r\n"										\
			+ [device_expected] + "\r\n    "										\
			+ [blk_profile_rev] + " = "												\
			+ itoa(CHECK_PROFILE_REV / 256) 										\
			+ "." + itoa(CHECK_PROFILE_REV & 0xff)									\
			+ "\r\n\r\n"															\
			+ [device_found] + "\r\n    "											\
			+ [phys_device_man_id] + " = "											\
			+ szManufacturer + "\r\n    "											\
			+ [phys_device_id] + " = "												\
			+ id_phys_device_id														\
			+ "\r\n    "															\
			+ [blk_profile_rev]	+ " = "												\
			+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 						\
			+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		 		\
			+ "\r\n    "															\
			+ [tag_desc] + " = "													\
			+ id_phys_tag_desc														\
			+ "\r\n\r\n"															\
			+ [no_communication_possible] ;											\
																					\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, sz);	\
			}																		\
																					\
			process_abort() ;														\
		}




#define FUNCTION_CHECK_MANUFACTURER													\
		if( (id_phys_manufacturer_id != DEFAULT_MANUFACTURER_ID)					\
		&&  (DEFAULT_MANUFACTURER_ID != 252) )										\
		{																			\
			get_variable_string(id_phys_manufacturer_id, szManufacturer) ;			\
			id_phys_manufacturer_id_required = DEFAULT_MANUFACTURER_ID ;			\
			get_variable_string(id_phys_manufacturer_id_required, szManufacturerRequired) ;	\
			sz = [DeviceTypeMismatch] + "\r\n\r\n"									\
			+ [device_expected] + "\r\n    "										\
			+ [phys_device_man_id] + " = "											\
			+ szManufacturerRequired												\
			+ "\r\n\r\n"															\
			+ [device_found] + "\r\n    "											\
			+ [phys_device_man_id] + " = "											\
			+ szManufacturer + "\r\n    "											\
			+ [phys_device_id] + " = "												\
			+ id_phys_device_id														\
			+ "\r\n    "															\
			+ [blk_profile_rev]	+ " = "												\
			+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 						\
			+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		 		\
			+ "\r\n    "															\
			+ [tag_desc] + " = "													\
			+ id_phys_tag_desc														\
			+ "\r\n\r\n"															\
			+ [no_communication_possible] ;											\
																					\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, sz);								\
			}																		\
																					\
			process_abort() ;														\
		}




#define FUNCTION_CHECK_DEVICE_TYPE													\
		if( strtrim(id_phys_device_id) != strtrim(CHECK_DEVICE_TYPE) )				\
		{																			\
			get_variable_string(id_phys_manufacturer_id, szManufacturer) ;			\
			sz = [mismatch_identcheck] + "\r\n    "									\
			+ [phys_device_id] + "\r\n\r\n"											\
			+ [device_found] + "\r\n    "											\
			+ [phys_device_man_id] + " = "											\
			+ szManufacturer + "\r\n    "											\
			+ [phys_device_id] + " = "												\
			+ id_phys_device_id														\
			+ "\r\n    "															\
			+ [blk_profile_rev]	+ " = "												\
			+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 						\
			+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		 		\
			+ "\r\n    "															\
			+ [phys_software_revision] + " = "										\
			+ id_phys_software_rev													\
			+ "\r\n    "															\
			+ [tag_desc] + " = "													\
			+ id_phys_tag_desc														\
			+ "\r\n\r\n"															\
			+ [device_expected] + "\r\n    "										\
			+ [phys_device_id] + " = "												\
			+ CHECK_DEVICE_TYPE														\
			+ "\r\n    "															\
			+ "\r\n\r\n"															\
			+ [no_communication_possible] ;											\
																					\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, sz);	\
			}																		\
																					\
			process_abort() ;														\
		}																			\


#ifndef FUNCTION_CHECK_SOFTWARE_VERSION
#define FUNCTION_CHECK_SOFTWARE_VERSION												\
		if( strtrim(id_phys_software_rev) != strtrim(CHECK_SOFTWARE_VERSION) )		\
		{																			\
			sz = [mismatch_identcheck] + "\r\n    "									\
			+ [phys_software_revision] + "\r\n\r\n"									\
			+ [device_expected] + "\r\n    "										\
			+ [phys_software_revision] + " = "										\
			+ CHECK_SOFTWARE_VERSION												\
			+ "\r\n\r\n"															\
			+ [device_found] + "\r\n    "											\
			+ [phys_device_man_id] + " = "											\
			+ szManufacturer + "\r\n    "											\
			+ [phys_device_id] + " = "												\
			+ id_phys_device_id														\
			+ "\r\n    "															\
			+ [blk_profile_rev]	+ " = "												\
			+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 						\
			+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		 		\
			+ "\r\n    "															\
			+ [phys_software_revision] + " = "										\
			+ id_phys_software_rev													\
			+ "\r\n    "															\
			+ [tag_desc] + " = "													\
			+ id_phys_tag_desc														\
			+ "\r\n\r\n"															\
			+ [no_communication_possible] ;											\
																					\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, sz);	\
			}																		\
																					\
			process_abort() ;														\
		}
#endif

#define FUNCTION_CHECK_DEVICE_REVISION												\
		if (( PHYS_BlkDeviceRevision_1 < CHECK_DEVICE_REVISION ) || ( PHYS_BlkDeviceRevisionCompatibility_1 > CHECK_DEVICE_REVISION ))						\
		{																			\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				sz = [mismatch_identcheck] + "\r\n    "								\
				+ "Device Revision" + "\r\n\r\n"									\
				+ [device_expected] + "\r\n    "									\
				+ "Device Revision" + " >= "										\
				+ CHECK_DEVICE_REVISION												\
				+ "\r\n"															\
				+ "Device Revision Compatibility" + " <= "							\
				+ CHECK_DEVICE_REVISION												\
				+ "\r\n\r\n"														\
				+ [device_found] + "\r\n    "										\
				+ [phys_device_man_id] + " = "										\
				+ szManufacturer + "\r\n    "										\
				+ [phys_device_id] + " = "											\
				+ id_phys_device_id													\
				+ "\r\n    "														\
				+ [blk_profile_rev]	+ " = "											\
				+ itoa(ivar_value(id_phys_blk_profile_rev) / 256) 					\
				+ "." + itoa(ivar_value(id_phys_blk_profile_rev) & 0xff)		 	\
				+ "\r\n    "														\
  			+ [phys_software_revision] + " = "										\
	  		+ id_phys_software_rev													\
	  		+ "\r\n    "															\
				+ "Device Revision" + " = "											\
				+ PHYS_BlkDeviceRevision_1											\
				+ "\r\n    "														\
				+ "Device Revision Compatibility" + " = "							\
				+ PHYS_BlkDeviceRevisionCompatibility_1								\
				+ "\r\n    "														\
				+ [tag_desc] + " = "												\
				+ id_phys_tag_desc													\
				+ "\r\n\r\n"														\
				+ [no_communication_possible] ;										\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, [mismatch_identcheck] + " " + "Device Revision");	\
			}																		\
																					\
			process_abort() ;														\
		}


///////////////////////////////////////////////////////////////////////
// IdentCheck DEBUG Dialog

#ifdef DEBUG_OPTION1

MENU OfflineDialog_DebugDeviceIdentification
{
	LABEL	"Test_Identification";
	ITEMS
	{
		Page_DebugDeviceIdentification,
		Page_DebugWriteProtection,
		Page_DebugRevisionCounter
	}
}



MENU Page_DebugDeviceIdentification
{
	LABEL	"Test_Identification";
	ITEMS
	{
		id_firstCheck,
		ret_CheckDeviceIdentification,
		Group_IdentCheck_dd,
		Group_IdentCheck_device,
		std_CheckDeviceIdentification,
		std_CheckDeviceIdentificationUpload,
		std_CheckDeviceIdentificationDownload
	}
}



MENU Page_DebugWriteProtection
{
	LABEL	"Write Protection";
	ITEMS
	{
		ret_CheckWriteProtection,
		std_CheckWriteProtection
	}
}


MENU Page_DebugRevisionCounter
{
	LABEL	"Revision Counter";
	ITEMS
	{
		id_num_of_phys_blocks,
		id_num_of_trans_blocks,
		id_num_of_func_blocks,
		id_phys_st_rev,
		Group_IdentCheck_TB_RevCounters,
		Group_IdentCheck_FB_RevCounters,
		std_LoadRevisionCounters,
		std_GetConfigChangedState,
		ret_ConfigChangedState		
	}
}



MENU Group_IdentCheck_dd
{
	LABEL "Offline data";
	ITEMS
	{
		PHYS_TagDesc_1			(READ_ONLY),
		PHYS_BlkParentClass_1,
		PHYS_BlkProfileRev_1,
		id_trans_blk_parent_class, 
		id_trans_blk_class
	}
}



MENU Group_IdentCheck_device
{
	LABEL "Device";
	ITEMS
	{
		id_phys_tag_desc			(READ_ONLY),	
		id_phys_blk_parent_class,
		id_phys_blk_profile_rev,
		id_trans_blk_parent_class, 
		id_trans_blk_class,
		id_phys_serial_num
	}
}



MENU Group_IdentCheck_TB_RevCounters
{
	LABEL		"Transducer Block";
	ITEMS
	{
		id_trans_st_rev
	}
}



MENU Group_IdentCheck_FB_RevCounters
{
	LABEL		"Function Block";
	ITEMS
	{
		id_func_st_rev
	}
}

#endif



///////////////////////////////////////////////////////////////////////
// ID - Checking Variables

VARIABLE	ret_CheckDeviceIdentification
{
	LABEL		"ret_CheckDeviceIdentification";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	ID_CHECK_ABORT;
	}
	HANDLING	READ;
}

VARIABLE	ret_CheckTAGIdentity
{
	LABEL		"ret_CheckTAGIdentity";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	1;
	}
	HANDLING	READ;
}

VARIABLE	ret_CheckWriteProtection
{
	LABEL		"Write Protection Result";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	ID_CHECK_WRITABLE;
	}
	HANDLING	READ;
}

VARIABLE id_Method_In_SilentMode
{
    LABEL		"Method in Silent Mode";
    CLASS		LOCAL;
    TYPE		ENUMERATED
    {
	    DEFAULT_VALUE	0x00;	
	    { 0x00, [no]	},
        { 0x01, [yes]	}
	}
    HANDLING	READ;
}

VARIABLE	id_firstCheck
{
	LABEL		"id_firstCheck";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	1;
	}
	HANDLING	READ;
}

VARIABLE	id_status
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	ID_CHECK_ABORT;
	}
	HANDLING	READ;
}

VARIABLE	id_dummy_float
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		FLOAT;
	HANDLING	READ;
}

VARIABLE	id_dummy_dword
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (4);
	HANDLING	READ;
}

VARIABLE	id_dummy_word
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (2);
	HANDLING	READ;
}

VARIABLE	id_dummy_byte
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1);
	HANDLING	READ;
}

#if _PDM_ < 700
VARIABLE	id_dummy_array
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		ASCII (200);
	HANDLING	READ;
}
#endif

VARIABLE id_phys_manufacturer_id
{
	LABEL		[phys_device_man_id];
	HELP		[phys_device_man_id_help];
	CLASS		LOCAL ;
	TYPE		ENUMERATED (2)
	{
#ifdef DEFAULT_MANUFACTURER_ID
		DEFAULT_VALUE DEFAULT_MANUFACTURER_ID ;
#endif
		MANUFACTURER_LIST
	}
	HANDLING	READ;
}


id_phys_manufacturer_id_required LIKE VARIABLE id_phys_manufacturer_id
{
}

VARIABLE id_phys_device_id
{
	LABEL		[phys_device_id];
	CLASS		LOCAL ;
	TYPE		ASCII (16) ;
	HANDLING	READ;
}



///////////////////////////////////////////////////////////////////////
// Block	Directory

VARIABLE	id_block_num
{
	LABEL		"Block Number";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (4)
	{
		DEFAULT_VALUE	1;
	}
	HANDLING	READ;
}



VARIABLE	id_num_of_phys_blocks
{
	LABEL		"Number of Physical Blocks";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (2)
	{
		DEFAULT_VALUE	0;
	}
	HANDLING	READ;
}



id_num_of_trans_blocks	LIKE VARIABLE	id_num_of_phys_blocks
{
	REDEFINE LABEL	"Number of Transducer Blocks";
}



id_num_of_func_blocks	LIKE VARIABLE	id_num_of_phys_blocks
{
	REDEFINE LABEL	"Number of Function Blocks";
}



///////////////////////////////////////////////////////////////////////
// Physical Block

BLOCK id_physical_block
{
	TYPE	PHYSICAL;
	NUMBER	1;
}



id_phys_blk_parent_class		LIKE VARIABLE	PHYS_BlkParentClass_1
{
	REDEFINE	CLASS	LOCAL;
	REDEFINE TYPE ENUMERATED(1)
	{
		{	1,	[phys_blk_parent_class_TRANSMITTER]	},
		{	2,	[phys_blk_parent_class_ACTUATOR]	},
		{   3,  [phys_blk_parent_class_BIN_IO]		},
		{	4,	[phys_blk_parent_class_CONTR]},
		{	5,	[phys_blk_parent_class_ANALYSER]}
	}
}



id_phys_blk_profile_rev			LIKE VARIABLE	PHYS_BlkProfileRev_1
{
	REDEFINE	CLASS	LOCAL;
	DELETE PURPOSE;
}



VARIABLE id_phys_software_rev
{
	LABEL		[phys_software_revision];
	HELP		[phys_software_revision_help];
	CLASS		LOCAL;
	TYPE		ASCII (16)
	{
		DEFAULT_VALUE	"1";
	}
	HANDLING	READ;
}



VARIABLE phys_write_locking
{
	LABEL		"phys_write_locking";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (2)
	{
		DEFAULT_VALUE	0;
	}
	HANDLING	READ;
}



VARIABLE id_phys_st_rev_online
{
	LABEL		[st_rev];
	HELP		[st_rev_help];
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (2)
	{
		DEFAULT_VALUE	0;
	}
	HANDLING	READ;
}



id_phys_st_rev					LIKE VARIABLE	id_phys_st_rev_online
{
	REDEFINE LABEL	"PB";
}



VARIABLE id_phys_tag_desc
{
	LABEL		[tag_desc];		
	HELP		[tag_desc_help];
	CLASS	LOCAL;
	TYPE		ASCII (32);
	HANDLING	READ & WRITE;
}



VARIABLE id_phys_serial_num
{
	LABEL		[phys_serial_num];
	HELP		[phys_device_ser_num_help];
	CLASS		LOCAL;
	TYPE		ASCII (16);
	HANDLING	READ;
}



///////////////////////////////////////////////////////////////////////
// TRANSDUCER BLOCK

BLOCK id_transducer_block
{
	TYPE	TRANSDUCER;
	NUMBER	id_block_num;
}



VARIABLE id_trans_blk_parent_class
{
	LABEL		"trans1_blk_parent_class";
	CLASS		LOCAL;
	TYPE ENUMERATED
	{
		{	1,	[trans_blk_parent_class_PRES]		},
		{	2,	[trans_blk_parent_class_TEMP]		},
		{	3,	[trans_blk_parent_class_FLOW]		},
		{	4,	[trans_blk_parent_class_LEVEL]		},
		{   5,  [trans_blk_parent_class_VALVE]		},
		{	7,	[trans_blk_parent_class_ANALYSIS]	},
		
		{	240, [block_class_manufacturer_specific_240]	},		
		{	241, [block_class_manufacturer_specific_241]	},
		{	242, [block_class_manufacturer_specific_242]	},
		{	243, [block_class_manufacturer_specific_243]	},
		{	244, [block_class_manufacturer_specific_244]	},
		{	245, [block_class_manufacturer_specific_245]	},
		{	246, [block_class_manufacturer_specific_246]	},
		{	247, [block_class_manufacturer_specific_247]	},
		{	248, [block_class_manufacturer_specific_248]	},
		{	249, [block_class_manufacturer_specific_249]	}
	}
	HANDLING	READ;
}


VARIABLE id_trans_blk_class
{
	LABEL		"trans1_blk_class";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1);
	HANDLING	READ;
}



id_trans_st_rev_online	LIKE VARIABLE	id_phys_st_rev_online
{											
	REDEFINE LABEL		"TB" + (ARRAY_INDEX+1);
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (ARRAY_INDEX)
}											
											


ARRAY  id_trans_st_rev
{
	NUMBER_OF_ELEMENTS  ID_MAX_BLOCK_NUM;
	TYPE id_trans_st_rev_online;
}



///////////////////////////////////////////////////////////////////////
// FUNCTION BLOCK

BLOCK id_function_block
{
	TYPE	FUNCTION;
	NUMBER	id_block_num;
}



VARIABLE id_func_blk_parent_class
{
	LABEL		[blk_parent_class];
	HELP		[func_blk_parent_class_help];
	CLASS		CONTAINED;
	TYPE		ENUMERATED(1)
	{
		{	1,	[func_blk_parent_class_INPUT]		}
		{	2,	[func_blk_parent_class_OUTPUT]		}
		{	3, 	[func_blk_parent_class_CONTR]		}
		{	4, 	[func_blk_parent_class_ADV_CONTR]	}
		{	5,	[func_blk_parent_class_CALC]		}
		{	6,	[func_blk_parent_class_AUX]			}
	}
	HANDLING	READ;
}



VARIABLE id_func_blk_class
{
	LABEL		[blk_class];
	HELP		[func_blk_class_help];
	CLASS		CONTAINED;
	TYPE		ENUMERATED(1)
	{
		SELECT (id_func_blk_parent_class)
		{
			CASE	1:		// PARENT CLASS: INPUT
				{	1,	[func_blk_class_AI]			}
				{	2,	[func_blk_class_DI]			}
			CASE	2:		// PARENT CLASS: OUTPUT
				{	1,	[func_blk_class_AO]			}
				{	2,	[func_blk_class_DO]			}
			CASE	5:		// PARENT CLASS: CALCULATION
				{	8,	[func_blk_class_TOTAL]		}
			CASE	6:		// PARENT CLASS: AUXILARY
				{	2,	[func_blk_class_SAMPLE]		}
				{	3,	[func_blk_class_LOGBOOK]	}
		}
	}
	HANDLING	READ;
}

id_func_st_rev_online			LIKE VARIABLE	id_phys_st_rev_online
{											
	REDEFINE LABEL		"FB" + (ARRAY_INDEX+1);
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (ARRAY_INDEX)
}											
	
ARRAY  id_func_st_rev
{
	NUMBER_OF_ELEMENTS  ID_MAX_BLOCK_NUM;
	TYPE id_func_st_rev_online;
}



///////////////////////////////////////////////////////////////////////

METHOD	std_CheckWriteProtection
{
	LABEL		"std_CheckWriteProtection";
	CLASS		INPUT;
	ACCESS		OFFLINE;
	DEFINITION
	{
		ret_CheckWriteProtection = ID_CHECK_WRITABLE;

		_TRACE("std_CheckWriteProtection");
/*
		if( VARID(phys_write_locking) != 0 )
		{
			ReadCommand(read_phys_write_locking);
			_TRACE("phys_write_locking = " + itoa(ivar_value(phys_write_locking)));
			if( ivar_value(phys_write_locking) == 0 )
			{
				ret_CheckWriteProtection = ID_CHECK_WRITE_PROTECTED;
				if (id_Method_In_SilentMode == 0)
				{
					ACKNOWLEDGE([DeviceWriteProtected0]);
					ret_CheckWriteProtection = ID_CHECK_WRITABLE;
				}
				else
				{
					LOG_MESSAGE(0, [DeviceWriteProtected0]) ;
				}
			}
		}
*/
	}
}



///////////////////////////////////////////////////////////////////////

METHOD	std_CheckDeviceIdentification
{
    LABEL       [CheckDeviceIdentification];
	HELP		[deviceidentification_help];
	CLASS		INPUT;
	ACCESS		OFFLINE;
	DEFINITION
	{
		char	szTrace[];
		char	sz[];
		char	sz0[];
		char	sz1[];
		char	sz2[];
		char	sz3[];
		char	szManufacturer[] ;
		char	szManufacturerRequired[] ;
		int		iResult;
		long	var_id[10];
		int iLen ;

		ret_CheckDeviceIdentification	= ID_CHECK_ABORT;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;

		_TRACE ("std_CheckDeviceIdentification");

		READ_DEVICE_IDENTIFICATION

		TRACE_DEVICE_IDENTIFICATION

		if (VARID(PHYS_DeviceSerNum_1) != 0)
		{
			sz1 = PHYS_DeviceSerNum_1;
		}
		else
		{
			sz1 = "???";
		}

		sz2 = PHYS_TagDesc_1;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(PHYS_BlkParentClass_1))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(id_trans_blk_parent_class))
					+ "; SerialNumber =  "				+ sz1 
					+ "; TAG = "						+ sz2;
			
		_TRACE(szTrace);

	FUNCTION_CHECK_DEVICE_CLASS

#ifdef DEFAULT_MANUFACTURER_ID	
	FUNCTION_CHECK_MANUFACTURER
#endif


#ifdef CHECK_DEVICE_TYPE
	FUNCTION_CHECK_DEVICE_TYPE
#endif

#ifdef CHECK_SOFTWARE_VERSION
	FUNCTION_CHECK_SOFTWARE_VERSION
#endif

#ifdef CHECK_DEVICE_REVISION
	FUNCTION_CHECK_DEVICE_REVISION
#endif

#ifdef CHECK_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------

		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if ((strtrim(id_phys_tag_desc) != strtrim(PHYS_TagDesc_1)) && (id_Method_In_SilentMode == 0))
			{
				var_id[0] = VARID(PHYS_TagDesc_1);
				var_id[1] = VARID(id_phys_tag_desc);
			
				if (id_Method_In_SilentMode == 0)
				{
					acknowledge([TagMismatch2], var_id);
				}
			}
		}

	//--- Serial Number auf Original-Variable schreiben, damit Meldung nicht wiederkommt  -------
		
		if (id_status == ID_CHECK_SUCCESS)
		{
			if (VARID(PHYS_DeviceSerNum_1) != 0)
			{
				PHYS_DeviceSerNum_1 = id_phys_serial_num;
			}

			PHYS_DeviceId_1 = id_phys_device_id;
		}

		id_Method_In_SilentMode	= 0;
		id_firstCheck			= 0;
		ret_CheckDeviceIdentification = id_status;
	}
}



///////////////////////////////////////////////////////////////////////

METHOD	std_CheckDeviceIdentificationUpload
{
    LABEL       [CheckDeviceIdentificationUpload];
	HELP		[deviceidentification_help];
	CLASS		INPUT;
	ACCESS		OFFLINE;
	DEFINITION
	{
		int		n;
		char	sz[];
		char	szTrace[];
		char	sz0[];
		char	sz1[];
		char	sz2[];
		char	sz3[];
		char	sz4[];
		char	sz5[];
		char	szManufacturer[] ;
		char	szManufacturerRequired[] ;
		int		iResult;
		int		iChoice;
		long	var_id[10];
		int 	iLen;
	

		ret_CheckDeviceIdentification	= ID_CHECK_ABORT;
		ret_CheckTAGIdentity			= 1;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;

		_TRACE("std_CheckDeviceIdentificationUpload");

		READ_DEVICE_IDENTIFICATION

		TRACE_DEVICE_IDENTIFICATION
		
		if (VARID(PHYS_DeviceSerNum_1) != 0)
		{
			sz1 = PHYS_DeviceSerNum_1;
		}
		else
		{
			sz1 = "???";
		}

		sz2 = PHYS_TagDesc_1;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(PHYS_BlkParentClass_1))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(id_trans_blk_parent_class))
					+ "; SerialNumber =  "				+ sz1 
					+ "; TAG = "						+ sz2;
			
		_TRACE(szTrace);

	FUNCTION_CHECK_DEVICE_CLASS

#ifdef DEFAULT_MANUFACTURER_ID	
	FUNCTION_CHECK_MANUFACTURER
#endif

#ifdef CHECK_DEVICE_TYPE
	FUNCTION_CHECK_DEVICE_TYPE
#endif

#ifdef CHECK_SOFTWARE_VERSION
	FUNCTION_CHECK_SOFTWARE_VERSION
#endif

#ifdef CHECK_DEVICE_REVISION
	FUNCTION_CHECK_DEVICE_REVISION
#endif

#ifdef CHECK_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------

		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if( strtrim(id_phys_tag_desc) != strtrim(PHYS_TagDesc_1) )
			{
				get_dictionary_string(cancel, sz1);
				get_dictionary_string(TagMismatch_keep_old, sz2);
				get_dictionary_string(TagMismatch_apply, sz3);

				sz4 = PHYS_TagDesc_1;
				sz5 = id_phys_tag_desc;
				sz0 = sz1
					+ ";"
					+ sz2
					+ " (" 
					+ sz4 
					+ ")" 
					+ ";" 
					+ sz3
					+ " (" 
					+ sz5 
					+ ")" ;
							
				if( id_Method_In_SilentMode == 0 )
				{
					iChoice = SELECT_FROM_LIST([TagMismatch], sz0);

					switch (iChoice)
					{
						case 1:						// keep old
							break;

						case 2:						// use new
							PHYS_TagDesc_1 = id_phys_tag_desc;
							break;

						default:					// abort
							id_status = ID_CHECK_ABORT;
							break;
					}
				}
				else
				{
					ret_CheckTAGIdentity			= 0;

					get_dictionary_string(TagMismatch, sz0);
					sz0 += " (" ;
					sz0 += sz4 ;
					sz0 += " / " ;
					sz0 += ")" ;
					_TRACE(sz0) ;

					LOG_MESSAGE (0, sz0);
				}
			}
		}

	//--- Check Revision Counter ------------------------------------------------
		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			ReadCommand(read_id_directory);
			if (id_num_of_trans_blocks > ID_MAX_BLOCK_NUM)
			{
				id_status = ID_CHECK_ABORT;
				if( id_Method_In_SilentMode == 0 )
				{
					ACKNOWLEDGE([TooManyTransducerBlocks]);
				}
				_ERROR("std_CheckDeviceIdentificationUpload: Too many TRANSDUCER Blocks (" + id_num_of_trans_blocks + ")");
				id_num_of_trans_blocks = ID_MAX_BLOCK_NUM;
			}

			if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
			{
				id_status = ID_CHECK_ABORT;
				if( id_Method_In_SilentMode == 0 )
				{
					ACKNOWLEDGE([TooManyFunctionBlocks]);
				}
				_ERROR("std_CheckDeviceIdentificationUpload: Too many FUNCTION Blocks (" + id_num_of_func_blocks + ")");
				id_num_of_func_blocks = ID_MAX_BLOCK_NUM;
			}
			
			if (id_status == ID_CHECK_SUCCESS)
			{
				//--- Physical Block: Revision Counter
				ReadCommand(read_id_phys_st_rev);
				if (id_phys_st_rev_online != ivar_value(id_phys_st_rev))
				{
					id_status = ID_CHECK_ABORT;

					if( id_Method_In_SilentMode == 0 )
					{
						ACKNOWLEDGE ([StaticRevisionMismatch]);
					}
				}

				//--- Transducer Block: Revision Counter
				if (id_status == ID_CHECK_SUCCESS)
				{
					for (n = 0; n < id_num_of_trans_blocks; n++)
					{
						id_block_num = n + 1;
						ReadCommand(read_id_trans_st_rev);
						if (id_trans_st_rev_online != ivar_value(id_trans_st_rev[n]))
						{
							id_status = ID_CHECK_ABORT;
							if( id_Method_In_SilentMode == 0 )
							{
								ACKNOWLEDGE ([StaticRevisionMismatch]);
							}
							break;
						}
					}
				}
					
				//--- Funciton Block: Revision Counter
				if (id_status == ID_CHECK_SUCCESS)
				{
					for (n = 0; n < id_num_of_func_blocks; n++)
					{
						id_block_num = n + 1;
						ReadCommand(read_id_func_st_rev);
						if (id_func_st_rev_online != ivar_value(id_func_st_rev[n]))
						{
							if( id_Method_In_SilentMode == 0 )
							{
								ACKNOWLEDGE ([StaticRevisionMismatch]);
							}

							break;
						}
					}
				}					
				id_status = ID_CHECK_SUCCESS;
			}
		}

	//--- Serial Number auf Original-Variable schreiben, damit Meldung nicht wiederkommt  -------
		
		if (id_status == ID_CHECK_SUCCESS)
		{
			if (VARID(PHYS_DeviceSerNum_1) != 0)
			{
				PHYS_DeviceSerNum_1 = id_phys_serial_num;
			}

			PHYS_DeviceId_1 = id_phys_device_id;
		}

		id_firstCheck = 0;
		ret_CheckDeviceIdentification = id_status;
	}
}



///////////////////////////////////////////////////////////////////////

METHOD	std_CheckDeviceIdentificationDownload
{
    LABEL       [CheckDeviceIdentificationDownload];
	HELP		[deviceidentification_help];
	CLASS		INPUT;
	ACCESS		OFFLINE;
	DEFINITION
	{
		char	sz[];
		char	szTrace[];
		char	sz0[];
		char	sz1[];
		char	sz2[];
		char	sz3[];
		char	szManufacturer[] ;
		char	szManufacturerRequired[] ;
		int		iResult;
		long	var_id[10];
		int 	iLen;

		ret_CheckDeviceIdentification	= ID_CHECK_ABORT;
		ret_CheckTAGIdentity			= 1;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;

		_TRACE("std_CheckDeviceIdentificationDownload -------------------------");

		READ_DEVICE_IDENTIFICATION

		TRACE_DEVICE_IDENTIFICATION
		
		if (VARID(PHYS_DeviceSerNum_1) != 0)
		{
			sz1 = PHYS_DeviceSerNum_1;
		}
		else
		{
			sz1 = "???";
		}

		sz2 = PHYS_TagDesc_1;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(PHYS_BlkParentClass_1))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(id_trans_blk_parent_class))
					+ "; SerialNumber =  "				+ sz1 
					+ "; TAG = "						+ sz2;
			
		_TRACE(szTrace);

	FUNCTION_CHECK_DEVICE_CLASS

#ifdef DEFAULT_MANUFACTURER_ID	
	FUNCTION_CHECK_MANUFACTURER
#endif

#ifdef CHECK_DEVICE_TYPE
	FUNCTION_CHECK_DEVICE_TYPE
#endif

#ifdef CHECK_SOFTWARE_VERSION
	FUNCTION_CHECK_SOFTWARE_VERSION
#endif

#ifdef CHECK_DEVICE_REVISION
	FUNCTION_CHECK_DEVICE_REVISION
#endif

#ifdef CHECK_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------

		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if( strtrim(id_phys_tag_desc) != strtrim(PHYS_TagDesc_1) )
			{
				ret_CheckTAGIdentity			= 0;
				var_id[0] = VARID(PHYS_TagDesc_1);
				var_id[1] = VARID(id_phys_tag_desc);
			
				if( id_Method_In_SilentMode == 0 )
				{
					acknowledge([TagMismatch2], var_id);
				}
				else
				{
					ret_CheckTAGIdentity			= 0;
				}
			}
		}

	//--- Serial Number auf Original-Variable schreiben, damit Meldung nicht wiederkommt  -------
		
		if (id_status == ID_CHECK_SUCCESS)
		{
			if (VARID(PHYS_DeviceSerNum_1) != 0)
			{
				PHYS_DeviceSerNum_1 = id_phys_serial_num;
			}
			
			PHYS_DeviceId_1 = id_phys_device_id;
		}

		id_firstCheck = 0;
		ret_CheckDeviceIdentification = id_status;
	}
}



///////////////////////////////////////////////////////////////////////

METHOD	std_LoadRevisionCounters
{
	LABEL		"std_LoadRevisionCounters";
	CLASS		INPUT;
	ACCESS		OFFLINE;
	DEFINITION
	{
		int		n;
		
		ret_CheckDeviceIdentification	= ID_CHECK_ABORT;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;
		
		_TRACE("std_LoadRevisionCounters") ;

		ReadCommand(read_id_directory);

		if (id_num_of_trans_blocks > ID_MAX_BLOCK_NUM)
		{
			id_status = ID_CHECK_ABORT;
			if( id_Method_In_SilentMode == 0 )
			{
				ACKNOWLEDGE([TooManyTransducerBlocks]);
			}
			_ERROR("std_LoadRevisionCounters: Too many TRANSDUCER Blocks (" + id_num_of_trans_blocks + ")");
			id_num_of_trans_blocks = ID_MAX_BLOCK_NUM;
		}

		if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
		{
			id_status = ID_CHECK_ABORT;
			if( id_Method_In_SilentMode == 0 )
			{
				ACKNOWLEDGE([TooManyFunctionBlocks]);
			}
			_ERROR("std_LoadRevisionCounters: Too many FUNCTION Blocks (" + id_num_of_func_blocks + ")");
			id_num_of_func_blocks = ID_MAX_BLOCK_NUM;
		}
		
		if (id_status == ID_CHECK_SUCCESS)
		{

		//--- Physical Block: Revision Counter --------------------------------------
			ReadCommand(read_id_phys_st_rev);
			id_phys_st_rev = id_phys_st_rev_online;

		//--- Transducer Block: Revision Counter ------------------------------------
			for (n = 0; n < ID_MAX_BLOCK_NUM; n++)
			{
				id_trans_st_rev[n] = id_trans_st_rev[n].DEFAULT_VALUE;
			}
			for (n = 0; n < id_num_of_trans_blocks; n++)
			{
				id_block_num = n + 1;
				ReadCommand(read_id_trans_st_rev);
				id_trans_st_rev[n] = id_trans_st_rev_online;
			}
		
		//--- Funciton Block: Revision Counter --------------------------------------
			for (n = 0; n < ID_MAX_BLOCK_NUM; n++)
			{
				id_func_st_rev[n] = id_func_st_rev[n].DEFAULT_VALUE;
			}
			for (n = 0; n < id_num_of_func_blocks; n++)
			{
				id_block_num = n + 1;
				ReadCommand(read_id_func_st_rev);
				id_func_st_rev[n] = id_func_st_rev_online;
			}
		}

		ret_CheckDeviceIdentification = id_status;
	}
}


/*******************************************************************************/
/*****	Configuration_Changed handling	****************************************/
/*******************************************************************************/

VARIABLE ret_ConfigChangedState
{
	LABEL		"ConfigChanged";
	CLASS		LOCAL;
	TYPE		UNSIGNED_INTEGER (1)
	{
		DEFAULT_VALUE	0 ;
	}
	HANDLING	READ & WRITE;
}


METHOD std_GetConfigChangedState
{
	LABEL		"std_GetConfigChangedState";
	ACCESS		OFFLINE;
	DEFINITION
	{
		int		n;

		_TRACE("std_GetConfigChangedState");
		
		ReadCommand(read_id_directory);

		ret_ConfigChangedState	= 0;
		
		if (id_num_of_trans_blocks > ID_MAX_BLOCK_NUM)
		{
			_ERROR("std_GetConfigChangedState: Too many TRANSDUCER Blocks (" + id_num_of_trans_blocks + ")");
			id_num_of_trans_blocks = ID_MAX_BLOCK_NUM;
		}

		if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
		{
			_ERROR("std_GetConfigChangedState: Too many FUNCTION Blocks (" + id_num_of_func_blocks + ")");
			id_num_of_func_blocks = ID_MAX_BLOCK_NUM;
		}

		//--- Physical Block: Revision Counter
		ReadCommand(read_id_phys_st_rev);
		if (id_phys_st_rev_online != id_phys_st_rev)
		{
			ret_ConfigChangedState = 1;
			_TRACE("std_GetConfigChangedState PB: Revision Counter different");
		}

		//--- Transducer Block: Revision Counter
		if (ret_ConfigChangedState == 0)
		{
			for (n = 0; n < id_num_of_trans_blocks; n++)
			{
				id_block_num = n + 1;
				ReadCommand(read_id_trans_st_rev);
				if (id_trans_st_rev_online != id_trans_st_rev[n])
				{
					ret_ConfigChangedState = 1;
					_TRACE("std_GetConfigChangedState TB" + id_block_num + ": Revision Counter different");
					break;
				}
			}
		}
			
		//--- Funciton Block: Revision Counter
		if (ret_ConfigChangedState == 0)
		{
			for (n = 0; n < id_num_of_func_blocks; n++)
			{
				id_block_num = n + 1;
				ReadCommand(read_id_func_st_rev);
				if (id_func_st_rev_online != id_func_st_rev[n])
				{
					ret_ConfigChangedState = 1;
					_TRACE("std_GetConfigChangedState FB" + id_block_num + ": Revision Counter different");
					break;
				}
			}
		}
		
		_TRACE("std_GetConfigChangedState: ret_ConfigChangedState = " + ret_ConfigChangedState);
	}
}


METHOD std_ResetConfigChangedState
{
	LABEL		"std_ResetConfigChangedState";
	ACCESS		OFFLINE;
	DEFINITION
	{
		int		n;
		
		_TRACE("std_ResetConfigChangedState") ;

		ReadCommand(read_id_directory);

		if (id_num_of_trans_blocks > ID_MAX_BLOCK_NUM)
		{
			_ERROR("std_ResetConfigChangedState: Too many TRANSDUCER Blocks (" + id_num_of_trans_blocks + ")");
			id_num_of_trans_blocks = ID_MAX_BLOCK_NUM;
		}

		if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
		{
			_ERROR("std_ResetConfigChangedState: Too many FUNCTION Blocks (" + id_num_of_func_blocks + ")");
			id_num_of_func_blocks = ID_MAX_BLOCK_NUM;
		}
		
	//--- Physical Block: Revision Counter --------------------------------------
		ReadCommand(read_id_phys_st_rev);
		id_phys_st_rev = id_phys_st_rev_online;

	//--- Transducer Block: Revision Counter ------------------------------------
		for (n = 0; n < ID_MAX_BLOCK_NUM; n++)
		{
			id_trans_st_rev[n] = id_trans_st_rev[n].DEFAULT_VALUE;
		}
		for (n = 0; n < id_num_of_trans_blocks; n++)
		{
			id_block_num = n + 1;
			ReadCommand(read_id_trans_st_rev);
			id_trans_st_rev[n] = id_trans_st_rev_online;
		}
	
	//--- Funciton Block: Revision Counter --------------------------------------
		for (n = 0; n < ID_MAX_BLOCK_NUM; n++)
		{
			id_func_st_rev[n] = id_func_st_rev[n].DEFAULT_VALUE;
		}
		for (n = 0; n < id_num_of_func_blocks; n++)
		{
			id_block_num = n + 1;
			ReadCommand(read_id_func_st_rev);
			id_func_st_rev[n] = id_func_st_rev_online;
		}

		ret_ConfigChangedState	= 0;
	}
}


///////////////////////////////////////////////////////////////////////
// COMMANDs

COMMAND read_id_directory
{
	SLOT	1;
	INDEX	1;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_dummy_word,				// Start_PB
			id_num_of_phys_blocks,		// Number of Physical Blocks
			id_dummy_word,				// Start_PB
			id_num_of_trans_blocks,		// Number of Transducer Blocks
			id_dummy_word,				// Start_PB
			id_num_of_func_blocks		// Number of Function Blocks
#if _PDM_  <  700			
			,id_dummy_array
#endif			
		}
	}
}



COMMAND read_id_phys_blk
{
	BLOCK id_physical_block;
	INDEX 0;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_dummy_byte,				// phys_blk_reserve 
			id_dummy_byte,				// phys_blk_object
			id_phys_blk_parent_class, 
			id_dummy_byte,				// phys_blk_class
			id_dummy_dword,				// phys_blk_dd_reference
			id_dummy_word,				// phys_blk_dd_rev
			id_dummy_word,				// phys_blk_profile
			id_phys_blk_profile_rev,
			id_dummy_byte,				// phys_blk_execution_time
			id_dummy_word,				// phys_blk_num_parameters
			id_dummy_word,				// phys_blk_index_view_1
			id_dummy_byte				// phys_blk_num_view_lists
		}
	}
}



COMMAND read_id_phys_st_rev
{
	BLOCK id_physical_block;
	INDEX 1;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_st_rev_online
		}
	}
}



COMMAND read_id_phys_tag_desc
{
	BLOCK id_physical_block;
	INDEX 2;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_tag_desc
		}
	}
}



COMMAND read_id_phys_software_rev
{
	BLOCK id_physical_block;
	INDEX 8;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_software_rev
		}
	}
}



COMMAND read_phys_write_locking
{
	BLOCK id_physical_block;
	INDEX 18;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			phys_write_locking
		}
	}
}



COMMAND read_id_phys_serial_num
{
	BLOCK id_physical_block;
	INDEX 12;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_serial_num
		}
	}
}



COMMAND read_id_phys_manufacturer_id
{
	BLOCK id_physical_block;
	INDEX 10;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_manufacturer_id
		}
	}
}



COMMAND read_id_phys_device_id
{
	BLOCK id_physical_block;
	INDEX 11;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_device_id
		}
	}
}



COMMAND read_id_trans_blk
{
	BLOCK id_transducer_block;
	INDEX 0;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_dummy_byte,				// trans_blk_reserve 
			id_dummy_byte,				// trans_blk_object
			id_trans_blk_parent_class, 
			id_trans_blk_class,
			id_dummy_dword,				// trans_blk_dd_reference
			id_dummy_word,				// trans_blk_dd_rev
			id_dummy_word,				// trans_blk_profile
			id_dummy_word,				// trans_blk_profile_rev
			id_dummy_byte,				// trans_blk_execution_time
			id_dummy_word,				// trans_blk_num_parameters
			id_dummy_word,				// trans_blk_index_view_1
			id_dummy_byte				// trans_blk_num_view_lists
		}
	}
}



COMMAND read_id_trans_st_rev
{
	BLOCK id_transducer_block;
	INDEX 1;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_trans_st_rev_online
		}
	}
}



COMMAND read_id_func_blk
{
	BLOCK id_function_block;
	INDEX 0;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_dummy_byte,				// func_blk_reserve 
			id_dummy_byte,				// func_blk_object
			id_func_blk_parent_class, 
			id_func_blk_class,
			id_dummy_dword,				// func_blk_dd_reference
			id_dummy_word,				// func_blk_dd_rev
			id_dummy_word,				// func_blk_profile
			id_dummy_word,				// func_blk_profile_rev
			id_dummy_byte,				// func_blk_execution_time
			id_dummy_word,				// func_blk_num_parameters
			id_dummy_word,				// func_blk_index_view_1
			id_dummy_byte				// func_blk_num_view_lists
		}
	}
}



COMMAND read_id_func_st_rev
{
	BLOCK id_function_block;
	INDEX 1;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_func_st_rev_online   
		}
	}
}



///////////////////////////////////////////////////////////////////////

#endif
// SIPASTIDENT02_INC_INCLUDED
