[B
  'PackInst' import  
 
  /LogMemo Create:LogMemo def
  /Log [B LogMemo.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    
    /Continue #1 def
    PortType 'CAN' eq [B
    	PackInst:_SelectDeviceMACID [B  
     	  /DeviceMACID exch def	
     	 	%/DeviceName 'InstallDevice' PortName add '_ID: ' add DeviceMACID cvs add def
    	][B    	
    	  /Continue #0 def
    	] ifelse    
    ][B
      PortType 'ETH' eq [B
        PackInst:_SelectIPAddress [B  
       	  /IPAddress exch def	
       	 	%/DeviceName 'InstallDevice' PortName add '_IP: ' add IPAddress cvs add def
    	  ][B    	
    		  /Continue #0 def
    	  ] ifelse       
      ]
      [B
     	  /DeviceMACID 0 def	        	
       	%/DeviceName 'InstallDevice' PortName add def
      ] ifelse	 
    ] ifelse
    Continue [B
      PortType 'CAN' eq [B
        % Configure and open the CAN port
		    /CANComPort Create:CANComPort def
		    CANComPort.Open not [B
		      'Firmware stop: aborted! CAN port cannot been opened!' log                   		    		      
		    ]
		    [B
		      'Sending stop command and waiting for response from controller...' log      
		      /NumOfAttemps 0 def
		      20 [B
		        /NumOfAttemps NumOfAttemps 1 add def
		        /Ident 0 def
		        /Ident Ident 8 25 shl add def
		        /Ident Ident $FF 13 shl add def
		        /Ident Ident DeviceMACID 5 shl add def
		        Ident 1 $21 chr CANComPort.SendData 	
		        500 CANComPort.WaitResponse
		        CANComPort.GetExpired not [B ExitLoop ] if
		      ] repeat
		      NumOfAttemps 20 lt [B
		        'Firmware successfully stopped!' log
		      ]
		      [B
		        'Firmware stop: failed! No response from controller!' log      
		      ] ifelse  
		      CANComPort.Close		      
		    ] ifelse 
      ]
      [B
        PortType 'ETH' eq [B
                						
    	  ]
    	  [B    	
		      % Configure and open the serial port
		      /Comm Create:Comm def
		      ComPort 38400 Comm.Open
		      % Create a buffer for receive the data
		      /RxBuf 100 Comm.CreateBuffer def
		      RxBuf Comm.ClearBuffer
		      100 wait
		      'Sending stop command and waiting for response from controller...' log      
		      /NumOfAttemps 0 def
		      20 [B
		        /NumOfAttemps NumOfAttemps 1 add def
		        $A5 chr $01 chr add $21 chr add $21 chr add Comm.SendString
		        RxBuf 500 $A5 chr Comm.WaitForChar
		        Comm.GetExpired not [B ExitLoop ] if
		      ] repeat
		      NumOfAttemps 20 lt [B
		        'Firmware successfully stopped!' log
		      ]
		      [B
		        'Firmware stop: failed! No response from controller!' log      
		      ] ifelse  
		      Comm.Close
    	  ] ifelse       
      ] ifelse
    ]
    [B
      'Firmware stop: aborted! No port has been selected!' log        
    ] ifelse  
  ]
  [B
    'Firmware stop: aborted! No port has been selected!' log  
  ] ifelse
             
  LogMemo.Remain  
]