[P
  [A ]
  
  [B

    /FirmwareType 			$0100 def
	/FirmwareTypeAddress 	$A3000070 def
	/FirmwareVersionAddress $A3000072 def	
	
    'PackInst' import
	
    /PackInst:OnMessageCallback PackInst:InitNew
    /log [B 'LogTxt' exch PackInst:OnMessageCallback ] def
	
	/TalkIntf PIVar:TalkIntf def
				
	/WriteWordToElo [B
		TalkIntf.WriteMemory
	] def
	
	/ReadMemory [B 
		TalkIntf.ReadMemory     
		TalkIntf.GetResult 0 eq 
		[B TalkIntf.GetData ]
		[B 'TalkError: ' TalkIntf.GetResult cvs add raisese ] ifelse
	] def
      

        'Start Download?' 'C' 'YA' msgdlg [B
          
          'Y' [B
		  
			/ModuleType  $A3000000 ReadMemory def    
			
			ModuleType $40 eq [B
				/ModuleHWVersion	$0103 def		% latest HW Version: Version 1, Revision B
				/ModuleHWVersionAddress $A3000002 def
				/ModuleHWVersionRead  ModuleHWVersionAddress ReadMemory def  
						
				ModuleHWVersionRead ModuleHWVersion ge[B
				% Module HW >= V1.0.2 
					/FirmwareVersion 	$0201 def % Version 2, Subversion 1
				    /FileName 	'EPLHUB_FPGA_V2_0.HX2' def
				    'Download: ' FileName extfilename add log
					/Data FileName loadobj def
				]
				[B
					'Download aborted: Wrong Module HW Version!' log
				]ifelse
			
				'Programming FPGA...' log     	
				/JTAG_START_EXECUTION $A5A5 def
				/JTAG_Execute $90000200 def
				JTAG_Execute JTAG_START_EXECUTION WriteWordToElo						
				Data FileName PackInst:DownloadHX2File
				
				FirmwareTypeAddress FirmwareType WriteWordToElo	
				FirmwareVersionAddress FirmwareVersion WriteWordToElo	
				
			]
			[B
			  'Download aborted: Wrong Module Type!' log
			] ifelse 
			
			
          ]

          'A' [B
            /Msg 'Download aborted by user'
            /SuppressAbortMsg #1
            2 cdict raise
          ]

        ][B
        ] case
		
		PackInst:Exit
		
  ] [B
    /Dict exch def
    Dict /SuppressAbortMsg known [B
      Dict.Msg log
      PIVar:LogMemo.Remain
    ] [B
      Dict.Msg log
      'Download aborted' log
      PIVar:LogMemo.Remain
    ] ifelse
  ] tryexcept

  [A ]
  
]