[D
	
	
	/PowerUPDlg [P
		[A ]
		
		/PowerUPDlg 'Power UP' 368 140 Create:Form def
		'PowerUPLbl' '' 'Please power cycle the controller, then press OK!' 92 19 PowerUPDlg.AddLabel
		% add ok button
		75 25 PowerUPDlg.SetButtonSize
		'Ok' '' 'Ok' 1 146 70 PowerUPDlg.AddButton
		PowerUPDlg.Execute
		[A ]
	] 
	
	/RebootWithoutStart [P
		[A counts ]
		1 RebootDevice
		8000 wait
		/Stopped #0 def
		counts [B 
			150 wait
			PIVar:TalkIntf.StopProgram
			PIVar:TalkIntf.GetResult 0 eq PIVar:TalkIntf.GetResult $DA eq or [B 
				/Stopped #1 def
				ExitLoop 
			] if
		] repeat 
		Stopped not [B
			'StopProgram' '' PIVar:TalkIntf.GetResult PackInst:_RaiseTalkError           
		] if
		[A ]   
	]
	
	
	/LoadSW [P
		[A LoadFlag ]	% LoadFlag = False -> Check only if Files exist 	
		/OSSWFileName 'UPOS_' def
		
		/Result #1 def
		/MissingFile '' def
		
		%/SWFile FilePath OSDir add '\' add OSSWFileName add EloTypeExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		UPOSExt '' ne [B
			/SWFile FilePath OSDir add '\' add OSSWFileName add UPOSExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		]
		[B
			/SWFile FilePath OSDir add '\' add OSSWFileName add EloTypeExt add '_V' add OSSWVersion cvs add 'S' add OSSWSubVersion cvs add def 
		] ifelse  

		OSSWBetaInfo '' ne [B
			/SWFile SWFile '_' add OSSWBetaInfo add def
		] if
		
		PIVar:TalkVersion $20 eq [B
			/SWFile SWFile '.HX2' add def		
		] 
		[B
			PIVar:TalkVersion $40 eq [B
				ProgFlag [B
				     /SWFile SWFile '.HX2' add def 
				] [B
					'Installation error 0x012 occurred. Please contact support.' raisese 
				] ifelse
			]
			[B
				/SWFile SWFile '.HX3' add def		
			] ifelse  
		] ifelse
		
		OSTypeExt '' ne [B
		  /TreeFile FilePath OSDir add '\' add OSTreeFileName add OSTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 		
		]
		[B
		  /TreeFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 
		] ifelse  
		OSTreeBetaInfo '' ne [B
			/TreeFile TreeFile '_' add OSTreeBetaInfo add def
		] if
		/TreeFile TreeFile '.HX2' add def
		
		%/DefaultParFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def
		OSTypeExt '' ne [B
		  /DefaultParFile FilePath OSDir add '\' add OSTreeFileName add OSTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 		
		]
		[B
		  /DefaultParFile FilePath OSDir add '\' add OSTreeFileName add EloTypeExt add '_V' add OSTreeVersion cvs add 'S' add OSTreeSubVersion cvs add def 
		] ifelse  
		OSTreeBetaInfo '' ne [B
			/DefaultParFile DefaultParFile '_' add OSTreeBetaInfo add def
		] if
		/DefaultParFile DefaultParFile '.Gr3' add def				
		
		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 LoadFlag and [B
			
			PIVar:TalkVersion $F0 and [B
				% B1100
				$40 [B
					%ResetDevice
					PIVar:PortType 'CAN' eq [B
						/MACIDSourceSel MACIDSourceSelAddr ReadMemory def
						/MACIDValue MACIDValueAddr ReadMemory def
					] if	
					
					
					PackInst:StopProgram	
					
					'Erasing firmware sectors...' log     
					$C04000 PackInst:EraseFlash
					$C06000 PackInst:EraseFlash
					$C08000 PackInst:EraseFlash
					$C10000 PackInst:EraseFlash
					
%					'Resetting Device...' log     			
%					ResetDevice
%					1000 Wait
%					PackInst:StopProgram	
				
					'Downloading OS...' log
					
					ProgFlag PIVar:TalkVersion $0F and $00 eq and [B
						SWFile dup loadobj exch PackInst:DownloadHX2File		
					] [B
						SWFile dup loadobj exch PackInst:DownloadHX3File
					] ifelse
					
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					%PIVar:TalkVersion $0F and $00 eq [B
					%SWFile dup loadobj exch PackInst:DownloadHX2File		
					%] [B
					%SWFile dup loadobj exch PackInst:DownloadHX3File		
					%] ifelse
					
					'Resetting Device...' log     			
					ResetDevice
					1000 Wait
					PackInst:StopProgram	
					
					$0 StartProgram
					%'Waiting for OS reply...' log     
					%[B
					%		2000 Wait      
					%		$0 ReadMemory 0 eq [B 
					%      '...OS started...' log
					%      exitloop 
					%   ] if	     
					%] loop 
					
					
					'Waiting until OS is ready...' log
					15000 wait
%					5000 wait		% extra wait for ML8050
					PackInst:StopProgram
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					%PackInst:StopProgram		
					'Erasing OS updater ...' log     
					$C08000 PackInst:EraseFlash		
					%5000 wait						  
					$C10000 PackInst:EraseFlash		
					%5000 wait						  
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					
					PIVar:PortType 'CAN' eq [B
						MACIDSourceSelAddr MACIDSourceSel WriteWordToElo
						MACIDValueAddr MACIDValue WriteWordToElo
					] if	
					
					'Resetting Device...' log
					ResetDevice                                                                                            
					1000 Wait
					
					'Clearing Parameter Sections...' log
					/ClearFile FilePath OSDir add '\' add 'B1100_ParaClear.HX2' add def
					ClearFile dup loadobj exch PackInst:DownloadHX2File			

					'Resetting Device...' log
					ResetDevice                                                                                            
					1000 Wait
					
				]
				
				% E1250 / E1450 / B8050 / MB8050
				$30 [B
					/OSInstallCommandAddress	$D000181E	def
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						/IPConfigMode IPConfigModeAddr ReadMemory def
						/CfgMasterTimeOut CfgMasterTimeOutAddr ReadMemory def
						/DefGWConfigMode DefGWConfigModeAddr ReadMemory def
						% read the static IP address, network mask and gateway
						/IPAddressLo IPAddressAddr ReadMemory def
						/IPAddressHi IPAddressAddr 2 add ReadMemory def
						/NetMaskLo NetMaskAddr ReadMemory def
						/NetMaskHi NetMaskAddr 2 add ReadMemory def		
						/DefaultGatewayLo DefaultGatewayAddr ReadMemory def
						/DefaultGatewayHi DefaultGatewayAddr 2 add ReadMemory def										    																			
						% read the working IP address, network mask and gateway
						/IPAddressWorkLo IPAddressAddrWorking ReadMemory def
						/IPAddressWorkHi IPAddressAddrWorking 2 add ReadMemory def
						/NetMaskWorkLo NetMaskAddrWorking ReadMemory def
						/NetMaskWorkHi NetMaskAddrWorking 2 add ReadMemory def		
						/DefaultGatewayWorkLo DefaultGatewayAddrWorking ReadMemory def
						/DefaultGatewayWorkHi DefaultGatewayAddrWorking 2 add ReadMemory def										    
					] if	
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressWorkLo WriteWordToElo
						IPAddressAddr 2 add IPAddressWorkHi WriteWordToElo
						NetMaskAddr NetMaskWorkLo WriteWordToElo
						NetMaskAddr 2 add NetMaskWorkHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayWorkLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayWorkHi WriteWordToElo
						% set the config mode to static
						IPConfigModeAddr 2 WriteWordToElo
						DefGWConfigModeAddr 1 WriteWordToElo
					] if		
					
					20 OSLoader:RebootWithoutStart
					
					'Erasing firmware sectors...' log     
					$AFE00000 PackInst:EraseFlash % CURVE
					$AFE10000 PackInst:EraseFlash % CT	
					$A0008000 PackInst:EraseFlash % INTF Tree block 1 		
					$A000C000 PackInst:EraseFlash % INTF Tree block 2		
					$A0010000 PackInst:EraseFlash % INTF Tree block 3		
					$A0020000 PackInst:EraseFlash % MC and INTF Tree		
					$A0040000 PackInst:EraseFlash % INTF
					$A0180000 PackInst:EraseFlash % APPL
					$A0100000 PackInst:EraseFlash % MCSW			
					
					'Downloading OS...' log
					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
									
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					ResetDevice % AutoStart OS Updater after reset
					
					'Waiting for OS reply...' log     
					55000 wait	% to be modified
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File	
					
					IntfSel.Name 'POWERLINK' eq IntfSel.Name 'POWERLINK_ML' eq or[B	
						/ModuleFWType		$0100 def	% PL
						/ModuleFWVersion	$0103 def	% latest compatibel FW Version: Version 1, Subversion 3
						/ModuleHWVersion	$0103 def	% latest HW Version: Version 1, Revision B
						
						/ModuleFWTypeAddress $A3000070 def		
						/ModuleFWVersionAddress $A3000072 def
						/ModuleHWVersionAddress $A3000002 def
						
						/MissingFile '' def
						/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModuleOSUP add def
							ModuleParFile FileExist not [B
							/MissingFile ModuleParFile def			    
						] if 

						/ModuleFWTypeRead  ModuleFWTypeAddress ReadMemory def            
						/ModuleFWVersionRead  ModuleFWVersionAddress ReadMemory def   
						/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def  
						/ModuleType  $A3000000 ReadMemory def   
						
						% check HW module version
						ModuleHWVersionRead ModuleHWVersion ge[B
						% Module HW >= V1.0.2 
							ModuleType $40 eq [B
								ModuleFWTypeRead ModuleFWType ne ModuleFWVersionRead ModuleFWVersion lt ModuleFWVersionRead $FFFF eq or or [B
									'Downloading FPGA image...' log
									ModuleParFile dup loadobj exch PackInst:DownloadHX2File	% load OSUP for FPGA
									
									% Write install new FPGA image controller
									/OSInstallCommand OSInstallCommandAddress ReadMemory def
									/OSInstallCommand OSInstallCommand $0010 or def
									OSInstallCommandAddress OSInstallCommand WriteWordToElo			
									
									ResetDevice % AutoStart FPGA Updater after reset
									'Updating FPGA...' log
									80000 wait
									
									% erase FPGA image	 
									$80040000 PackInst:EraseFlash
									250 wait % give switch some time to process eth frames received while erasing flash which is blocking
									
									% write new FPGA version info
									ModuleFWTypeAddress ModuleFWType WriteWordToElo
									ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
								]
								[B
									% Do nothing. FPGA is already up to date.
								] ifelse 
							] 
							[B
								'Warning: POWERLINK module is not connected!' log				
							] ifelse
						]
						[B
							/Result #0 def 
							'Warning: POWERLINK module HW Version older than V1.0.2!' log	
						]ifelse						
					]if

					IntfSel.Name 'SERCOSIII' eq IntfSel.Name 'SERCOSIII_ML' eq or[B	
						/ModuleFWType		$0200 def		% SC
						/ModuleFWVersion	$0101 def		% Version 1, Subversion 1
						
						/ModuleFWTypeAddress $A3000070 def		
						/ModuleFWVersionAddress $A3000072 def
						
						/MissingFile '' def
						/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModuleOSUP add def
							ModuleParFile FileExist not [B
							/MissingFile ModuleParFile def			    
						] if 

						/ModuleFWTypeRead  ModuleFWTypeAddress ReadMemory def            
						/ModuleFWVersionRead  ModuleFWVersionAddress ReadMemory def   
						/ModuleType  $A3000000 ReadMemory def   
						
						ModuleType $40 eq [B
							ModuleFWTypeRead ModuleFWType ne ModuleFWVersionRead ModuleFWVersion lt ModuleFWVersionRead $FFFF eq or or [B
								'Downloading FPGA image...' log
								ModuleParFile dup loadobj exch PackInst:DownloadHX2File	% load OSUP for FPGA
								
								% Write install new FPGA image controller
								/OSInstallCommand OSInstallCommandAddress ReadMemory def
								/OSInstallCommand OSInstallCommand $0010 or def
								OSInstallCommandAddress OSInstallCommand WriteWordToElo			
								
								ResetDevice % AutoStart FPGA Updater after reset
								'Updating FPGA...' log
								80000 wait
								
								% erase FPGA image	 
								$80040000 PackInst:EraseFlash
								250 wait % give switch some time to process eth frames received while erasing flash which is blocking
								
								% write new FPGA version info
								ModuleFWTypeAddress ModuleFWType WriteWordToElo
								ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
						
							]
							[B
								% Do nothing. FPGA is already up to date.
							] ifelse 
						] 
						[B
							'Warning: SERCOSIII module is not connected!' log				
						] ifelse
						
					]if
					
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressLo WriteWordToElo
						IPAddressAddr 2 add IPAddressHi WriteWordToElo
						NetMaskAddr NetMaskLo WriteWordToElo
						NetMaskAddr 2 add NetMaskHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayHi WriteWordToElo
						% set the config modes to the old values
						IPConfigModeAddr IPConfigMode WriteWordToElo
						CfgMasterTimeOut 0 eq [B						
							CfgMasterTimeOutAddr CfgMasterTimeOut WriteWordToElo		% only if Lock is disabled
						] if 
						DefGWConfigModeAddr DefGWConfigMode WriteWordToElo
					] if																				
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
					
				]
				
				% A1100, C1100
				$50 [B
					/SystemStartupDelayAddress	$300906	def
					/OSInstallCommandAddress	$00F82E	def
					
					'Erasing firmware sectors...' log     
					
					0 1 3 [B
						/SectorIndex exch def
						$D80000 $1000 SectorIndex mul add PackInst:EraseFlash	% CT
					] for	
					0 1 7 [B
						/SectorIndex exch def
						$D88000 $1000 SectorIndex mul add PackInst:EraseFlash	% CURVE
					] for						
					0 1 63 [B
						/SectorIndex exch def
						$C40000 $1000 SectorIndex mul add PackInst:EraseFlash	% MC
					] for	
					0 1 63 [B
						/SectorIndex exch def
						$C80000 $1000 SectorIndex mul add PackInst:EraseFlash	% Intf
					] for	
					0 1 59 [B
						/SectorIndex exch def
						$CC0000 $1000 SectorIndex mul add PackInst:EraseFlash	% App
					] for	
					
					'Downloading OS...' log					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
						
					SystemStartupDelayAddress 0 WriteWordToElo						
					MCInstallValidAddr InstallationValid WriteWordToElo

					ResetDevice % AutoStart OS Updater after reset
					'Waiting for OS reply...' log     
					10000 wait	% to be modified
					
					StartProgram
  
					55000 wait	% to be modified
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing MC Parameter Section...' log
					2 PIVar:TalkIntf.ClearInstancePar
					'Clearing Intf Parameter Section...' log
					3 PIVar:TalkIntf.ClearInstancePar
					'Clearing Appl Parameter Section...' log
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
				]

				% C1250 % E1400V2
				$60 [B
					/OSInstallCommandAddress	$D000181E	def
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						/IPConfigMode IPConfigModeAddr ReadMemory def
						/DefGWConfigMode DefGWConfigModeAddr ReadMemory def
						% read the static IP address, network mask and gateway
						/IPAddressLo IPAddressAddr ReadMemory def
						/IPAddressHi IPAddressAddr 2 add ReadMemory def
						/NetMaskLo NetMaskAddr ReadMemory def
						/NetMaskHi NetMaskAddr 2 add ReadMemory def		
						/DefaultGatewayLo DefaultGatewayAddr ReadMemory def
						/DefaultGatewayHi DefaultGatewayAddr 2 add ReadMemory def										    																			
						% read the working IP address, network mask and gateway
						/IPAddressWorkLo IPAddressAddrWorking ReadMemory def
						/IPAddressWorkHi IPAddressAddrWorking 2 add ReadMemory def
						/NetMaskWorkLo NetMaskAddrWorking ReadMemory def
						/NetMaskWorkHi NetMaskAddrWorking 2 add ReadMemory def		
						/DefaultGatewayWorkLo DefaultGatewayAddrWorking ReadMemory def
						/DefaultGatewayWorkHi DefaultGatewayAddrWorking 2 add ReadMemory def										    
					] if	
					
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressWorkLo WriteWordToElo
						IPAddressAddr 2 add IPAddressWorkHi WriteWordToElo
						NetMaskAddr NetMaskWorkLo WriteWordToElo
						NetMaskAddr 2 add NetMaskWorkHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayWorkLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayWorkHi WriteWordToElo
						% set the config mode to static
						IPConfigModeAddr 2 WriteWordToElo
						DefGWConfigModeAddr 1 WriteWordToElo
					] if		
					
					20 OSLoader:RebootWithoutStart
					10000 wait
							
					'Erasing firmware sectors...' log     
					$AF000000 PackInst:EraseFlash % CURVE
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$AF080000 PackInst:EraseFlash % CT		
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking	

					$80008000 PackInst:EraseFlash % INTF Tree block 1 		
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$8000C000 PackInst:EraseFlash % INTF Tree block 2		
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$80010000 PackInst:EraseFlash % INTF Tree block 3		
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$80020000 PackInst:EraseFlash % MC Tree and INTF Tree		 
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$80040000 PackInst:EraseFlash % INTF
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$80180000 PackInst:EraseFlash % APPL
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$801C0000 PackInst:EraseFlash % APPL
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking
					$80100000 PackInst:EraseFlash % MCSW  	 
					250 wait % give switch some time to process eth frames received while erasing flash which is blocking				
					$80140000 PackInst:EraseFlash % MCSW 			
					
					'Downloading OS...' log
					20 OSLoader:RebootWithoutStart
					10000 wait
					
					SWFile dup loadobj exch PackInst:DownloadHX3File % Load OS Updater 
									
					MCInstallValidAddr InstallationValid WriteWordToElo
					% deactivate install new FPGA image bit to make sure nothing happens if device does not contain an FM04
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $FFEF and def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo		
						
					ResetDevice % AutoStart OS Updater after reset
										
					'Waiting for OS reply...' log     
					65000 wait	% to be modified

					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					IntfSel.Name 'POWERLINK' eq [B	
						/ModuleFWType		$0100 def	% PL
						/ModuleFWVersion	$0201 def	% latest compatibel FW Version: Version 2, Subversion 1
						/ModuleHWVersion	$0103 def	% latest HW Version: Version 1, Revision B
						
						/ModuleFWTypeAddress $A3000070 def		
						/ModuleFWVersionAddress $A3000072 def
						/ModuleHWVersionAddress $A3000002 def
						
						/MissingFile '' def
						/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModuleOSUP add def
							ModuleParFile FileExist not [B
							/MissingFile ModuleParFile def			    
						] if 

						/ModuleFWTypeRead  ModuleFWTypeAddress ReadMemory def            
						/ModuleFWVersionRead  ModuleFWVersionAddress ReadMemory def   
						/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def 
						/ModuleType  $A3000000 ReadMemory def   
						
						% check HW module version
						ModuleHWVersionRead ModuleHWVersion ge[B
						% Module HW >= V1.0.2 
							ModuleType $40 eq [B
								ModuleFWTypeRead ModuleFWType ne ModuleFWVersionRead ModuleFWVersion lt ModuleFWVersionRead $FFFF eq or or [B
									'Downloading FPGA image...' log
									ModuleParFile dup loadobj exch PackInst:DownloadHX2File	% load OSUP for FPGA
									
									% Write install new FPGA image controller
									/OSInstallCommand OSInstallCommandAddress ReadMemory def
									/OSInstallCommand OSInstallCommand $0010 or def
									OSInstallCommandAddress OSInstallCommand WriteWordToElo			
									
									ResetDevice % AutoStart FPGA Updater after reset
									'Updating FPGA...' log
									80000 wait
									
									% erase FPGA image	 
									$80040000 PackInst:EraseFlash
									250 wait % give switch some time to process eth frames received while erasing flash which is blocking
									
									% write new FPGA version info
									ModuleFWTypeAddress ModuleFWType WriteWordToElo
									ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
							
								]
								[B
									% Do nothing. FPGA is already up to date.
								] ifelse 
							] 
							[B
								'Warning: POWERLINK module is not connected!' log				
							] ifelse
						]
						[B
							/Result #0 def 
							'Warning: POWERLINK module HW Version older than V1.0.2!' log	
						]ifelse
					]if

					IntfSel.Name 'SERCOSIII' eq [B	
						/ModuleFWType		$0200 def		% SC
						/ModuleFWVersion	$0202 def		% Version 2, Subversion 1 --> sercon100s V2.11
						
						/ModuleFWTypeAddress $A3000070 def		
						/ModuleFWVersionAddress $A3000072 def
						
						/MissingFile '' def
						/ModuleParFile FilePath IntfSel.IntfDir add IntfSel.IntfModuleOSUP add def
							ModuleParFile FileExist not [B
							/MissingFile ModuleParFile def			    
						] if 

						/ModuleFWTypeRead  ModuleFWTypeAddress ReadMemory def            
						/ModuleFWVersionRead  ModuleFWVersionAddress ReadMemory def   
						/ModuleType  $A3000000 ReadMemory def   
						
						ModuleType $40 eq [B
							ModuleFWTypeRead ModuleFWType ne ModuleFWVersionRead ModuleFWVersion lt ModuleFWVersionRead $FFFF eq or or [B
								'Downloading FPGA image...' log
								ModuleParFile dup loadobj exch PackInst:DownloadHX2File	% load OSUP for FPGA
								
								% Write install new FPGA image controller
								/OSInstallCommand OSInstallCommandAddress ReadMemory def
								/OSInstallCommand OSInstallCommand $0010 or def
								OSInstallCommandAddress OSInstallCommand WriteWordToElo			
								
								ResetDevice % AutoStart FPGA Updater after reset
								'Updating FPGA...' log
								80000 wait
								
								% erase FPGA image	 
								$80040000 PackInst:EraseFlash
								250 wait % give switch some time to process eth frames received while erasing flash which is blocking
								
								% write new FPGA version info
								ModuleFWTypeAddress ModuleFWType WriteWordToElo
								ModuleFWVersionAddress ModuleFWVersion WriteWordToElo
						
							]
							[B
								% Do nothing. FPGA is already up to date.
							] ifelse 
						] 
						[B
							'Warning: SERCOSIII module is not connected!' log				
						] ifelse
						
					]if
					
	
					PIVar:PortType 'ETH' eq ProgFlag not and [B
						IPAddressAddr IPAddressLo WriteWordToElo
						IPAddressAddr 2 add IPAddressHi WriteWordToElo
						NetMaskAddr NetMaskLo WriteWordToElo
						NetMaskAddr 2 add NetMaskHi WriteWordToElo
						DefaultGatewayAddr DefaultGatewayLo WriteWordToElo
						DefaultGatewayAddr 2 add DefaultGatewayHi WriteWordToElo
						% set the config modes to the old values
						IPConfigModeAddr IPConfigMode WriteWordToElo
						DefGWConfigModeAddr DefGWConfigMode WriteWordToElo
					] if																				
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar	
					
					% Write new Firmware message to controller
					/OSInstallCommand OSInstallCommandAddress ReadMemory def
					/OSInstallCommand OSInstallCommand $0001 or def
					OSInstallCommandAddress OSInstallCommand WriteWordToElo				
				]
				
				% E1100
				$20 [B
					ResetDevice
					15000 wait
					ResetDevice
					1500 wait
					PackInst:StopProgram		
					
					'Erasing firmware sectors...' log     
					$10000 PackInst:EraseFlash		
					$30000 PackInst:EraseFlash		
					$40000 PackInst:EraseFlash						
					$D0000 PackInst:EraseFlash		
					$E0000 PackInst:EraseFlash		
					$F0000 PackInst:EraseFlash		
					
					'Downloading OS...' log
					PIVar:TalkVersion $0F and $00 eq [B
						SWFile dup loadobj exch PackInst:DownloadHX2File		
					] [B
						SWFile dup loadobj exch PackInst:DownloadHX3File		
					] ifelse
					
					MCInstallValidAddr InstallationValid WriteWordToElo
					
					%PIVar:TalkVersion $0F and $00 eq [B
					%SWFile dup loadobj exch PackInst:DownloadHX2File
					%] [B
					%SWFile dup loadobj exch PackInst:DownloadHX3File
					%] ifelse
					'Resetting Device...'log     			
					ResetDevice
					15000 Wait
					
					'Starting OS...' log
					$10000 StartProgram
					'Waiting for OS reply...' log     
					[B
						2000 Wait      
						0 ReadMemory 0 eq [B 
							'...OS started...' log
							exitloop 
						] if	     
					] loop 
					'Waiting until OS is ready...' log
					5000 wait
					
					[B
						2000 Wait
						$A2FE ReadMemory 0 eq  [B 
							'...OS is ready' log
							exitloop 
						] if	     
					] loop
					
					MCInstallValidAddr InstallationInvalid WriteWordToElo
					
					'Erasing OS parameter sector...' log     
					$C0000 PackInst:EraseFlash		
					'Downloading OS parameter tree...' log    
					TreeFile dup loadobj exch PackInst:DownloadHX2File                
					
					ResetDevice
					8000 Wait
					
					'Downloading OS default parameters ...' log    
					DefaultParFile dup loadobj exch PackInst:DownloadGR3File
					
					'Resetting Device...' log
					ResetDevice                                                                                            
					
					[B
						3000 Wait
						$A2FE ReadMemory 0 eq  [B 
							'...OS is ready' log
							exitloop 
						] if	     
					] loop     

					'Clearing Parameter Sections...' log
					2 PIVar:TalkIntf.ClearInstancePar
					3 PIVar:TalkIntf.ClearInstancePar
					4 PIVar:TalkIntf.ClearInstancePar					
				]
			]
			[B
				%				
			] case
			
			
		] if
		[A /MissingFile /Result]
	]
	
]