c++ - Sending more than one character from Qt to Arduino -
first of all: sorry i'm not english.
i'm making serial communication between qt (c++) , arduino. first tried send 1 character ('1') arduino turn led on , worked. want send more 1 character. how can send more characters each character variable in arduino code?
this qt code 1 character:
void mainwindow::on_pushbutton_clicked() { serial.setportname("com17"); serial.setbaudrate(qserialport::baud9600); serial.setdatabits(qserialport::data8); serial.setparity(qserialport::noparity); serial.setstopbits(qserialport::onestop); serial.setflowcontrol(qserialport::noflowcontrol); serial.open(qiodevice::readwrite); serial.write("'0'"); }
i suppose using qserialport class qt.
as can see documentation (http://doc.qt.io/qt-5/qserialport-members.html), have 3 functions overloading write(...), super class
write(const char *, qint64) : qint64 write(const char *) : qint64 write(const qbytearray &) : qint64
what sending "'0'"
string composed 3 characters, 2 single quotes , number zero.
if you'd send more 1 character, have pack characters qbytearray.
you'll have call serial.write() in following way
qbytearray ba; ba.append('1') ba.append('2') ba.append('3') etc... serial.write(ba)
in way send data composed 3 bytes { '1', '2', '3' }
Comments
Post a Comment