[PLEASE HELP] how to make a barcode receiver?
-
@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
-
@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.
-
@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
-
@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();
-
@jsulm i have fixed it and still nothing
-
finally solved
@Pablo-J-Rogina you were right it's lower level problem
put this in the constructor
and every barcode scan it willqDebug() << scannedData;
Of course need modifying
but here is the codeQSerialPort* 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; // ... }); }