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. [PLEASE HELP] how to make a barcode receiver?
Forum Updated to NodeBB v4.3 + New Features

[PLEASE HELP] how to make a barcode receiver?

Scheduled Pinned Locked Moved Solved General and Desktop
57 Posts 9 Posters 14.4k Views 4 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.
  • JKSHJ JKSH

    @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

    same error
    i tried from ttyS0 to ttyS5 didn't work

    You didn't answer my question. What is the name of the port that your scanner is connected to?

    Also, what does QSerialPortInfo::availablePorts() give you? http://doc.qt.io/qt-5/qserialportinfo.html#availablePorts

    ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #45

    @JKSH ok i could find the right port and passed from

    if( port->open(QSerialPort::ReadOnly) )
    

    now I'm stuck on

    if( !port->bytesAvailable() )
                      return;
    

    it always return
    witch mean no bytes is available

    JKSHJ 1 Reply Last reply
    0
    • ? A Former User

      @JKSH ok i could find the right port and passed from

      if( port->open(QSerialPort::ReadOnly) )
      

      now I'm stuck on

      if( !port->bytesAvailable() )
                        return;
      

      it always return
      witch mean no bytes is available

      JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #46

      @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

      now I'm stuck on

      if( !port->bytesAvailable() )
                        return;
      

      it always return
      witch mean no bytes is available

      Did you choose the correct settings? How is your scanner configured for the following?

      • Baud rate
      • Parity
      • Data bits
      • Stop bits
      • Flow control

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #47

        @JKSH
        Baud rate 115200

        aha_1980A 1 Reply Last reply
        0
        • ? A Former User

          @JKSH
          Baud rate 115200

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #48

          @davidlabib

          I guess you don't have permission to use the serial port.

          Please type: ls -l /dev/<your-serial-port-name> in a terminal and post the output here.

          Qt has to stay free or it will die.

          1 Reply Last reply
          1
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #49

            @aha_1980 yes i don't have
            but i use sudo

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #50

              Don't develop as super-user.

              The command @aha_1980 will show the user and group affected to the device. Add your own user to that group, then log out and log in again and you will have access to the device.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              4
              • aha_1980A Offline
                aha_1980A Offline
                aha_1980
                Lifetime Qt Champion
                wrote on last edited by
                #51

                @davidlabib Better add your user to the group dialout and reboot your computer.

                Of course sudo works, but may give new problems.

                As @JKSH wrote, not only baudrate is important.

                I'd suggest to use a terminal program first to verify your scanner works correctly. Then use the same parameters for your code.

                Qt has to stay free or it will die.

                1 Reply Last reply
                4
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by A Former User
                  #52

                  solved PermissionError
                  now iam stuck in this

                     QSerialPort* port = new QSerialPort( this );
                     QSerialPortInfo::availablePorts();
                     port->setBaudRate( QSerialPort::Baud115200 ); // possible something else, also check the manual
                     port->setPort( QSerialPortInfo("ttyACM0") ); // COM port - check Device Manager for connected port
                     QSerialPortInfo::availablePorts();
                     if( port->open(QSerialPort::ReadOnly) )
                     {
                         ui->label->setText("port opended sucssefully");
                             connect(port, &QSerialPort::readyRead, this, [port]() {
                                   if( !port->bytesAvailable() )
                                       qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data
                                        return;
                                   const QByteArray scannedData = port->readAll();
                                   // ...
                             });
                     }
                     else
                     {
                         ui->label->setText("Error");
                         qDebug() << port->error();
                         QSerialPortInfo::availablePorts();
                     }
                  }
                  

                  also it will execute this if i clicked a button what if the user didn't click

                  jsulmJ 1 Reply Last reply
                  0
                  • ? A Former User

                    solved PermissionError
                    now iam stuck in this

                       QSerialPort* port = new QSerialPort( this );
                       QSerialPortInfo::availablePorts();
                       port->setBaudRate( QSerialPort::Baud115200 ); // possible something else, also check the manual
                       port->setPort( QSerialPortInfo("ttyACM0") ); // COM port - check Device Manager for connected port
                       QSerialPortInfo::availablePorts();
                       if( port->open(QSerialPort::ReadOnly) )
                       {
                           ui->label->setText("port opended sucssefully");
                               connect(port, &QSerialPort::readyRead, this, [port]() {
                                     if( !port->bytesAvailable() )
                                         qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data
                                          return;
                                     const QByteArray scannedData = port->readAll();
                                     // ...
                               });
                       }
                       else
                       {
                           ui->label->setText("Error");
                           qDebug() << port->error();
                           QSerialPortInfo::availablePorts();
                       }
                    }
                    

                    also it will execute this if i clicked a button what if the user didn't click

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #53

                    @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

                    qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data

                    Do you mean the slot is called but bytesAvailable() returns 0? If so what does

                    qDebug() << port->error();
                    

                    print out?

                    "also it will execute this if i clicked a button what if the user didn't click" - yes, if user does not click the button it will not be executed.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    ? 1 Reply Last reply
                    0
                    • jsulmJ jsulm

                      @davidlabib said in [PLEASE HELP] how to make a barcode receiver?:

                      qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data

                      Do you mean the slot is called but bytesAvailable() returns 0? If so what does

                      qDebug() << port->error();
                      

                      print out?

                      "also it will execute this if i clicked a button what if the user didn't click" - yes, if user does not click the button it will not be executed.

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #54

                      @jsulm said in [PLEASE HELP] how to make a barcode receiver?:

                      Do you mean the slot is called but bytesAvailable() returns 0? If so what does

                      qDebug() << port->error();
                      

                      print out?

                      nothing

                      jsulmJ 1 Reply Last reply
                      0
                      • ? A Former User

                        @jsulm said in [PLEASE HELP] how to make a barcode receiver?:

                        Do you mean the slot is called but bytesAvailable() returns 0? If so what does

                        qDebug() << port->error();
                        

                        print out?

                        nothing

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #55

                        @davidlabib Looks like the slot isn't called.
                        This code is broken:

                        if( !port->bytesAvailable() )
                            qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data
                            return;
                        const QByteArray scannedData = port->readAll();
                        

                        It shoud be

                        if( !port->bytesAvailable() ) {
                            qDebug() << port->error(); ////////// I'm stuck here it seems that there is no data
                            return;
                        }
                        const QByteArray scannedData = port->readAll();
                        

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        2
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by A Former User
                          #56

                          @jsulm i have fixed it and still nothing

                          1 Reply Last reply
                          0
                          • ? Offline
                            ? Offline
                            A Former User
                            wrote on last edited by A Former User
                            #57

                            finally solved
                            @Pablo-J-Rogina you were right it's lower level problem
                            put this in the constructor
                            and every barcode scan it will

                            qDebug() << scannedData;
                            

                            Of course need modifying
                            but here is the code

                                QSerialPort* port = new QSerialPort( this );
                                QSerialPortInfo::availablePorts();
                                port->setBaudRate( QSerialPort::Baud115200 ); // possible something else, also check the manual
                                port->setPort( QSerialPortInfo("COMX") ); // COM port - check Device Manager for connected port
                                if( port->open(QSerialPort::ReadOnly) )
                                {
                                    ui->label->setText("hi");
                                        connect(port, &QSerialPort::readyRead, this, [port]() {
                                              const QByteArray scannedData = port->readAll();
                                              qDebug() << scannedData;
                                              // ...
                                        });
                                }
                            
                            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