#include "barcodescanner.h"BarcodeScaner::BarcodeScaner(QObject *parent) : QObject(parent){QSerialPort * serial = new QSerialPort("/dev/ttyS0"); if(!serial->setBaudRate(QSerialPort::Baud9600)) qDebug() << serial->errorString(); if(!serial->setDataBits(QSerialPort::Data8)) qDebug() << serial->errorString(); if(!serial->setParity(QSerialPort::NoParity)) qDebug() << serial->errorString(); if(!serial->setFlowControl(QSerialPort::HardwareControl)) qDebug() << serial->errorString(); if(!serial->setStopBits(QSerialPort::OneStop)) qDebug() << serial->errorString(); if(!serial->open(QIODevice::ReadOnly)) qDebug() << serial->errorString();connect(serial, &QSerialPort::readyRead, this, &BarcodeScaner::read_barecode_scan);}BarcodeScaner::~BarcodeScaner(){ delete serial;}void BarcodeScaner::read_barecode_scan(){ QByteArray datas = serial->readAll(); QString datas_str = QString(datas).left(13); emit resultReady(datas_str);}
C++ (Qt)while(!asleep()) sheep++;
Bashsudo ls -al /dev/ttyS*
cat /etc/os-release