[PLEASE HELP] how to make a barcode receiver?
-
@JKSH said in [PLEASE HELP] how to make a barcode receiver?:
Qt Serial Port works with serial ports. A USB port is not a serial port.
thats not true. Of course QtSerialPort works with USB.
USB = Universal Serial BusThe code above i've posted definitively works with a USB Barcode scanner and i used it myself already.
-
@raven-worx
I'm using ubuntu now -
Hi,
It's QSerialPortInfo.
-
i dosn't do any thing it always execute "else"
QSerialPort::SerialPortError(DeviceNotFoundError) -
And what is the error ?
-
@raven-worx said in [PLEASE HELP] how to make a barcode receiver?:
thats not true. Of course QtSerialPort works with USB.
USB = Universal Serial BusWhat? QtSerialPort works only with serial ports. It has nothing common with USB... Please don't confuse peoples. ;)
-
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
QSerialPort::SerialPortError(DeviceNotFoundError)
Well, that means your program can't find a port called COM4. Read the comments in @raven-worx's code and think about what they are asking you to do.
What is the name of the port that your scanner is connected to? https://www.cyberciti.biz/faq/find-out-linux-serial-ports-with-setserial/
@raven-worx said in [PLEASE HELP] how to make a barcode receiver?:
The code above i've posted definitively works with a USB Barcode scanner and i used it myself already.
My apologies; I didn't read the codes or think of the scenario that @mrjj highlighted in his last post.
If the barcode scanner implements RS232-over-USB, then you're right -- Qt Serial Port can indeed work with the scanner via the USB port.
QtSerialPort works with USB.
USB = Universal Serial BusEven though they both have "serial" in their names, Universal Serial Bus is completely unrelated to old-school serial ports. The term "serial port" usually refers to an RS-232 port: https://en.wikipedia.org/wiki/Serial_port
A USB device can be programmed to emulate serial port comms, but these are the minority. You cannot, for example, use Qt Serial Port to read your USB keyboard.
-
@JKSH i didn't worked
i tried form com 1 to com 18
non of them worked -
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
@JKSH i didn't worked
i tried form com 1 to com 18
non of them workedWhat is the name of the port that your scanner is connected to? COMX is a Windows name. Linux names are different.
Read https://www.cyberciti.biz/faq/find-out-linux-serial-ports-with-setserial/ to find the name on your Ubuntu machine.
-
same error
i tried from ttyS0 to ttyS5 didn't work -
@davidlabib said in [PLEASE HELP] how to make a barcode receiver?:
same error
i tried from ttyS0 to ttyS5 didn't workYou 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 -
@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 availableDid you choose the correct settings? How is your scanner configured for the following?
- Baud rate
- Parity
- Data bits
- Stop bits
- Flow control
-
@JKSH
Baud rate 115200 -
@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. -
@aha_1980 yes i don't have
but i use sudo -
@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.
-
solved PermissionError
now iam stuck in thisQSerialPort* 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