[B
	

	/EraseFlashSectorsArray [A	% PFlash 0
								$80008000 $8000C000
								$80010000 $80014000 $80018000 $8001C000
								$80020000 $80040000 $80080000 $800C0000
								$80100000 $80140000 $80180000 $801C0000
								
								% PFlash 1
								$80800000 $80804000 $80808000 $8080C000
								$80810000 $80814000 $80818000 $8081C000
								$80820000 $80840000 $80880000 $808C0000
								$80900000 $80940000 $80980000 $809C0000
								
								% DFlash
								$AF000000 $AF080000
								] def
	
	% start of script
	
	'PackInst' import

	/LogMemo Create:LogMemo def
	/Log [B LogMemo.Log ] def
	/LogError [B
		% font color is set for the whole window, so no color reset shall be done
		$000000FF LogMemo.SetFontColor
		Log
	] def
	10 LogMemo.SetFontSize
	LogMemo.Show

	
	% Chose the serial port for the communication with the servo controller
	PackInst:_SelectCommPort [B
		/PortType exch def
		/ComPort exch def
		/PortDefined TRUE def
	] if
	
	% needed by PackInst in order to know that there is a ROS
	/UPROSExt 'UPROS_' def
	
	PortDefined [B
	
		% Configure and open the serial port
		/Comm Create:Comm def
		%ComPort 38400 Comm.Open
		
		
		% create talk interface
		/DevName 'TestDevice' def        	        	
		/Device Create:Device def
		'PortName' ComPort 1 DevName 'LinMotInstall' Device.CreateDevice
		DevName /PackInst:OnMessageCallback PackInst:Init
		/Result exch def
		
		
		Result [B
			
			EraseFlashSectorsArray
			[B
				/addr exch def
				'Erasing ' addr 16 cvrs add log
				
				addr PackInst:EraseFlash
			] forall
			
		] if
	
		
		Device.DestroyDevice
		Comm.Close
		
		Result [B
		  'Flash successfully erased!' log
		]
		[B
			'Error or no response' LogError
			'Flash erase: failed!' LogError
		] ifelse
	]
	[B
		'Flash erase: failed! No port has been selected!' LogError
	] ifelse  

	LogMemo.Remain
]