V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
kisscucci
V2EX  ›  Python

数据以 16 进制发送到树莓派

  •  
  •   kisscucci · 2017-08-23 20:01:35 +08:00 · 2682 次点击
    这是一个创建于 2438 天前的主题,其中的信息可能已经有所发展或是发生改变。
    #实例化串口
    import serial;
    ser = serial.Serial('/dev/ttyUSB0', 9600, timeout = 0.5);

    #需要发送的数据
    strnum = 7e 00 08 01 00 02 01 ab cd
    .....
    #这里该如何将 strnum 转换为 16 进制
    strSerial = strnum
    ser.write(strSerial)
    4 条回复    2017-08-24 09:31:07 +08:00
    kisscucci
        1
    kisscucci  
    OP
       2017-08-23 20:06:39 +08:00
    找到方法了:

    import binascii

    def order_list():
    a = 'aa0902630000bb'
    a_list = []
    for i in a.split():
    a_list.append(binascii.a2b_hex(i))
    return a_list

    ser = serial.Serial('/dev/ttyUSB0', 9600)
    ser.writelines(order_list())

    作者:知乎用户
    链接: https://www.zhihu.com/question/51733053/answer/147899163
    jiangbingo
        2
    jiangbingo  
       2017-08-24 09:14:34 +08:00
    nice
    jiangbingo
        3
    jiangbingo  
       2017-08-24 09:14:59 +08:00
    题主在用树莓派开发什么?
    kisscucci
        4
    kisscucci  
    OP
       2017-08-24 09:31:07 +08:00 via iPhone
    @jiangbingo 获取二维码扫描器数据
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2814 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:21 · PVG 20:21 · LAX 05:21 · JFK 08:21
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.