Send data to herkulex

    Paketize & write the packet to serial port

    Args:
        data (list): the data to be sent

    Raises:
        SerialException: Error occured while opening serial port

def send_data(data):
    """ Send data to herkulex

    Paketize & write the packet to serial port

    Args:
        data (list): the data to be sent

    Raises:
        SerialException: Error occured while opening serial port
    """
    datalength = len(data)
    csm1 = checksum1(data, datalength)
    csm2 = checksum2(csm1)
    data.insert(0, 0xFF)
    data.insert(1, 0xFF)
    data.insert(5, csm1)
    data.insert(6, csm2)
    stringtosend = ""
    for i in range(len(data)):
        byteformat = '%02X' % data[i]
        stringtosend = stringtosend + "\\x" + byteformat

    try:

        SERPORT.write(stringtosend.decode('string-escape'))
        #print stringtosend

    except:
        raise HerkulexError("could not communicate with motors")