def bin2hex(fin, fout, offset=0):
    """Simple bin-to-hex convertor.
    @return     0   if all OK

    @param  fin     input bin file (filename or file-like object)
    @param  fout    output hex file (filename or file-like object)
    @param  offset  starting address offset for loading bin
    """
    h = IntelHex()
    try:
        h.loadbin(fin, offset)
    except IOError:
        e = sys.exc_info()[1]     # current exception
        txt = 'ERROR: unable to load bin file:', str(e)
        print(txt)
        return 1

    try:
        h.tofile(fout, format='hex')
    except IOError:
        e = sys.exc_info()[1]     # current exception
        txt = "ERROR: Could not write to file: %s: %s" % (fout, str(e))
        print(txt)
        return 1

    return 0
def bin2hex ( fin , fout , offset = 0 ) : h = IntelHex ( ) try : h . loadbin ( fin , offset ) except IOError : e = sys . exc_info ( ) [ 1 ] txt = 'ERROR: unable to load bin file:' , str ( e ) print ( txt ) return 1 try : h . tofile ( fout , format = 'hex' ) except IOError : e = sys . exc_info ( ) [ 1 ] txt = "ERROR: Could not write to file: %s: %s" % ( fout , str ( e ) ) print ( txt ) return 1 return 0
Simple bin-to-hex convertor.
    @return     0   if all OK

    @param  fin     input bin file (filename or file-like object)
    @param  fout    output hex file (filename or file-like object)
    @param  offset  starting address offset for loading bin