开发者

pyserial input buffer

开发者 https://www.devze.com 2023-02-15 17:54 出处:网络
I communicate with my HW over USB emulated serial line (FT2232HL). I need to send a bitmap to it, using pySerial and Python Imaging Library. Here is the code:

I communicate with my HW over USB emulated serial line (FT2232HL). I need to send a bitmap to it, using pySerial and Python Imaging Library. Here is the code:


#!/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"

The problem is it doesn't work. I set up a loopback, capturing it with cutecom, but it seems that only about 30kB is transmitted (size of cutec开发者_JS百科om log). I also tried another hardware (Belkin usb-serial converter with F5U103v) with the same result. I suppose it can be some io buffer, but I couldn't find any info about it.

EDIT: the size of the first cutecom log (which contains data received from loopback) is 32725 bytes (sending exactly 42126 bytes). When I run the script twice without truncating the log file, it's size is 81838 bytes. I also checked return value of the device.write() call, it's exactly 42126.


It was my stupid fault. In cutecom I didn't close the log file, so the missing data were in the write() buffer. Device didn't work because of another bug.

0

精彩评论

暂无评论...
验证码 换一张
取 消