def error_service_routine(error_byte_list, type=0):

    if type == 0:

        error = {
            0: "INPUT VOLTAGE ERROR",
            1: "ANGLE LIMIT ERROR",
            2: "OVERHEATING ERROR",
            3: "RANGE ERROR",
            4: "CHECKSUM ERROR",
            5: "OVERLOAD ERROR",
            6: "INSTRUCTION ERROR",
            7: "INVALID ERROR BYTE",
        }

        for i in range(len(error_byte_list)):
            if error_byte_list[i]:
                exception_handling.handle_exception(__name__, error.get(i))
                # CHANGE -- DECIDE ERROR PRIORITY

    elif type == 1:
        error_message = "USER DEFINED ERROR : "
        error = {1: "COMMUNICATION ERROR"}
        error_message += error.get(error_byte_list)
        print(error_message)
def find_dynamixel_and_arduino() :
    global dynamixel_port,arduino_port

    #check if this function called by dynamixel.py or arduino.py
    #return the arduino or arduino or dynamixel port respectively
    stack = inspect.stack()
    if 'dynamixel' in stack[1][1] :
        try :
            ser = serial.Serial(port = dynamixel_port)      #create an instance of the serial.Serial class 
        except : 
            exception_handling.handle_exception('dynamixel','cant connect')
        else :
            print(ser)
            ser.baudrate = 57600                 #set baudrate equal to 57600
            return ser

    elif 'arduino' in stack[1][1] :
        return[arduino]
    else : 
        print('serial_ports_setup.py called by some module\
            other that dynamixel.py or arduino.py')