<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Motors scan
Scan all ports to find the connected Dynamixel motors
Step1:  Protocol is not the same for XL320 servomotors, set the using_XL320 flag to True if you use them.
Set my_baudrate to the baudrate you are using (1000000 for motors already configured, 57600 for new ones).
Step2:  If the code below gives you an exception, try to restart all other notebooks that may be running, wait 5 seconds and try again.
Step3:  Kill whoever uses the ports (should be used only as last chance try to free the ports).
<ASSISTANT_TASK:>
Python Code:
import pypot.dynamixel
ports = pypot.dynamixel.get_available_ports()
if not ports:
    raise IOError('no port found!')
print 'ports found', ports
Explanation: Motors scan
Scan all ports to find the connected Dynamixel motors
End of explanation
using_XL320 = False
my_baudrate = 1000000
Explanation: Protocol is not the same for XL320 servomotors, set the using_XL320 flag to True if you use them.
Set my_baudrate to the baudrate you are using (1000000 for motors already configured, 57600 for new ones).
End of explanation
for port in ports:
    print port
    try:
        if using_XL320:
            dxl_io = pypot.dynamixel.Dxl320IO(port, baudrate=my_baudrate)
        else:
            dxl_io = pypot.dynamixel.DxlIO(port, baudrate=my_baudrate)
        
        print "scanning"
        found =  dxl_io.scan(range(60))
        print found
        dxl_io.close()
    except Exception, e:
        print e
Explanation: If the code below gives you an exception, try to restart all other notebooks that may be running, wait 5 seconds and try again.
End of explanation
import os
for port in ports:
    os.system('fuser -k '+port);
Explanation: Kill whoever uses the ports (should be used only as last chance try to free the ports).
End of explanation
<END_TASK>