[D

	/RebootWithoutStart [P
		[A counts ]
		1 RebootDevice
		2000 wait
		/Stopped #0 def
		counts [B 
			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 are existing 	
%		/MCSWFileName 'MCSW1100_' def
%		/MCTreeFileName 'MCTr1100_' def	
		
		/Result #1 def
		/MissingFile '' def
		
		/SWFile FilePath MCDir add '\' add MCSWFileName add def
		/SWFile SWFile 'S' add EloSWVersion 16 cvrs add def
		/SWFile SWFile '_V' add MCSWVersion cvs add 'S' add MCSWSubVersion cvs add def 
		MCSWBetaInfo '' ne [B
			/SWFile SWFile '_' add MCSWBetaInfo add def
		] if
		/SWFile SWFile '.HX3' add def
		/TreeFile FilePath MCDir add '\' add MCTreeFileName add def
		/TreeFile TreeFile 'S' add EloSWVersion 16 cvrs add def
		/TreeFile TreeFile PowerExtension add IntfMCTreeExt add def
		/TreeFile TreeFile '_V' add MCTreeVersion cvs add 'S' add MCTreeSubVersion cvs add def 
		MCTreeBetaInfo '' ne [B
			/TreeFile TreeFile '_' add MCTreeBetaInfo add def
		] if
		/TreeFile TreeFile '.HX2' add def
		
		/DefaultParFile FilePath MCDir add '\' add MCTreeFileName add def
		/DefaultParFile DefaultParFile 'S' add EloSWVersion 16 cvrs add def
		/DefaultParFile DefaultParFile PowerExtension add IntfMCTreeExt add def
		/DefaultParFile DefaultParFile '_V' add MCTreeVersion cvs add 'S' add MCTreeSubVersion cvs add def 
		MCTreeBetaInfo '' ne [B
			/DefaultParFile DefaultParFile '_' add MCTreeBetaInfo 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 LoadFlag and [B
			'Erasing MC firmware sector...' log     
			2 TalkIntf.ClearInstanceAll
			
			%PIVar:TalkVersion $F0 and $30 eq
			%PIVar:TalkVersion $F0 and $50 eq or
			%PIVar:TalkVersion $F0 and $60 eq or [B
			%	20 MCLoader:RebootWithoutStart
			% ] if
			
%			'Downloading MC software...' log
			'Downloading ' SWFile add log
			SWFile dup loadobj exch PackInst:DownloadHX3File
%			'Downloading MC parameter tree...' log     		
			'Downloading ' TreeFile add log     		
			TreeFile dup loadobj exch PackInst:DownloadHX2File		
			'Updating UPID list...' log
			TalkIntf.UpdateUPIDList
			TalkIntf.GetResult 0 ne [B 
				ResetDevice 
				10000 wait
			] if      
%			'Downloading MC default parameters...' log
			'Downloading ' DefaultParFile add log
			DefaultParFile dup loadobj exch PackInst:DownloadGR3File					
		] if
		[A /MissingFile /Result]
	]
]