void MainWindow::readData(){ QByteArray bytearray; bytearray = serial->readAll(); qDebug() << "<---- readData():" << bytearray; sp_parseRecievedData(bytearray);}
MainWindow : public QMainWindow
QSerialPort *serial;
HardwarePickDialog *hardware; hardware = new HardwarePickDialog; hardware->mw = this;
bool QWshInstrument::openSerial(){ if (_serialPort.isOpen()) return true; if (_settings->value("SERIALPORT/Portname").isEmpty()) { setLastError("Serial port file not specified (eWSH.conf)"); return false; } _serialPort.setPortName(_settings->value("SERIALPORT/Portname")); if (_serialPort.open(QIODevice::ReadWrite)) { _serialPort.setBaudRate(static_cast<QSerialPort::BaudRate>(_settings->value("SERIALPORT/Baudrate").toInt())); _serialPort.setDataBits(static_cast<QSerialPort::DataBits>(_settings->value("SERIALPORT/Databits").toInt())); _serialPort.setStopBits(static_cast<QSerialPort::StopBits>(_settings->value("SERIALPORT/Stopbits").toInt())); _serialPort.setParity(static_cast<QSerialPort::Parity>(_parityNames.value(_settings->value("SERIALPORT/Parity")))); _serialPort.setFlowControl(static_cast<QSerialPort::FlowControl>(_flowControlNames.value(_settings->value("SERIALPORT/FlowControl")))); _serialPort.flush(); connect(&_serialPort, &QSerialPort::readyRead, this, &QWshInstrument::onDataRecived); connect(this, &QWshInstrument::dataRecieved, this, &QWshInstrument::onRawDataRecieved); return true; } else { setLastError(_settings->value("SERIALPORT/Portname") + " return error - " + _serialPort.errorString()); return false; }}void QWshInstrument::onDataRecived(){ if (_serialPort.bytesAvailable() > 0) { QByteArray newData = _serialPort.readAll(); if (_reciveData) [b]_inputData.append(newData);[/b] else return; QByteArray eor(decode(xmlValue("EOR")).toLatin1()); if (_inputData.indexOf(eor) > -1) { emit dataRecieved(QString(_inputData.left(_inputData.indexOf(eor)).replace('\0', ' ')).trimmed()); emit endInstRead(); _inputData.remove(0, _inputData.indexOf(eor) + eor.size()); } if (_inputData.size() > 5000) _inputData.clear(); }}