使用python xmodem 模块下载及上传文件
生活随笔
收集整理的這篇文章主要介紹了
使用python xmodem 模块下载及上传文件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉自:https://pypi.org/project/xmodem/
?
Documentation available at?http://packages.python.org/xmodem/
Python Package Index (PyPI) page is available at?https://pypi.python.org/pypi/xmodem
Usage
Create a function to get and put character data (to a serial line for example):
>>> import serial >>> from xmodem import XMODEM >>> ser = serial.Serial('/dev/ttyUSB0', timeout=0) # or whatever port you need >>> def getc(size, timeout=1): ... return ser.read(size) or None ... >>> def putc(data, timeout=1): ... return ser.write(data) # note that this ignores the timeout ... >>> modem = XMODEM(getc, putc)Now, to upload a file, use the?send?method:
>>> stream = open('/etc/fstab', 'rb') >>> modem.send(stream)To download a file, use the?recv?method:
>>> stream = open('output', 'wb') >>> modem.recv(stream)For more information, take a look at the?documentation.
總結
以上是生活随笔為你收集整理的使用python xmodem 模块下载及上传文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单片机I/O口推挽输出与开漏输出的区别(
- 下一篇: STM32高级开发(12)-在GCC中使