Exemplo n.º 1
0
def encodePayload(ftype, payload):
    tmpbuf = ftype + pk('<H', len(payload))
    tmpbuf += payload
    crc = CRC16.calcString(tmpbuf, CRC16.INITIAL_MODBUS)
    tmpbuf += pk('<H', crc)
    tmpbuf += pk('B', FRAME_TAIL)
    return tmpbuf
Exemplo n.º 2
0
def addCRC(myHex):
    #takes a hex string and adds a modbus CRC to it
    crc = CRC16.calcString(myHex, CRC16.INITIAL_MODBUS)
    flipped_res = "{0:#0{1}x}".format(crc, 6)
    res = flipped_res[4:6] + flipped_res[2:4]
    add_on = res.decode('hex')
    newHex = myHex + add_on
    return newHex