void MainWindow::on_RegisterButton_clicked() { int bytes_available; int i; for(i = 0; i < FINGERS && positions[i] == false; i++){ if((i == (FINGERS - 1)) && positions[i] == false){ QMessageBox::warning(this, tr("Bio-guised"), tr("Please register at least 1 fingerprint"), QMessageBox::Ok); return; } } MainWindow::hide(); QSerialPort serial; serial.setPortName("COM6"); serial.open(QIODevice::ReadWrite); serial.setBaudRate(QSerialPort::Baud9600); serial.setDataBits(QSerialPort::Data8); serial.setParity(QSerialPort::NoParity); serial.setStopBits(QSerialPort::OneStop); serial.setFlowControl(QSerialPort::NoFlowControl); qDebug() << "connected"; while(!serial.isWritable()); QByteArray index("v"); serial.write(index); do{ serial.waitForReadyRead(1000); bytes_available = serial.bytesAvailable(); }while(bytes_available <= 0); QByteArray byte_array = serial.read(bytes_available); qDebug() << byte_array; char *rawData = byte_array.data(); int data = (int)*rawData; delay(2000); while(!serial.isWritable()); QByteArray index2("k"); serial.write(index2); serial.waitForReadyRead(2000); bytes_available = serial.bytesAvailable(); QByteArray byte_array2 = serial.read(bytes_available); qDebug() << byte_array2; std::string key = byte_array2.toStdString(); biomodel->encryptKey(key); if(data > 0 ) bioGuised->show(); }
void onRxData() { if (m_port.bytesAvailable() < 9) return; if (m_port.error() != QSerialPort::NoError) return; if (! check(m_port.peek(9))) return setIoStatus(ChecksumError); uint8_t dummy; m_str >> m_address >> dummy >> m_status >> dummy >> m_value; setIoStatus(Ok); }
void MainWindow::gatherInfo(){ int i, bytes_available; // ConnectionThread connection; fingerprints = new FingerprintScanPopup[10]; bioGuised = new BioGuised; biomodel = new BioModel; // Initialize Serial QSerialPort serial; serial.setPortName("COM6"); serial.open(QIODevice::ReadWrite); serial.setBaudRate(QSerialPort::Baud9600); serial.setDataBits(QSerialPort::Data8); serial.setParity(QSerialPort::NoParity); serial.setStopBits(QSerialPort::OneStop); serial.setFlowControl(QSerialPort::NoFlowControl); qDebug() << "connected"; //delay(500); while(!serial.isWritable()); QByteArray index("n"); serial.write(index); for(int i = 0; i < FINGERS; i++){ do{ serial.waitForReadyRead(1000); bytes_available = serial.bytesAvailable(); }while(bytes_available <= 0); QByteArray byte_array = serial.read(bytes_available); // qDebug() << byte_array; char *rawData = byte_array.data(); int data = (int)*rawData; qDebug() << data; if(data == 1){ positions[i] = true; } else{ positions[i] = false; } if(serial.flush()) { qDebug() << "flushed ok" << endl; } } serial.close(); //std::thread first(); // connection.start(); i = 0; int flag = 0; do{ if(positions[i] == true){ on_RegisterButton_clicked(); flag = 1; } }while( i < FINGERS && positions[i++] == false && flag == 0); // run(); }