0

actually i have Qt code. so i need to send data of packets from serial port to terminal and display the data in terminal and also from terminal i need to read data and display it in Qt window page. main problem is, for serial communication to terminal, does we really require serial port should connect to some hardware devices and also.. can we write and read data to terminal without connecting any serial port to hardware devices.

the code from Transceiver layer to serial port

Transceiver::Transceiver(QObject *parent)
:
   QObject(parent),
   mSerial(new QSerialPort(this))
{
    mSerial->setPortName(QString("COM1"));
    qint32 baudRate = 9600;
    mSerial->setBaudRate(baudRate);
    mSerial->setDataBits(QSerialPort::Data8);
    mSerial->setParity(QSerialPort::NoParity);
    mSerial->setStopBits(QSerialPort::OneStop);

    connect
    (
        mSerial,
        &QSerialPort::readyRead,
        [ this ]()
        {
            QByteArray data = mSerial->readAll();
            OnDataReceived( data );
            qDebug()<<data;
        }
    );
}

 Transceiver::~Transceiver()
{
   mSerial->close();
}

void
Transceiver::Send_Data(const QByteArray & inDataStream )
{
   qDebug()<<"Data_in_Transceiver_layer :"<<inDataStream;
   mSerial->write(inDataStream);
}

bool
Transceiver::OpenConnection()
{
    mSerial->open(QIODevice::ReadWrite);
    QSerialPort::SerialPortError error = m`enter code here`Serial->error();
    return error == QSerialPort::NoError;
    //     connect(mSerial, SIGNAL(readyRead()), this, SLOT(read_data()));
}

when i run this it shows QIODevice::write (QSerialPort): device not open

  • What do you mean by "send data of packets from serial port to terminal" ? – mbg033 Apr 07 '17 at 10:49
  • As for error you mentioned - seems you didn't open the port (or there's no such serial port on your PC?) – mbg033 Apr 07 '17 at 10:50
  • i am new to Qt...i have the some data , so what i wanted is that data need to written on terminal and from terminal we need to read data and display it in qt window page...what all are the requirement like does we need to connect hardware devices to serial port ...but i didn't connected any devices to com port... – Shashidhar Gouda Apr 07 '17 at 11:00
  • I think that your problem is not related to Qt at all. You probably need some virtual serial ports connected to each other so you can write to one of them and read from the other. https://freevirtualserialports.com/ – ni1ight Apr 07 '17 at 11:42
  • You need to be reading/writing directly from the `tty` device, that is from file descriptor 0 and writing to file descriptor 1. [This answer](http://stackoverflow.com/a/20642135/1329652) demonstrates how to get notified when data is available from the console. If you insist I can write an example better suited to your problem. This is on Unix, right? – Kuba hasn't forgotten Monica Apr 07 '17 at 16:11
  • Actually I need to send data from Qt output and display on some terminal and from terminal I need to read data and display on Qt application window. How to do.. Please anyone help me regarding this.. – Shashidhar Gouda Apr 08 '17 at 06:30

0 Answers0