Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QSerialPort USB-SERIAL adapter FTDI

QSerialPort USB-SERIAL adapter FTDI

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    talexcomputers
    wrote on last edited by
    #1

    Hello,

    I try to develop an application to be used with a cash register on windows using QSerialPort. Cash register is connected using USB-SERIAL adapater. I have some problems with serial port:

    1. it call com.write(data); - the data is not send to printer until I call com.flush();
      So if I must send send data to printer it won't work.
    2. I try to read response from printer using readAll, waitForAvailable, read but all of them return nothing.

    I configure com port using settings as description : baud:4800, on stop bit, no parity, no flowcontrol, port name.

    The start sequence to talk with printer is : 0x11 0x11 0x30 0x31
    And she would responde with a block data containing : 000000

    Can you help me with any suggestion how I can get this read information from printer?

    Thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      talexcomputers
      wrote on last edited by
      #2

      Hello,

      Sorry for my late answer.
      I set in in constructor
      @connect(port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handlePortError(QSerialPort::SerialPortError)));@

      Thi is the function I call:
      @connectToPort() {
      port->setPortName("COM1");
      port->setBaudRate(QSerialPort::Baud4800);
      port->setDataBits(QSerialPort::Data8);
      port->setFlowControl(QSerialPort::NoFlowControl);
      port->setStopBits(QSerialPort::OneStop);
      port->setParity(QSerialPort::NoParity);
      if(port->open(QIODevice::ReadWrite)) {
      QMessageBox::information(0,"OPEN INFO", QString::number(port->baudRate()));

              port->write(QByteArray::fromHex("FF FF FF FF FF FF FF FF FF FF 13 13 13"));
              port->flush();
              port->write(QByteArray::fromHex("FF FF FF FF FF FF FF FF FF FF 11 11 30 31 FF FF FF FF FF"));
              port->flush();
      
         
      } else {
          QMessageBox::critical(0, "ERROR", port->errorString());
          port->close();
      }
      

      }
      @

      1. if I don't use port->flush() data is not send to port
      2. when the function try to open port a QSerialPort::SerialPortError signal is emited and throw error Unknown error message ( but the application continues to run and show message box with baudrate

      I make something wrong? Or there is a problem with
      @if(port->open(QIODevice::ReadWrite))@
      or the connection
      @connect(port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(handlePortError(QSerialPort::SerialPortError)));@ ?

      To mention I use USB-SERIAL FTDI adapter.

      Thank you.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kuzulis
        Qt Champions 2020
        wrote on last edited by
        #3

        What version of QtSerialPort did you use?

        1 Reply Last reply
        0
        • T Offline
          T Offline
          talexcomputers
          wrote on last edited by
          #4

          I'm not sure. Is version which came with with Qt 5.3.0 mingw windows binary.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            Probably you need to open() the device at first, and then to configure it, because (as I remember) for 5.3.0 your code is wrong. It is better - to update your Qt to latest.

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xmaze
              wrote on last edited by
              #6

              change to @ QMessageBox::critical(this, tr("Error"), port->errorString());@

              1 Reply Last reply
              0
              • T Offline
                T Offline
                talexcomputers
                wrote on last edited by
                #7

                Thank you for help. I move settings after I open com and also I change critical messagebox to show error. But the problem persist so for the moment I disable error reporting .
                I success print some data on printer ( I must mention this is quite a strange printer - I must put the com->write into a loop until I get an answer from device).

                I will update this night qt to last version and I will we back with more info.

                Thanks a lot.

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  talexcomputers
                  wrote on last edited by
                  #8

                  Hello,

                  I came back with another problem.
                  This is code:
                  @
                  /*
                  This function is called from an while loop and is used to send dataToPrint from main function
                  */

                  bool Driver::print() {

                  QByteArray readData;

                  port = new QSerialPort();
                  port->setPortName("COM1");
                  if (!port->open(QIODevice::ReadWrite) {
                  QMessageBox::information(0, "COM ERROR", port->errorString());
                  }
                  port->setBaudRate(QSerialPort::Baud4800);
                  port->DataBits(QSerialPort::Data8);
                  port->setStopBits(QSerialPort::OneStop);
                  port->setParity(QSerialPort::NoParity);
                  port->setFlowControl(QSerialPort::NoFlowControl);

                  port->write(QByteArray::fromHex("FF FF FF FF FF FF FF FF FF FF 13 13 13 FF FF FF FF FF FF"));
                  port->waiForBytesWritten(2);

                  while (1) {

                  port->write(QByteArray::fromHex("FF FF FF FF FF FF FF FF FF FF 11 11 30 31 FF FF FF FF FF FF"));
                  port->waiForBytesWritten(2);

                  if(port->waitForReadyRead(2)) {
                  dataRead.append(port->readAll());
                  }

                  if(dataRead.length >= 25) {

                  port->write(QByteArray::fromHex("FF FF FF FF FF FF FF FF FF FF 06 FF FF FF FF FF FF"));
                  port->waiForBytesWritten(2);

                  /*
                  If i put QMessageBox::information(0, "title", "bla bla"); then dataIwhistToSend is executed by
                  device ( but not all the time).
                  */
                  port->write(dataIwhistToSend);
                  port->waiForBytesWritten(2);

                  break;
                  }
                  }
                  return true;
                  }

                  @

                  This is situation:
                  This function is called from another function which iterates an message array and send info to device ( to printed).

                  Cases:

                  1 . If i send just one message ( not more) then is working and message is printed.

                  2 . If i send 2 messages (one after another) the second message is not printed.

                  1. If i send 2 messages (one after another) and i put commented QMessageBox the second message sometimes get printed .

                  2. If i send a message this is printed.If i close app and edit to send second message then is printed - seems i can only print just one message when app is running.

                  I test with QThread but i get nothing.

                  I also test with QApplication::proccessEvents() in while loop but nothing.

                  Seems that app cand only print one message . How can i do to get printed more messages?

                  Any suggestions?

                  I use Qt 5.3.2 for windows , on win 8 pro x64. QSerialPort version is 5.2.0.

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved