【发布时间】:2015-01-24 10:23:47
【问题描述】:
我尝试从 arduino(20KB - JPEG - 使用 SD 库)读取 SD 卡图像并通过 Xbee(系列 2)传输由于 xbee 的限制,必须中断到 60 个字节并发送直到完整的文件发送。我认为,图像存储在 ASCII 字符中。
void setup() {
Serial.begin(115200);
if (!SD.begin()) {
Serial.println("begin failed");
return;
}
file = SD.open("PIC00.JPG");
}
void loop() {
Serial.flush();
char buf[64];
if(file) {
while (file.position() < file.size())
{
while (file.read(buf, sizeof(buf)) == sizeof(buf)) // read chunk of 64bytes
{
Serial.write(buf); // Send to xbee via serial
delay(50);
}
}
file.close();
} }
但是这种方法,我在串行写入时看不到完整的图像传输。过了一会儿,我才知道图像的开头是 Y(ascii 字符)和 U(结束字符)。我只能看到结束开始字符 Y 看不到正确的结束字符。
请指教...努力解决这个问题。非常感谢...
【问题讨论】: