linux - pyserial输入缓冲区

标签 linux buffer pyserial

我通过 USB 模拟串行线 (FT2232HL) 与我的硬件进行通信。我需要使用 pySerial 和 Python 成像库向其发送位图。这是代码:


#!/usr/bin/python2

from PIL import Image
import serial
import string

img = Image.open("db/bitmap.bmp")
img = img.convert("L")
img = img.tostring()

print "img length: " + `len(img)`

device = serial.Serial("/dev/ttyUSB1", 115200, timeout=30)
device.write(size)
device.write(img) #the bitmap has about 40kB
print "image written"

问题是它不起作用。我设置了一个环回,用cutecom捕获它,但似乎只传输了大约30kB(cutecom日志的大小)。我还尝试了另一个硬件(带 F5U103v 的贝尔金 USB 串行转换器),结果相同。我想它可能是一些 io 缓冲区,但我找不到任何有关它的信息。

编辑:第一个cutecom日志(包含从环回接收的数据)的大小是32725字节(正好发送42126字节)。当我运行脚本两次而不截断日志文件时,它的大小为 81838 字节。我还检查了 device.write() 调用的返回值,它恰好是 42126。

最佳答案

这是我愚蠢的错误。在cutecom中,我没有关闭日志文件,因此丢失的数据位于write()缓冲区中。由于另一个错误,设备无法工作。

关于linux - pyserial输入缓冲区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5232903/

相关文章:

linux - 使用 bash shell 解析 CSV 以打印得分最高的行

php - Ajax 被 Wordpress 警告 : solve trough ob_start()? 破坏

python - 微 Controller 和pyserial之间的双向通信

python - pySerial 在运行时中断什么引脚?

python - pyserial,导入错误 : No module named serial

linux - 我怎样才能从文件中 grep 一个更接近的词?

linux - 如何制作脚本或程序来运行某些命令?

c - ARM 交叉编译 GLib 2.33.10,链接器错误

c - 如何刷新结构中的字符串?

在 C 中将未知长度缓冲区复制到固定大小缓冲区