foreach (const QSerialPortInfo &info, BlinkyTape::findBlinkyTapeBootloaders()) {
     report.append("  " + info.portName() + "\r");
     report.append("    Manufacturer: " + info.manufacturer() + "\r");
     report.append("    Description: " + info.description() + "\r");
     report.append("    VID: 0x" + QString::number(info.vendorIdentifier(),16) + "\r");
     report.append("    PID: 0x" + QString::number(info.productIdentifier(),16) + "\r");
 }
Esempio n. 2
0
void StatusBar::setDeviceInfo(const QSerialPort *port)
{
    QSerialPortInfo info = QSerialPortInfo(*port);
    if (info.isValid()) {
        QString deviceInfo = QString("%1 %2 @%3").arg(info.manufacturer()).arg(info.description()).arg(info.portName());
        m_lb_deviceName->setText(deviceInfo);
    }
}
Esempio n. 3
0
QT_USE_NAMESPACE

void CardReader::PrintPortInfo(const QSerialPortInfo &info)
{
    QTextStream cout(stdout);
    cout << "Name        : " << info.portName() << endl
         << "Description : " << info.description() << endl
         << "Manufacturer: " << info.manufacturer() << endl
         << "Is busy     : " << info.isBusy() << endl
         << endl;
}
Esempio n. 4
0
void StatusBar::setToolTip(const QSerialPort *port)
{

    QSerialPortInfo info = QSerialPortInfo(*port);
    if (info.isValid()) {
        QString deviceInfo = QString("%1 %2\n%3:%4 "
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
                                     )
#else
                                     "# %5")
#endif
                                 .arg(info.manufacturer())
                                 .arg(info.description())
                                 .arg(info.vendorIdentifier())
                                 .arg(info.productIdentifier())
#if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
                ;
#else
                                 .arg(info.serialNumber());
int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    // Get list of all serial ports
    QList<QSerialPortInfo> serialInfoList = QSerialPortInfo::availablePorts();
    qDebug();
    if (!serialInfoList.size() > 0)
    {
        qDebug() << "no serial ports found";
        return app.exec();
    }
    else
    {
        qDebug() << "List all serial ports";
        qDebug() << "---------------------";
        for (int i=0; i<serialInfoList.size(); i++)
        {
            QSerialPortInfo serialInfo = serialInfoList.at(i);
            qDebug() << "port: " << i;
            qDebug() << "  name:          " << serialInfo.portName();
            qDebug() << "  description:   " << serialInfo.description();
            qDebug() << "  manufacturer:  " << serialInfo.manufacturer();
            //qDebug() << "  serial Number: " << serialInfo.serialNumber();
            if (serialInfo.hasVendorIdentifier())
            {
                qDebug() << "  vendorId:     " << serialInfo.vendorIdentifier();
            }
            if (serialInfo.hasProductIdentifier())
            {
                qDebug() << "  producId:     " << serialInfo.productIdentifier();
            }
            qDebug();
        }
    }

    qDebug() << "opening panels controller";
    QSerialPortInfo serialInfo = serialInfoList.at(0);
    bias::PanelsController pcontrol(serialInfo);
    bool isOpen = pcontrol.open();
    if (!isOpen)
    {
        qDebug() << "  unable to open device";
        return app.exec();
    }
    qDebug() << "  device opened";

     if (true)
    {
        qDebug() << "  blink led";
        pcontrol.blinkLED();
        QThread::msleep(4000);
    }

    // Test allOn, allOff 
     if (true)
    {
        for (int i=0; i<5; i++)
        {
            qDebug() << "  all on";
            pcontrol.allOn();
            QThread::msleep(500);
            qDebug() << "  all off";
            pcontrol.allOff();
            QThread::msleep(500);
        }
    }

    // Test setToGrayLevel
     if (true)
    {
        for (int i=0; i<2; i++)
        {
            for (int j=1; j<bias::PanelsController::NUM_GRAY_LEVEL; j++)
            {
                qDebug() << "  set to gray level = " << j;
                pcontrol.setToGrayLevel(j);
                QThread::msleep(100);
            }
            for (int j=bias::PanelsController::NUM_GRAY_LEVEL-1; j>=0; j--) 
            {
                qDebug() << "  set to gray level = " << j;
                pcontrol.setToGrayLevel(j);
                QThread::msleep(100);
            }
        }
    }

    // Test setConfigID
     if (true)
    {
        int id = 1;
        qDebug() << "  set config id = " << id;
        pcontrol.setConfigID(id);
        QThread::msleep(1000);
    }


    // Test setPatternID 
    if (true)
    {
        int id = 1;
        qDebug() << "  set pattern id = " << id;
        pcontrol.setPatternID(id);
        QThread::msleep(1000);
    }

    // Test start/stop
     if (true)
    {
        qDebug() << "  start";
        pcontrol.start();
        QThread::msleep(5000);

        qDebug() << "  stop";
        pcontrol.stop();
        QThread::msleep(1000);
    }

    // Test controller reset
     if (true)
    {
        qDebug() << "  reset controller";
        pcontrol.reset(true);

        qDebug() << "  allOn";
        pcontrol.allOn();
        QThread::msleep(1000);
        qDebug() << "  allOff";
        pcontrol.allOff();
        QThread::msleep(1000);
    }

    // Test show bus number
     if (true)
    {
        qDebug() << "  show bus number";
        pcontrol.showBusNumber();
        QThread::msleep(1000);
    }


    // Test set position (not sure how this works??)
     if (false)
    {
        qDebug() << "  test set position";
        pcontrol.stop();
        for (int i=0;i<100;i++)
        {
            qDebug() << "  i = " << i;
            pcontrol.setPosition(i,0);
            pcontrol.start();
            QThread::msleep(500);
            pcontrol.stop();
        }
        pcontrol.stop();
    }

    // Test set gainAndOffset
     if (true)
    {
        qDebug() << "  test set gain and offset";
        pcontrol.setPatternID(1);
        pcontrol.start();
        pcontrol.setGainAndBias(0,0,0,0);

        qDebug() << "  test x gain";
        QThread::msleep(2000);
        pcontrol.setGainAndBias(10,0,0,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(-10,0,0,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,0,0);
        QThread::msleep(500);

        qDebug() << "  test y gain";
        pcontrol.setGainAndBias(0,0,10,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,-10,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,0,0);
        QThread::msleep(500);

        qDebug() << "  test x offset";
        pcontrol.setGainAndBias(0,10,0,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,-10,0,0);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,0,0);
        QThread::msleep(500);

        qDebug() << "  test y offset";
        pcontrol.setGainAndBias(0,0,0,10);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,0,-10);
        QThread::msleep(2000);
        pcontrol.setGainAndBias(0,0,0,0);
        QThread::msleep(500);

        pcontrol.stop();
    }

    // Test set offsets again
    if (true)
    {
        pcontrol.setPatternID(1);
        qDebug() << "  testing y offset";
        int8_t n = 30;
        for (int8_t i=0; i<n; i++)
        {
            pcontrol.stop();
            pcontrol.setGainAndBias(0,0,0,i);
            pcontrol.start();
            QThread::msleep(200);
        }
        for (int8_t i=n; i>-n; i--)
        {
            pcontrol.stop();
            pcontrol.setGainAndBias(0,0,0,i);
            pcontrol.start();
            QThread::msleep(200);
        }
        for (int8_t i=-n; i<1; i++)
        {
            pcontrol.stop();
            pcontrol.setGainAndBias(0,0,0,i);
            pcontrol.start();
            QThread::msleep(200);
        }
        pcontrol.stop();
    }

    pcontrol.close();
    qDebug() << "Press Ctl-C to exit";
    return app.exec();
}
Esempio n. 6
0
void Kompas::on()
{

    timer->stop();
    QSerialPortInfo *info = new QSerialPortInfo(*port);
    if(!(port->isOpen() && info->portName() == settings->m_name_COM))
    {
        if(port->isOpen())
            port->close();

        qDebug()<<settings->m_name_COM;
        port->setPortName(settings->m_name_COM);
        if (port->open(QIODevice::ReadWrite))
        {
            QFile file("dataRead.dat");
            if (file.open(QIODevice::ReadOnly | QIODevice::Text))
            {
               QTextStream stream(&file);
               m_skl = stream.readLine().toInt();
               m_coef_A = stream.readLine().toInt();
               file.close();
            }

            updateSettings();
            QSerialPortInfo *info = new QSerialPortInfo(*port);
            qDebug() << "Name        : " << info->portName();
            qDebug() << "Description : " << info->description();
            qDebug() << "Manufacturer: " << info->manufacturer();
            qDebug() << "BaudRate: " << port->baudRate();
            qDebug() << "Parity: " << port->parity();
            qDebug() << "Data bits: " << port->dataBits();
            qDebug() << "Stop Bits: " << port->stopBits();
            delete info;
            m_state=1;
            emit stateChanged();
            m_connect_state=1;
            emit connect_stateChanged();
            qDebug()<<"state = 1 ON";
            qDebug()<<settings->m_name_COM<<"opened";
        }
        else
        {
            if(port->isOpen())
                port->close();
            qDebug()<<"Error while opening";
        }
    }
    if(port->isOpen() && port->waitForReadyRead(1000))
    {
        QString data;
        QByteArray ByteArray;
        m_state = 1;
        while(m_state)
        {
            qint64 byteAvail = port->bytesAvailable();
            qApp->processEvents();
            if(byteAvail >=13)
            {
                ByteArray = port->readAll();
                data = data.fromLocal8Bit(ByteArray).trimmed();
                if(ByteArray[3]=='p')
                {
                    QBitArray bitdata(104),two_bytes(16);
                    for(int i = 0,j; i < 104; ++i)
                    {
                        j=i/8;
                        if(j<=13)
                            bitdata[i] = ByteArray[j] & (1 << i%8);
                        else
                            break;
                    }

                    for(int i=40,j=15;i<56&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Roll
                    setRoll(Round(toDec(two_bytes,1)*1.41,1));
                    for(int i=56,j=15;i<72&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Pitch
                    setPitch(Round(toDec(two_bytes,1)*1.41,1));
                    for(int i=72,j=15;i<88&&j>=0;i++,j--){two_bytes[j]=bitdata[i];} //Azimuth

                    setAngle(Round(toDec(two_bytes,0)*1.41,1));
                    m_state=0;
                    qApp->processEvents();
                }
            }
        }
    }
    else
    {
        qDebug()<<"WaitForReadyRead failed";
        qDebug()<<port->error();
    }
    kompasThread1->quit();
    timer->start(10);
}