From 5be9ea056632e54fa8390b4fe865950ca3370260 Mon Sep 17 00:00:00 2001 From: Laszlo Papp Date: Fri, 7 Mar 2014 02:39:47 +0000 Subject: Set the port settings before open in the examples Change-Id: I946a3f1d3a64a9b8c0d901347aa8ff5959ebc601 Reviewed-by: Sergey Belyashov --- examples/serialport/cwritersync/main.cpp | 29 +++-------------------------- 1 file changed, 3 insertions(+), 26 deletions(-) (limited to 'examples/serialport/cwritersync/main.cpp') diff --git a/examples/serialport/cwritersync/main.cpp b/examples/serialport/cwritersync/main.cpp index 6433c7c2..4b68315a 100644 --- a/examples/serialport/cwritersync/main.cpp +++ b/examples/serialport/cwritersync/main.cpp @@ -65,34 +65,11 @@ int main(int argc, char *argv[]) QString serialPortName = argumentList.at(1); serialPort.setPortName(serialPortName); - if (!serialPort.open(QIODevice::WriteOnly)) { - standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; - return 1; - } - int serialPortBaudRate = (argumentCount > 2) ? argumentList.at(2).toInt() : QSerialPort::Baud9600; - if (!serialPort.setBaudRate(serialPortBaudRate)) { - standardOutput << QObject::tr("Failed to set 9600 baud for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; - return 1; - } - - if (!serialPort.setDataBits(QSerialPort::Data8)) { - standardOutput << QObject::tr("Failed to set 8 data bits for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; - return 1; - } + serialPort.setBaudRate(serialPortBaudRate); - if (!serialPort.setParity(QSerialPort::NoParity)) { - standardOutput << QObject::tr("Failed to set no parity for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; - return 1; - } - - if (!serialPort.setStopBits(QSerialPort::OneStop)) { - standardOutput << QObject::tr("Failed to set 1 stop bit for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; - return 1; - } - - if (!serialPort.setFlowControl(QSerialPort::NoFlowControl)) { - standardOutput << QObject::tr("Failed to set no flow control for port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; + if (!serialPort.open(QIODevice::WriteOnly)) { + standardOutput << QObject::tr("Failed to open port %1, error: %2").arg(serialPortName).arg(serialPort.errorString()) << endl; return 1; } -- cgit v1.2.3