View Full Version : how sending and recieving file via serial port
Alex22
20th November 2016, 08:26
Hi,
I want to send a file via serial port (rs232) on a device to another device. Any idea for doing this by Qt?
Alex22
22nd November 2016, 10:03
I think after setting some thing like baud rate, bit data, stop bits, parity and etc then i can use this code for sending file:
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)){
qDebug() << "Open file fault";
start(false);
port->close();
return;
}
QByteArray data = file.readAll();
quint64 r = port->write(data);
port->waitForBytesWritten(responseTimeout);
port->waitForReadyRead(responseTimeout);
cout<<r<<endl;
if (r == quint64(data.size())) qDebug() << "Writed text file.";
else qDebug() << "Bytes writed small: " << r;
}
how much mega bytes cab sent by serial port? and could i consider a checksum for sending and recieving all right?
Lesiok
22nd November 2016, 11:54
Serial port can transfer any number of bytes - it is only a pipe. That you have to define a protocol and transmit the data in an orderly manner so that the recipient can interpret them correctly.
PS
An example protocol for file transfer is xmodem or zmodem.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.