[D
	/LoadSW [P
		[A LoadFlag ]	% LoadFlag = False -> Check only if Files are existing 	
		
		/Result #1 def
		/MissingFile '' def
		
		% Build SW File name
		/SWFile FilePath IntfSel.IntfDir add '\' add IntfSel.IntfSWFileName add IntfSWTypeExt add def
		/SWFile SWFile '_V' add IntfSel.SWVersion cvs add 'S' add IntfSel.SWSubVersion cvs add def 
		IntfSel.SWBetaInfo '' ne [B
			/SWFile SWFile '_' add IntfSel.SWBetaInfo add def
		] if
		/SWFile SWFile '.HX3' add def
		
		% Build Tree File name
		/TreeFile FilePath IntfSel.IntfDir add '\' add IntfSel.IntfTreeFileName add IntfTreeTypeExt add def
		/TreeFile TreeFile '_V' add IntfSel.TreeVersion cvs add 'S' add IntfSel.TreeSubVersion cvs add def 
		IntfSel.TreeBetaInfo '' ne [B
			/TreeFile TreeFile '_' add IntfSel.TreeBetaInfo add def
		] if
		/TreeFile TreeFile '.HX2' add def
		
		% Build DefaultPar File name
		/DefaultParFile FilePath IntfSel.IntfDir add '\' add IntfSel.IntfTreeFileName add IntfTreeTypeExt add def
		/DefaultParFile DefaultParFile '_V' add IntfSel.TreeVersion cvs add 'S' add IntfSel.TreeSubVersion cvs add def 
		IntfSel.TreeBetaInfo '' ne [B
			/DefaultParFile DefaultParFile '_' add IntfSel.TreeBetaInfo add def
		] if
		/DefaultParFile DefaultParFile '.GR3' add def
		
		
		% check if files are existing
		Result [B
			SWFile FileExist not [B
				/Result #0 def 
				/MissingFile SWFile def
			] if
		] if
		Result [B
			TreeFile FileExist not [B
				/Result #0 def 
				/MissingFile TreeFile def
			] if
		] if
		Result [B
			DefaultParFile FileExist not [B
				/Result #0 def 
				/MissingFile DefaultParFile def
			] if
		] if
		Result [B
			IntfSel /IntfSpecificSetup known [B
				/SpecificSetupName IntfSel.IntfSpecificSetup def
				#0 'IntfLoader:' SpecificSetupName add cvn exec
				/MissingFile exch def
				/Result exch def
			] if
		] if
		
		
		Result LoadFlag and [B
			% write serialnumber, articlenumber and articlenumber string according to selected interface
			% only for 2S netX drives at the moment: 10.09.2021, dc
			IntfSel /VirtArtNumberValue known [B

				/VirtArtNumberValueAddress $A20006C6 def
				/VirtArtNumberStringAddress $A20006BC def
				/SerialNumberStringAddress $A20006AE def
			
				VirtArtNumberValueAddress IntfSel.VirtArtNumberValue WriteWordToElo
				VirtArtNumberStringAddress IntfSel.VirtArtNumberCompleteString 10 ' ' padr WriteStringToElo

				/SerialNumberStr IntfSel.VirtArtNumberString def %XXXXX.YYY.ZZZ
				% read .YYY of ordering serial number
					/Value $A2001094 ReadMemory def
					/SerialNumberStr SerialNumberStr Value $FF and chr add def
					/SerialNumberStr SerialNumberStr Value 8 shr chr add def  
					/Value $A2001096 ReadMemory def
					/SerialNumberStr SerialNumberStr Value $FF and chr add def
					/SerialNumberStr SerialNumberStr Value 8 shr chr add def  
				% read .ZZZ of ordering serial number
					/Value $A2001098 ReadMemory def
					/SerialNumberStr SerialNumberStr Value $FF and chr add def
					/SerialNumberStr SerialNumberStr Value 8 shr chr add def  
					/Value $A200109A ReadMemory def
					/SerialNumberStr SerialNumberStr Value $FF and chr add def
					/SerialNumberStr SerialNumberStr Value 8 shr chr add def  
					/SerialNumberStr SerialNumberStr 0 chr add def 
				SerialNumberStringAddress SerialNumberStr 14 ' ' padr WriteStringToElo

			] if
			
			
			% Read drive
			% Get Installation Valid Flag
			/InstVal INTFInstallValidAddr PackInst:ReadMemory def
			
			% Get SW CRC
			/CRC_drive_SW INTF_SW_CRC_Addr PackInst:_GetBlock def
			
			% Get Tree CRC
			/CRC_drive_Tr INTF_Tr_CRC_Addr PackInst:_GetBlock def
			
			% Get SW file name
			/Filename_read_SW INTF_SW_FileName_Addr GetInstalledFileName uppercase def
			
			% Get Tree file name
			/Filename_read_Tr INTF_Tr_FileName_Addr GetInstalledFileName uppercase def
			
			
			% Read file
			% Get SW CRC
			getcurrentdir '\' add SWFile add INTF_SW_CRC_Addr SystGen_CRC crcfromfile
			/Res exch def
			/CRC_file_SW exch def
			
			% Get Tree CRC
			getcurrentdir '\' add TreeFile add INTF_Tr_CRC_Addr SystGen_CRC crcfromfile
			/Res exch def
			/CRC_file_Tr exch def
			
			% Get SW file name
			/Filename_file_SW SWFile extfilename '' chfileext uppercase def
			
			% Get Tree file name
			/Filename_file_Tr TreeFile extfilename '' chfileext uppercase def
			
			% Check CRC
			CRC_file_SW CRC_invalid1 eq
			CRC_file_SW CRC_invalid2 eq or [B
				'File: ' SWFile extfilename add ' is corrupted!' add log
				/Result #0 def
			] if
			
			CRC_file_Tr CRC_invalid1 eq
			CRC_file_Tr CRC_invalid2 eq or [B
				'File: ' TreeFile extfilename add ' is corrupted!' add log
				/Result #0 def
			] if
			
			Result [B
				% if it is an MI SG6 devices download netx90 FW image before rest of interface FW
				IntfSel /IntfSpecificSetup known [B
					
					IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG6' eq IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG61_SG62' eq or[B
						/SpecificSetupName IntfSel.IntfSpecificSetup def
						#1 'IntfLoader:' SpecificSetupName add cvn exec
						/MissingFile exch def
						/Result exch def

						IntfSel.Name 'None' ne IntfSel.Name 'NoChange' ne and [B
						
							% set bit on to indicate when install is finished
							/OSInstallCommand OSInstallCommandAddress ReadMemory def
							/OSInstallCommand OSInstallCommand $0008 or def
							OSInstallCommandAddress OSInstallCommand WriteWordToElo
							
							% set re-Download FW flag and framework enable flag for netx
							/REDOWNLOADFLAG_ADDRESS $A2001E00 def
							/REDOWNLOADFLAG_VALUE $00000003 def
							REDOWNLOADFLAG_ADDRESS REDOWNLOADFLAG_VALUE WriteWordToElo
							
							'' log
							'Init update of Interface FW-stack...' log
						
						][B
							% reset re-Download FW flag for netx
							/REDOWNLOADFLAG_ADDRESS $A2001E00 def
							/REDOWNLOADFLAG_VALUE $00000001 def
							REDOWNLOADFLAG_ADDRESS REDOWNLOADFLAG_VALUE WriteWordToElo
						]ifelse
						
						'Resetting Device. Please wait...' log
						ResetDevice
						8000 wait

					]if
				] if
				
				InstVal InstallationValid ne [B
					'Clearing Intf Parameter Section...' log
					3 PIVar:TalkIntf.ClearInstancePar

					'Erasing INTF SW firmware sector...' log
					'Erasing INTF Tree firmware sector...' log
					2 EraseSWInstance
					
					'Downloading ' SWFile add log
					SWFile dup loadobj exch PackInst:DownloadHX3File
										
					'Downloading ' TreeFile add log
					TreeFile dup loadobj exch PackInst:DownloadHX2File
					
					'Updating UPID list...' log
					TalkIntf.UpdateUPIDList
					
					TalkIntf.GetResult 0 ne [B
					
						IntfSel /IntfSpecificSetup known [B
							IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG6' eq IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG61_SG62' eq or[B
							% wait for netX firmware installation to finish
							% only check the netX FW state if the interface was downloaded
								IntfSel.Name 'None' ne IntfSel.Name 'NoChange' ne and [B
									CheckNetXSWDownload not [B
										'NX firmware download failed!' log
										/Continue FALSE def
									] if
								]if	
							] if
						] if
						ResetDevice
						10000 wait
					] if
					
					'Default parameters...' log
					3 TalkIntf.SetInstanceDefPar

				][B
					/InstallSW
						Filename_file_SW Filename_read_SW ne
						CRC_file_SW CRC_drive_SW ne or def
					
					/InstallTr
						Filename_file_Tr Filename_read_Tr ne
						CRC_file_Tr CRC_drive_Tr ne or def
					
					InstallSW [B
						INTFInstallValidAddr InstallationInvalid WriteWordToElo
					
						'Erasing INTF SW firmware sector...' log
						12 EraseSWInstance
						
						'Downloading ' SWFile add log
						SWFile dup loadobj exch PackInst:DownloadHX3File
					][B
						'Download INTF SW firmware skipped. Already up to date...' log
					] ifelse

					InstallTr [B
						INTFInstallValidAddr InstallationInvalid WriteWordToElo
					
						'Clearing Intf Parameter Section...' log
						3 PIVar:TalkIntf.ClearInstancePar

						'Erasing INTF Tree firmware sector...' log
						102 EraseSWInstance
						
						'Downloading ' TreeFile add log
						TreeFile dup loadobj exch PackInst:DownloadHX2File
					
						'Updating UPID list...' log
						TalkIntf.UpdateUPIDList

						TalkIntf.GetResult 0 ne [B
						
							IntfSel /IntfSpecificSetup known [B
								IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG6' eq IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG61_SG62' eq or[B
								% wait for netX firmware installation to finish
								% only check the netX FW state if the interface was downloaded
									IntfSel.Name 'None' ne IntfSel.Name 'NoChange' ne and [B
										CheckNetXSWDownload not [B
											'NX firmware download failed!' log
											/Continue FALSE def
										] if
									]if	
								] if
							] if
							ResetDevice
							10000 wait
						] if
						
						'Default Intf parameters...' log
						3 TalkIntf.SetInstanceDefPar
						
					][B
						'Download INTF Tree firmware skipped. Already up to date...' log
					] ifelse
				] ifelse
				
				IntfSel /IntfSpecificSetup known [B

					IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG6' ne IntfSel.IntfSpecificSetup 'MIGenericSetup_NX_SG61_SG62' ne and[B
						/SpecificSetupName IntfSel.IntfSpecificSetup def
						#1 'IntfLoader:' SpecificSetupName add cvn exec
						/MissingFile exch def
						/Result exch def
					][B
						% wait for netX firmware installation to finish
						% only check the netX FW state if the interface was downloaded
						IntfSel.Name 'None' ne IntfSel.Name 'NoChange' ne and [B
							CheckNetXSWDownload not [B
								'NX firmware download failed!' log
								/Continue FALSE def
							] if
							
						] if
					]ifelse
					
				] if
				
				
				
			] if
		] if
		
		[A /MissingFile /Result]
	]
	
	/EtherCATSetup_SG5_SG6 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		LoadFlag [B
			/ModuleType  $A3000000 ReadMemory def
			ModuleType $10 eq [B
				'Downloading ' ModuleParFile add log
				ModuleParFile dup loadobj exch PackInst:DownloadHX2File	
				/Value $A200068E ReadMemory def
				$A400001C Value WriteWordToElo
				/Value $A200068C ReadMemory def
				$A400001E Value WriteWordToElo
			]
			[B
				/Result #0 def 
				'Warning: EtherCAT module is not connected!' log
			] ifelse  
		] if
		[A /Result /MissingFile] 
	]
	
	/EtherCATSetup_SG7 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		LoadFlag [B
			'Downloading ' moduleparfile add log
			moduleparfile dup loadobj exch packinst:downloadhx2file
		] if
		[A /Result /MissingFile] 
	]
	
	/ProfiNetSetup_SG5 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def

		/ModuleParFile1 FilePath IntfSel.IntfDir add IntfSel.IntfModulePar1 add def
		ModuleParFile1 FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile1 def
		] if 
		%/ModuleParFile2 FilePath IntfSel.IntfDir add IntfSel.IntfModulePar2 add def
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		
		LoadFlag [B
			/ModuleType  			$A3000000 ReadMemory def
			/ModuleFWTypeAddress 	$A3000070 def
			/ModuleFWVersionAddress $A3000072 def
			/ModuleHWVersionAddress $A3000002 def
			/ModuleFWVersion		$0101 def
			/ModuleFWVersionErased	$FFFF def
			/ModuleFWVersionRead  	ModuleFWVersionAddress ReadMemory def

			ModuleType $70 eq [B

				/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def

				/PN_Flash_CRCRead  	$C00001A2 ReadMemory def
				/PN_Flash_CRC 		$8791 def
				% check CRC to decide if second part of PN FW has to be reloaded
				PN_Flash_CRCRead	PN_Flash_CRC ne [B
				
					ModuleFWVersionAddress ModuleFWVersionErased WriteWordToElo
					
						% Erase whole RT Flash with special bulkerase command
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $78 chr add $56 chr add $34 chr add $12 chr add TalkIntf.GenericCmd
						15000 wait
						ResetDevice
						15000 wait
					
						'Downloading ' ModuleParFile add log
						ModuleParFile dup loadobj exch PackInst:DownloadHX2file
						
					ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
				] 
				[B
				
					ModuleHWVersionRead $00202 ge[B % Module Version >= V2RA
						% Erase the first 16 4k blocks  in the flash
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $00 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $10 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $20 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $30 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $40 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $50 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $60 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $70 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $80 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $90 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $A0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $B0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $C0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $D0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $E0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $F0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
					]if
				
					'Defaulting ' ModuleParFile1 add log
					ModuleParFile1 dup loadobj exch PackInst:DownloadHX2file
				] ifelse
			]
			[B
				/Result #0 def 
				'Warning: ProfiNet module is not connected!' log
			] ifelse  
		] if
		[A /Result /MissingFile] 
	]

	/ProfiNetSetup_SG6 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def

		/ModuleParFile1 FilePath IntfSel.IntfDir add IntfSel.IntfModulePar1 add def
		ModuleParFile1 FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile1 def
		] if 
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		
		LoadFlag [B
			/ModuleType  			$A3000000 ReadMemory def
			/ModuleFWTypeAddress 	$A3000070 def
			/ModuleFWVersionAddress $A3000072 def
			/ModuleHWVersionAddress $A3000002 def
			/ModuleFWVersion		$0101 def
			/ModuleFWVersionErased	$FFFF def
			/ModuleFWVersionRead  	ModuleFWVersionAddress ReadMemory def

			ModuleType $70 eq [B

				/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def  

				/PN_Flash_CRCRead  	$900001A2 ReadMemory def 
				/PN_Flash_CRC 		$8791 def
				% check CRC to decide if second part of PN FW has to be reloaded
				PN_Flash_CRCRead	PN_Flash_CRC ne [B
				
					ModuleFWVersionAddress ModuleFWVersionErased WriteWordToElo
					
						% Erase whole RT Flash with special bulkerase command
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $78 chr add $56 chr add $34 chr add $12 chr add TalkIntf.GenericCmd
						15000 wait
						ResetDevice
						15000 wait
					
						'Downloading ' ModuleParFile add log
						ModuleParFile dup loadobj exch PackInst:DownloadHX2file
						
					ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
				] 
				[B
				
					ModuleHWVersionRead $00302 ge[B % Module Version >= V3RA
						% Erase the first 16 4k blocks  in the flash
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $00 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $10 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $20 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $30 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $40 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $50 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $60 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $70 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $80 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $90 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $A0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $B0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $C0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $D0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $E0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $A7 chr add $00 chr add $F0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
					]if
					
					'Defaulting ' ModuleParFile1 add log
					ModuleParFile1 dup loadobj exch PackInst:DownloadHX2file
					
				] ifelse
			]
			[B
				/Result #0 def 
				'Warning: ProfiNet module is not connected!' log
			] ifelse  
		] if
		[A /Result /MissingFile] 
	]

	/ProfiNetSetup_SG7 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def

		/ModuleParFile1 FilePath IntfSel.IntfDir add IntfSel.IntfModulePar1 add def
		ModuleParFile1 FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile1 def
		] if 
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		
		LoadFlag [B
			/ModuleFWVersionAddress $301062 def
			/ModuleFWVersion		$0101 def
			/ModuleFWVersionErased	$FFFF def
			/ModuleFWVersionRead  	ModuleFWVersionAddress ReadMemory def
			
			/DI_ProfinetonboardAddress	$D952 def
			/DI_Profinetonboard  		DI_ProfinetonboardAddress ReadMemory def 
			
			
				/PN_Flash_CRCRead  	$805E ReadMemory def 
				/PN_Flash_CRC 		$8791 def
				% check CRC to decide if second part of PN FW has to be reloaded
				PN_Flash_CRCRead	PN_Flash_CRC ne [B
				
					ModuleFWVersionAddress ModuleFWVersionErased WriteWordToElo
					
						% Erase whole RT Flash with special bulkerase command
						$31 chr $66 chr add $66 chr add $66 chr add $78 chr add $56 chr add $34 chr add $12 chr add TalkIntf.GenericCmd
						15000 wait
						ResetDevice
						15000 wait
					
						'Downloading ' ModuleParFile add log
						ModuleParFile dup loadobj exch PackInst:DownloadHX2file	
						
					ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
				] 
				[B
				
					DI_Profinetonboard $0041 ge[B % Profinetonboard DI-Block entry >= 0x41
						% Erase the first 16 4k blocks  in the flash
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $00 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $10 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $20 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $30 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $40 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $50 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $60 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $70 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $80 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $90 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $A0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $B0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $C0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $D0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $E0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
						$31 chr $66 chr add $66 chr add $66 chr add $00 chr add $F0 chr add $00 chr add $55 chr add TalkIntf.GenericCmd
						100 wait
					]if
					
					'Defaulting ' ModuleParFile1 add log
					ModuleParFile1 dup loadobj exch PackInst:DownloadHX2file
				] ifelse
				
		] if
		[A /Result /MissingFile] 
	]
	
	% special SG6 netx devices such as C1250-CC
	/MIGenericSetup_NX_SG6 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def
		
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def 
			/MissingFile ModuleParFile def
		] if 
		
		LoadFlag [B
			netX90Based[B
				IntfSel.IntfModulePar GetNetX90FWVersionFromFileName
			][B
				IntfSel.IntfModulePar GetNetX52FWVersionFromFileName
			] ifelse
			/ProtStackRevNumber exch def
			/ProtStackBuildVers exch def
			/ProtStackMinorVers exch def
			/ProtStackMajorVers exch def
			
			/ProtStackVersName IntfSel.ProtStackVersName uppercase def
			
			ProtStackMajorVers ProtStackMajorVersRead eq
			ProtStackMinorVers ProtStackMinorVersRead eq and
			ProtStackBuildVers ProtStackBuildVersRead eq and
			ProtStackRevNumber ProtStackRevNumberRead eq and 
			ProtStackVersName  ProtStackVersNameRead  eq and [B
				'Download netX firmware skipped. Already up to date...' log
				
				IntfSel /Name known [B
					IntfSel /Name 'NoChange' puts
				] if
			][B
				/ModuleTypeAddress 		$A3000000 def
				/ModuleHWVersionAddress $A3000002 def
				
				/ModuleHWVersion		$0201 def % latest HW Version: Version 2, No Revision
				
				/ModuleType  ModuleTypeAddress ReadMemory def
		
				% check Module Type
				ModuleType $90 eq[B
					/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def
					
					% check HW module version
					ModuleHWVersionRead ModuleHWVersion ge[B
							'Erasing netX firmware sectors...' log
							% wait 250 ms between erase commands, to give switch some time to process eth frames received while erasing flash which is blocking
							$80900000 PackInst:EraseFlash
							250 wait
							$80940000 PackInst:EraseFlash
							250 wait
							$80980000 PackInst:EraseFlash
							250 wait
							$809C0000 PackInst:EraseFlash
							250 wait
					
							'Downloading ' ModuleParFile add log
							ModuleParFile dup loadobj exch PackInst:DownloadHX2file	
					][B
						/Result #0 def 
						'Warning: Wrong HW Module Version!' log
					] ifelse 
				]
				[B
					/Result #0 def 
					'Warning: Wrong HW Module Type connected!' log
				] ifelse 
			] ifelse
		] if
		
		[A /Result /MissingFile] 
	]
	
	%  SG6 MI netx devices
	/MIGenericSetup_NX_SG61_SG62 [P
		[A /LoadFlag ]
		/Result #1 def
		/MissingFile '' def
		
		/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModulePar add def
		ModuleParFile FileExist not [B
			/Result #0 def
			/MissingFile ModuleParFile def
		] if
		
		LoadFlag [B
		
			netX90Based[B
				IntfSel.IntfModulePar GetNetX90FWVersionFromFileName
			][B
				IntfSel.IntfModulePar GetNetX52FWVersionFromFileName
			] ifelse
			/ProtStackRevNumber exch def
			/ProtStackBuildVers exch def
			/ProtStackMinorVers exch def
			/ProtStackMajorVers exch def
			
			/ProtStackVersName IntfSel.ProtStackVersName uppercase def
			
			ProtStackMajorVers ProtStackMajorVersRead eq
			ProtStackMinorVers ProtStackMinorVersRead eq and
			ProtStackBuildVers ProtStackBuildVersRead eq and
			ProtStackRevNumber ProtStackRevNumberRead eq and 
			ProtStackVersName  ProtStackVersNameRead  eq and [B
				'Download netX firmware skipped. Already up to date...' log
				
				IntfSel /Name known [B
					IntfSel /Name 'NoChange' puts
				] if
			][B
				'Erasing netX firmware sectors...' log
				% wait 250 ms between erase commands, to give switch some time to process eth frames received while erasing flash which is blocking
				$80900000 PackInst:EraseFlash
				250 wait
				$80940000 PackInst:EraseFlash
				250 wait
				$80980000 PackInst:EraseFlash
				250 wait
				$809C0000 PackInst:EraseFlash
				250 wait
			
				'Downloading ' ModuleParFile add log
				ModuleParFile dup loadobj exch PackInst:DownloadHX2file
			] ifelse
		] if
		
		[A /Result /MissingFile]
	]
]
