/*--------------------------------------------------------------*/
/*	Copyright (C) Siemens AG (1999). All Rights Reserved		*/
/*	Product:		SIMATIC PDM									*/
/*																*/
/*	Device:			Identification Check for PROFIBUS PA		*/
/*	Description:	Device Description							*/
/*	Dictionary:		SIPADC01.dct								*/
/*																*/
/*  $Revision: 1.2 $	    								*/
/*  $Date: 2008/04/17 15:32:27CEST $							*/
/*  $Date: 2008/04/17 15:32:27CEST $	/*--------------------------------------------------------------*/


#ifndef SIPASTIDENT01_INC_INCLUDED
#define SIPASTIDENT01_INC_INCLUDED

#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			20

#define	ID_FC_ERROR					3000

// --- Identcheck and WriteProtectionCheck use features only supported in 5.0.2 !


#ifdef _V502_

// enable ident check
#define ENABLE_IDENTCHECK

// enable WriteProtection check
#define ENABLE_WRITEPROTECTIONCHECK

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

#endif


#ifndef _V510_
#define LOG_MESSAGE(priority, text) _TRACE(text) 
#endif



#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)								\
			{														\
				if (id_Method_In_SilentMode == 0)					\
					ACKNOWLEDGE([IdentCheckCommProblem]);			\
				else												\
					process_abort();								\
			}														\
		}															\


#ifdef _V510_
#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);								
#else
#define TRACE_DEVICE_IDENTIFICATION					
#endif


#ifdef _V510_
#define FUNCTION_CHECK_DEVICE_CLASS														\
		if ((id_phys_blk_parent_class	!= ivar_value(phys_blk_parent_class))	||		\
			(id_trans_blk_parent_class	!= ivar_value(trans1_blk_parent_class)))		\
		{																				\
			if( id_Method_In_SilentMode == 0 )											\
			{																			\
				char szPhysBlkClass[] ;													\
				char szTransBlkClass[] ;												\
				char szIdPhysBlkClass[] ;												\
				char szIdTransBlkClass[] ;												\
				get_variable_string(phys_blk_parent_class, szPhysBlkClass) ;			\
				get_variable_string(trans1_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] ;											\
				PUT_MESSAGE(sz);														\
			}																			\
			else																		\
			{																			\
				LOG_MESSAGE(0, [DeviceTypeMismatch]);									\
			}																			\
																						\
			id_status = ID_CHECK_ABORT;													\
		}
#else
#define FUNCTION_CHECK_DEVICE_CLASS	
#endif


#ifdef _V510_
#define FUNCTION_CHECK_SERIAL_NUMBER													\
	if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))						\
	{																					\
		if( (id_phys_serial_num != sz1)	|| (id_phys_device_id != phys_device_id) )		\
		{																				\
			if( id_Method_In_SilentMode == 0 )											\
			{																			\
				sz = [mismatch_identcheck] + "\r\n    "									\
				+ [phys_ser_num] + "\r\n\r\n"									\
				+ [device_expected] + "\r\n    "										\
				+ [phys_device_id] + " = "												\
				+ phys_device_id														\
				+ "\r\n    "															\
				+ [phys_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_ser_num] + " = "											\
				+ id_phys_serial_num													\
				+ "\r\n    "															\
				+ [tag_desc] + " = "													\
				+ id_phys_tag_desc														\
				+ "\r\n\r\n"															\
				+ [continue_anyway] ;													\
				ACKNOWLEDGE(sz);														\
			}																			\
			else																		\
			{																			\
				LOG_MESSAGE(0, [mismatch_identcheck] + " " + [phys_ser_num]);	\
			}																			\
		}																				\
	}																					
#else
#define	FUNCTION_CHECK_SERIAL_NUMBER
#endif

#ifdef _V510_
#define FUNCTION_CHECK_PROFILE_REV													\
		if( id_phys_blk_profile_rev != CHECK_PROFILE_REV )							\
		{																			\
			get_variable_string(id_phys_manufacturer_id, szManufacturer) ;			\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				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] ;										\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, [mismatch_identcheck] + " " + [blk_profile_rev]);	\
			}																		\
																					\
			process_abort() ;														\
		}
#else
#define FUNCTION_CHECK_PROFILE_REV	
#endif



#ifdef _V510_
#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) ;	\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				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] ;										\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, [DeviceTypeMismatch]);								\
			}																		\
																					\
			process_abort() ;														\
		}
#else
#define FUNCTION_CHECK_MANUFACTURER	
#endif


#define FUNCTION_CHECK_DEVICE_TYPE													\
		if( id_phys_device_id != CHECK_DEVICE_TYPE )								\
		{																			\
			get_variable_string(id_phys_manufacturer_id, szManufacturer) ;			\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				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] ;										\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, [mismatch_identcheck] + " " + [blk_profile_rev]);	\
			}																		\
																					\
			process_abort() ;														\
		}																			\



#ifdef _V510_
#ifndef FUNCTION_CHECK_SOFTWARE_VERSION
#define FUNCTION_CHECK_SOFTWARE_VERSION												\
    _TRACE("********** BEGIN: E+H Flowtec IdentCheck - SW Version");		\
    if( id_phys_software_rev != CHECK_SOFTWARE_VERSION )						\
		{																			\
			if( id_Method_In_SilentMode == 0 )										\
			{																		\
				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] ;										\
				PUT_MESSAGE(sz);													\
			}																		\
			else																	\
			{																		\
				LOG_MESSAGE(0, [mismatch_identcheck] + " " + [phys_software_revision]);	\
			}																		\
																					\
			process_abort() ;														\
		} \
		_TRACE("********** END: E+H Flowtec IdentCheck - SW Version");
#else
#define FUNCTION_CHECK_SOFTWARE_VERSION
#endif
#endif





/***********************************************************************/
/*    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
	}
}


MENU Group_IdentCheck_dd
{
	LABEL "Offline data";
	ITEMS
	{
		phys_tag_desc			(READ_ONLY),
		phys_blk_parent_class,
		phys_blk_profile_rev,
		trans1_blk_parent_class, 
		trans1_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[1],
		id_trans_st_rev[2],
		id_trans_st_rev[3],
		id_trans_st_rev[4],
		id_trans_st_rev[5],
		id_trans_st_rev[6],
		id_trans_st_rev[7],
		id_trans_st_rev[8],
		id_trans_st_rev[9],
		id_trans_st_rev[10],
		SEPARATOR,
		id_trans_st_rev[11],
		id_trans_st_rev[12],
		id_trans_st_rev[13],
		id_trans_st_rev[14],
		id_trans_st_rev[15],
		id_trans_st_rev[16],
		id_trans_st_rev[17],
		id_trans_st_rev[18],
		id_trans_st_rev[19],
		id_trans_st_rev[20]
	}
}

MENU Group_IdentCheck_FB_RevCounters
{
	LABEL		"Function Block";
	ITEMS
	{
		id_func_st_rev[1],
		id_func_st_rev[2],
		id_func_st_rev[3],
		id_func_st_rev[4],
		id_func_st_rev[5],
		id_func_st_rev[6],
		id_func_st_rev[7],
		id_func_st_rev[8],
		id_func_st_rev[9],
		id_func_st_rev[10],
		SEPARATOR,
		id_func_st_rev[11],
		id_func_st_rev[12],
		id_func_st_rev[13],
		id_func_st_rev[14],
		id_func_st_rev[15],
		id_func_st_rev[16],
		id_func_st_rev[17],
		id_func_st_rev[18],
		id_func_st_rev[19],
		id_func_st_rev[20]
	}
}

#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_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_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;
}

VARIABLE	id_dummy_array
{
	LABEL		"";
	CLASS		LOCAL;
	TYPE		ASCII (200);
	HANDLING	READ;
}

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
      { 1,   [Acromag]						},
      { 2,   [Allen_Bradley]				},
      { 3,   [Ametek]						},
      { 4,   [Analog_Devices]				},
      { 5,   [Elsag_Bailey]					},
      { 6,   [Beckman]						},
      { 7,   [Bell_Microsensor]				},
      { 8,   [Bourns]						},
      { 9,   [Bristol_Babcock]				},
      { 10,  [Brooks_Instrument]			},
      { 11,  [Chessell]						},
      { 12,  [Combustion_Engineering]		},
      { 13,  [Daniel_Industries]			},
      { 14,  [Delta]						},
      { 15,  [Dieterich_Standard]			},
      { 16,  [Dohrmann]						},
      { 17,  [Endress_and_Hauser]			},
      { 18,  [Elsag_Bailey]					},
      { 19,  [Fisher_Controls]				},
      { 20,  [Foxboro]						},
      { 21,  [Fuji]							},
      { 22,  [Elsag_Bailey]					},
      { 23,  [Honeywell]					},
      { 24,  [ITT_Barton]					},
      { 25,  [KayRay_Sensall]				},
      { 26,  [Kent]							},
      { 27,  [Leeds_and_Northrup]			},
      { 28,  [Leslie]						},
      { 29,  [M_System_Co]					},
      { 30,  [Measurex]						},
      { 31,  [Micro_Motion]					},
      { 32,  [Moore_Industries]				},
      { 33,  [Moore_Products]				},
      { 34,  [Ohkura_Electric]				},
      { 35,  [Paine]						},
      { 36,  [Rochester_Instrument_Systems] },
      { 37,  [Ronan]						},
      { 38,  [Rosemount]					},
      { 39,  [Peek_Measurement]				},
      { 40,  [Schlumberger]					},
      { 41,  [Sensall]						},
      { 42,  [Siemens]						},
      { 43,  [Camille_Bauer]				},
      { 44,  [Toshiba]						},
      { 45,  [Transmation]					},
      { 46,  [Rosemount_Analytical]			},
      { 47,  [Valmet]						},
      { 48,  [Valtek]						},
      { 49,  [Varec]						},
      { 50,  [Viatran]						},
      { 51,  [Weed]							},
      { 52,  [Westinghouse]					},
      { 53,  [Xomox]						},
      { 54,  [Yamatake]						},
      { 55,  [Yokogawa]						},
      { 56,  [Nuovo_Pignone]				},
      { 57,  [Promac]						},
      { 58,  [Exac_Corporation]				},
      { 59,  [KDG_Mobrey]					},
      { 60,  [Acrom_Control_System]			},
      { 61,  [Princo]						},
      { 62,  [Smar]							},
      { 63,  [Foxboro_Eckardt]				},
      { 64,  [Measurement_Technology]		},
      { 65,  [Applied_System_Technologies]	},
      { 66,  [Samson]						},
      { 67,  [Sparling_Instruments]			},
      { 68,  [Fireye]						},
      { 69,  [Krohne]						},
      { 70,  [Betz_Equipment]				},
      { 71,  [Druck]						},
      { 72,  [SOR]							},
      { 73,  [Elcon_Instruments]			},
      { 74,  [EMCO]							},
      { 75,  [Termiflex]					},
      { 76,  [VAF_Instruments]				},
      { 77,  [Westlock_Controls]			},
      { 78,  [Drexelbrook]					},
      { 79,  [saab_tank_control]			},
      { 80,  [K_TEK]						},
      { 81,  [Flowdata]						},
      { 82,  [Draeger]						},
	  { 83,  [Raytek]						},
	  { 84,  [Meridian_Instruments]			},
	  { 85,  [BTG]							},
	  { 86,  [Magnetrol]					},
	  { 87,  [Neles_Controls]				},
	  { 88,  [Milltronics]					},
	  { 89,  [HELIOS]						},
      { 90,	 [Anderson_Instrument_Company]	},
      { 91,  [INOR]							},
      { 92,  [ROBERTSHAW]					},
      { 93,  [PEPPERL_FUCHS]				},
      { 94,  [ACCUTECH]						},
      { 95,  [Flow_Measurement]				},
      { 96,  [KAMSTRUP]						},
      { 97,  [Knick]						},
      { 98,  [VEGA]							},
      { 99,  [MTS_SYS_CORPS_SENSORS]		},
      { 100, [Oval]							},
      { 101, [Masoneilan_DRESSER]			},
      { 102, [Besta]						},
      { 103, [Ohmart]						},
      { 104, [Harold_Beck_and_Sons]			},
      { 105, [rittmeyer_instrumentation]	},
      { 106, [rossel_messtechnik]			},
      { 107, [WIKA]							},
      { 108, [Bopp_and_Reuther_Heinrichs]	},
      { 109, [pr_eletronics]				},
      { 110, [jordan_controls]				},
      { 111, [valcom]						},
      { 112, [us_electric_motors]			}, 
      { 113, [apparatebau_hundsbach]		},
      { 250, [not_used]						},
      { 251, [none]							},
      { 252, [unknown]						},
      { 253, [special]						}
	}
	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		"";
	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_blk_parent_class
{
	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]		}
	}
}


id_phys_blk_profile_rev			LIKE VARIABLE	phys_blk_profile_rev
{
	REDEFINE	CLASS	LOCAL;
}

id_phys_software_rev			LIKE VARIABLE	phys_software_rev
{
	REDEFINE	CLASS	LOCAL;
}

id_phys_st_rev_online			LIKE VARIABLE	phys_st_rev
{
	REDEFINE	CLASS	LOCAL;
}

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

id_phys_tag_desc				LIKE VARIABLE	phys_tag_desc
{
	REDEFINE	CLASS	LOCAL;
}

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


/***********************************************************************/
/*    Transducer Block: Actuator 									   */
/***********************************************************************/

BLOCK id_transducer_block
{
	TYPE	TRANSDUCER;
	NUMBER	id_block_num;
}

id_trans_blk_parent_class		LIKE VARIABLE	trans1_blk_parent_class
{
	REDEFINE	CLASS	LOCAL;
	REDEFINE 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]	},
		{	7,	[trans_blk_parent_class_ANALYSIS]	},
	}
}

id_trans_blk_class				LIKE VARIABLE	trans1_blk_class
{
	REDEFINE	CLASS	LOCAL;
}

id_trans_st_rev_online			LIKE VARIABLE	id_phys_st_rev_online
{											
}											
											
id_trans01_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 1";
}

id_trans02_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 2";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (2)
}

id_trans03_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 3";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (3)
}

id_trans04_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 4";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (4)
}

id_trans05_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 5";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (5)
}

id_trans06_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 6";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (6)
}

id_trans07_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 7";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (7)
}

id_trans08_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 8";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (8)
}

id_trans09_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 9";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (9)
}

id_trans10_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 10";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (10)
}

id_trans11_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 11";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (11)
}

id_trans12_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 12";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (12)
}

id_trans13_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 13";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (13)
}

id_trans14_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 14";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (14)
}

id_trans15_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 15";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (15)
}

id_trans16_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 16";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (16)
}

id_trans17_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 17";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (17)
}

id_trans18_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 18";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (18)
}

id_trans19_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 19";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (19)
}

id_trans20_st_rev				LIKE VARIABLE	id_trans_st_rev_online
{
	REDEFINE LABEL		"TB 20";
	REDEFINE VALIDITY	VALID_ID_TRANS_BLOCK (20)
}

ARRAY OF VARIABLE	id_trans_st_rev
{
   ELEMENTS
   {   
	    1,		id_trans01_st_rev;
		2,		id_trans02_st_rev;
		3,		id_trans03_st_rev;
		4,		id_trans04_st_rev;
		5,		id_trans05_st_rev;
		6,		id_trans06_st_rev;
		7,		id_trans07_st_rev;
		8,		id_trans08_st_rev;
		9,		id_trans09_st_rev;
		10,		id_trans10_st_rev;
		11,		id_trans11_st_rev;
		12,		id_trans12_st_rev;
		13,		id_trans13_st_rev;
		14,		id_trans14_st_rev;
		15,		id_trans15_st_rev;
		16,		id_trans16_st_rev;
		17,		id_trans17_st_rev;
		18,		id_trans18_st_rev;
		19,		id_trans19_st_rev;
		20,		id_trans20_st_rev;
   }
}

/***********************************************************************/
/*    Function Block                                                   */
/***********************************************************************/

BLOCK id_function_block
{
	TYPE	FUNCTION;
	NUMBER	id_block_num;
}

id_func_st_rev_online			LIKE VARIABLE	id_phys_st_rev_online
{											
}											
											
id_func01_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 1";
}

id_func02_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 2";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (2)
}

id_func03_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 3";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (3)
}

id_func04_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 4";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (4)
}

id_func05_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 5";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (5)
}

id_func06_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 6";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (6)
}

id_func07_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 7";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (7)
}

id_func08_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 8";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (8)
}

id_func09_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 9";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (9)
}

id_func10_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 10";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (10)
}

id_func11_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 11";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (11)
}

id_func12_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 12";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (12)
}

id_func13_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 13";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (13)
}

id_func14_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 14";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (14)
}

id_func15_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 15";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (15)
}

id_func16_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 16";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (16)
}

id_func17_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 17";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (17)
}

id_func18_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 18";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (18)
}

id_func19_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 19";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (19)
}

id_func20_st_rev				LIKE VARIABLE	id_func_st_rev_online
{
	REDEFINE LABEL		"FB 20";
	REDEFINE VALIDITY	VALID_ID_FUNC_BLOCK (20)
}

ARRAY OF VARIABLE	id_func_st_rev
{
   ELEMENTS
   {   
		1,		id_func01_st_rev;
		2,		id_func02_st_rev;
		3,		id_func03_st_rev;
		4,		id_func04_st_rev;
		5,		id_func05_st_rev;
		6,		id_func06_st_rev;
		7,		id_func07_st_rev;
		8,		id_func08_st_rev;
		9,		id_func09_st_rev;
		10,		id_func10_st_rev;
		11,		id_func11_st_rev;
		12,		id_func12_st_rev;
		13,		id_func13_st_rev;
		14,		id_func14_st_rev;
		15,		id_func15_st_rev;
		16,		id_func16_st_rev;
		17,		id_func17_st_rev;
		18,		id_func18_st_rev;
		19,		id_func19_st_rev;
		20,		id_func20_st_rev;
   }
}

/*******************************************************************************/
/*****	Methods		************************************************************/
/*******************************************************************************/

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

		_TRACE("std_CheckWriteProtection");

		if( VARID(phys_hw_write_protection) != 0 )
		{
			ReadCommand(read_phys_hw_write_protection);
			_TRACE("phys_hw_write_protection = " + itoa(ivar_value(phys_hw_write_protection)));
			if( ivar_value(phys_hw_write_protection) == 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]) ;
				}
			}
		}
	}
}
#endif


#ifdef ENABLE_IDENTCHECK
METHOD	std_CheckDeviceIdentification
{
	LABEL		"std_CheckDeviceIdentification";
	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_serial_num) != 0)
		{
			sz1 = phys_serial_num;
		}
		else
		{
			if (VARID(phys_ser_num) != 0)
			{
				sz1 = phys_ser_num;
			}
			else
			{
				sz1 = "???";
			}
		}

		sz2 = phys_tag_desc;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(phys_blk_parent_class))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(trans1_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_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------
		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if ((id_phys_tag_desc != sz2) && (id_Method_In_SilentMode == 0))
			{
				var_id[0] = VARID(phys_tag_desc);
				var_id[1] = VARID(id_phys_tag_desc);
			
				if (id_Method_In_SilentMode == 0)
				{
					acknowledge([TagMismatch2], var_id);
				}
			}
		}

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


#ifdef ENABLE_IDENTCHECK
METHOD	std_CheckDeviceIdentificationUpload
{
	LABEL		"std_CheckDeviceIdentificationUpload";
	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;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;

		_TRACE("std_CheckDeviceIdentificationUpload");

		READ_DEVICE_IDENTIFICATION

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

		sz2 = phys_tag_desc;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(phys_blk_parent_class))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(trans1_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_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------
		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if (id_phys_tag_desc != sz2)
			{
				get_dictionary_string(cancel, sz1);
				get_dictionary_string(TagMismatch_keep_old, sz2);
				get_dictionary_string(TagMismatch_apply, sz3);

				sz4 = phys_tag_desc;
				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_tag_desc = id_phys_tag_desc;
							break;

						default:					// abort
							id_status = ID_CHECK_ABORT;
							break;
					}
				}
				else
				{
					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]);
				}
			}

			if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
			{
				id_status = ID_CHECK_ABORT;
				if( id_Method_In_SilentMode == 0 )
				{
					ACKNOWLEDGE([TooManyFunctionBlocks]);
				}
			}
			
			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 = 1; n <= id_num_of_trans_blocks; n++)
					{
						id_block_num = n;
						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 = 1; n <= id_num_of_func_blocks; n++)
					{
						id_block_num = n;
						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;
			}
		}

		id_firstCheck = 0;
		ret_CheckDeviceIdentification = id_status;
	}
}
#endif


#ifdef ENABLE_IDENTCHECK
METHOD	std_CheckDeviceIdentificationDownload
{
	LABEL		"std_CheckDeviceIdentificationDownload";
	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;
		id_status						= ID_CHECK_SUCCESS;
		id_block_num					= 1;

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

		READ_DEVICE_IDENTIFICATION

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

		sz2 = phys_tag_desc;
		szTrace = "Device expected: PhysParentClass = "	+ itoa(ivar_value(phys_blk_parent_class))
#ifdef CHECK_PROFILE_REV
					+ "; Profile rev = "				+ itoa(CHECK_PROFILE_REV / 256)
					+ "."								+ itoa(CHECK_PROFILE_REV & 0xff)
#endif
					+ "; TransParentClass = "			+ itoa(ivar_value(trans1_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_PROFILE_REV
	FUNCTION_CHECK_PROFILE_REV
#endif

	FUNCTION_CHECK_SERIAL_NUMBER

	//--- Check TAG -------------------------------------------------------------
		if ((id_status == ID_CHECK_SUCCESS) && (id_firstCheck == 0))
		{
			if (id_phys_tag_desc != sz2)
			{
				var_id[0] = VARID(phys_tag_desc);
				var_id[1] = VARID(id_phys_tag_desc);
			
				if( id_Method_In_SilentMode == 0 )
				{
					acknowledge([TagMismatch2], var_id);
				}
			}
		}

		id_firstCheck = 0;
		ret_CheckDeviceIdentification = id_status;
	}
}
#endif



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;
		
		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]);
			}
		}

		if (id_num_of_func_blocks > ID_MAX_BLOCK_NUM)
		{
			id_status = ID_CHECK_ABORT;
			if( id_Method_In_SilentMode == 0 )
			{
				ACKNOWLEDGE([TooManyFunctionBlocks]);
			}
		}
		
		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 = 1; n <= ID_MAX_BLOCK_NUM; n++)
			{
				id_trans_st_rev[n] = id_trans_st_rev[n].DEFAULT_VALUE;
			}
			for (n = 1; n <= id_num_of_trans_blocks; n++)
			{
				id_block_num = n;
				ReadCommand(read_id_trans_st_rev);
				id_trans_st_rev[n] = id_trans_st_rev_online;
			}
		
		//--- Funciton Block: Revision Counter --------------------------------------
			for (n = 1; n <= ID_MAX_BLOCK_NUM; n++)
			{
				id_func_st_rev[n] = id_func_st_rev[n].DEFAULT_VALUE;
			}
			for (n = 1; n <= id_num_of_func_blocks; n++)
			{
				id_block_num = n;
				ReadCommand(read_id_func_st_rev);
				id_func_st_rev[n] = id_func_st_rev_online;
			}

		}

		ret_CheckDeviceIdentification = id_status;
	}
}


/*******************************************************************************/
/*****	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
			id_dummy_array
		}
	}
}

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 physical_block;
	INDEX 8;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_phys_software_rev
		}
	}
}

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_st_rev
{
	BLOCK id_function_block;
	INDEX 1;
	OPERATION READ;
	TRANSACTION
	{
		REQUEST
		{
		}
		REPLY
		{
			id_func_st_rev_online   
		}
	}
}

#endif
// SIPASTIDENT01_INC_INCLUDED
