void MainWindow::resetPortList()
{
    QSerialPortInfo info;
    portList = info.availablePorts();
    ui->portBox->clear();
    for(int i=0;i<portList.size();i++)
    {
        ui->portBox->addItem(portList[i].portName());
    }
}
bool SerialCommandQueue::open(QSerialPortInfo info)
{
    if (isConnected()) {
        qCritical("Already connected to serial device");
        return false;
    }

    qDebug() << "connecting to " << info.portName();

#if defined(Q_OS_OSX)
    // Note: This should be info.portName(). Changed here as a workaround for:
    // https://bugreports.qt.io/browse/QTBUG-45127
    serial->setPortName(info.systemLocation());
#else
    serial->setPortName(info.portName());
#endif
    serial->setBaudRate(QSerialPort::Baud115200);

    if (!serial->open(QIODevice::ReadWrite)) {
        qDebug() << "Could not connect to serial device. Error: " << serial->error()
                 << serial->errorString();
        return false;
    }

    return true;
}
bool MainWindow::LoadSettings()
{
    bool returnvalue = false;
    QSettings settings("thunderbug","SpherebotSettings");
    settings.beginGroup("settings");
    curFile = settings.value("fileName", "").toString();
    curDir = settings.value("currentDirectory", "").toString();
    qDebug() << "curdir"<< curDir<<endl;
    if(!curFile.isEmpty())
    {
        if(QFile::exists(curFile))
        {
            qDebug()<<"load last file.";
            loadFile(curFile);
            returnvalue = true;
        }
    }
    qDebug()<<"load: "<<curFile;
    QString SavedPortName = settings.value("PortName", "").toString();
    QSerialPortInfo info;
    portList = info.availablePorts();
    for(int i = 0; i < portList.size();i++)
    {
        if(QString::compare(portList.at(i).portName(),SavedPortName) == 0)
        {
            ui->portBox->setCurrentIndex(i);
            bot->connectWithBot(SavedPortName);
        }
    }
    settings.endGroup();
    qDebug()<<"settings loaded: ";
    return returnvalue;
}
Esempio n. 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{

    ui->setupUi(this);

    ui->console->clear();

    timerMOTOR = new QTimer(this);


    ui->comboBox_baundrate->addItem("57600",QSerialPort::Baud57600);
    ui->comboBox_baundrate->addItem("9600",QSerialPort::Baud9600);


    for(QSerialPortInfo port : QSerialPortInfo::availablePorts())
        ui->comboBox_port->addItem(port.portName(),port.description());

    serialhandler = new SerialHandler(this);


    connect(serialhandler,SIGNAL(console(QString)),ui->console,SLOT(insertPlainText(QString)));

    connect(serialhandler,SIGNAL(motor1(int)),ui->bar_m1,SLOT(setValue(int)));
    connect(serialhandler,SIGNAL(motor2(int)),ui->bar_m2,SLOT(setValue(int)));
    connect(serialhandler,SIGNAL(motor3(int)),ui->bar_m3,SLOT(setValue(int)));
    connect(serialhandler,SIGNAL(motor4(int)),ui->bar_m4,SLOT(setValue(int)));

    ui->pushButton_connect->click();

}
 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. 6
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);
    }
}
 //  Found the available ports, associated vendor id and product id
 foreach(const QSerialPortInfo &serialPortInfo, QSerialPortInfo::availablePorts()){
     if(serialPortInfo.hasVendorIdentifier() && serialPortInfo.hasProductIdentifier()){
         if(serialPortInfo.vendorIdentifier() == found_vendorID){
             if(serialPortInfo.productIdentifier() == found_productID){
                 arm_portname = serialPortInfo.portName();
                 arm_port_is_available = true;
             }
         }
     }
 }
Esempio n. 8
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;
}
serialportconnectioncontrols::serialportconnectioncontrols(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::serialportconnectioncontrols)
{
    ui->setupUi(this);
    connected = false;
    QList <QSerialPortInfo> ports = portInfo.availablePorts();
    QSerialPortInfo tmp;
    for(int i=0;i<ports.size();i++)
    {
        tmp = ports.at(i);
        ui->PortBox->addItem(tmp.portName());
    }
    autoconnect = true;
}
Esempio n. 10
0
/*!
 * \brief Rs232DevicePrivate::Rs232DevicePrivate - CTor
 * \param info
 * \param parent
 */
Rs232DevicePrivate::Rs232DevicePrivate(const QSerialPortInfo &info, QObject *parent) :
    QSerialPort(info, parent)
{
    m_debug = false;

    qDebug() << headDebug << "CTor" << info.portName();

    // Faccio partire un timer: se entro il suo timeout non ho trovato il converter mi autodistruggo
    connect (&m_timerAutodelete, SIGNAL(timeout()), this, SLOT(deleteLater()));
    m_timerAutodelete.start(2000);

    connect (&m_timerSendGetId, SIGNAL(timeout()), this, SLOT(sendMsgGetId()));

    // Sono riuscito a configurare la porta?
    if (configPort())
    {
        // Si, la porta e' fisica e non virtuale.
        m_statoParser = STATO_RS232_DLE_STX;
        m_checksum = 0;

        connect(this, SIGNAL(error(QSerialPort::SerialPortError)),
                this, SLOT(errorSlot(QSerialPort::SerialPortError)));
        connect(this, SIGNAL(readyRead()), this, SLOT(fromDeviceSlot()));

        // Spedisco il messaggio per sapere se e' collegato un converter
        sendMsgGetId();
    }
}
Esempio n. 11
0
    foreach (QSerialPortInfo info, QSerialPortInfo::availablePorts())
    {
        //QListWidgetItem * item = new QListWidgetItem( info.portName(),this->ui->list);
        QListWidgetItem * item = new QListWidgetItem( info.portName());
        this->ui->list->addItem(item);
        item->setFlags(Qt::ItemIsUserCheckable|Qt::ItemIsEnabled|Qt::ItemIsSelectable);
        item->setCheckState(Qt::Checked);

    }
Esempio n. 12
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());
Esempio n. 13
0
 bool operator() (const QSerialPortInfo &serialPortInfo) const
 {
     return serialPortInfo.portName() == m_serialPortName;
 }
bool sortPorts(QSerialPortInfo const & s1, QSerialPortInfo const & s2)
{
    return s1.portName() < s2.portName();
}
Esempio n. 15
0
QString Builder::GetLeonardoSerialPort(QString defaultPort)
{
    QStringList before, after;
    QSerialPortInfo serialList;
    QSerialPort port;

    SetPercentage(100);

    for (int i=0; i < serialList.availablePorts().count(); i++) {
        before.append(serialList.availablePorts().at(i).portName());
    }

    /*#ifdef Q_OS_WIN
       	PrepareSerialPort(project->serialPort, "1200");
    #endif*/
    port.setPortName(project->serialPort);
    port.setFlowControl(QSerialPort::NoFlowControl);
    port.setBaudRate(QSerialPort::Baud1200);
    port.setParity(QSerialPort::NoParity);
    port.setStopBits(QSerialPort::OneStop);
    port.setDataBits(QSerialPort::Data8);
    bool open = port.open (QIODevice::ReadWrite);
//#endif
    if (open == false) {
        progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
        msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
    }
    /*char buffer[20] = "Hello!\r\n";
    port.write ((const char *)buffer);*/
    //QThread::msleep(10);
    port.close();

    QThread::msleep(100);

    int counter = 50;
    after.clear();
    bool warningMessage = true;
    while (counter > 0) {
        QSerialPortInfo newSerialList;
        for (int i=0; i < newSerialList.availablePorts().count(); i++) {
            after.append(newSerialList.availablePorts().at(i).portName());
        }

        for (int i=0; i < after.count(); i++) {
            if (before.indexOf(after.at(i)) < 0) {
                return after.at(i);
            }
        }
        QThread::msleep(120);
        counter--;

        if ( (progress->value() > 40) && warningMessage) {
            warningMessage = false;
            progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
            msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
        }

        SetPercentage(100 - counter * 2);
        if (GetCancel()) {
            counter = 0;
            break;
        }
    }

    msg.Add("Could not detect Leonardo serial port for programming. Please try pressing the RESET button at your board when you see the dialog message 'Detecting Leonardo port...'!", mtError);
    return "";
}
Esempio n. 16
0
bool ProjectProperties::Edit(Project * project)
{
	if (project == NULL) {
		return false;
	}
	ok = false;	

	ui.stackedWidget->setCurrentIndex(0);
	ui.menuList->setCurrentRow(0);

	ui.lblName->setText("General options for project '" + project->name + "':");
	
	// set board names combobox
	ui.cbBoardName->clear();
	map <QString, BoardDef>::iterator board;
	for (board = config.boards.begin(); board != config.boards.end() ;board++) {
		ui.cbBoardName->addItem(board->first);
		if (board->first == project->boardName) {
			ui.cbBoardName->setCurrentIndex(ui.cbBoardName->count()-1);
		}
	}
	if (ui.cbBoardName->currentIndex() < 0) {
		if (ui.cbBoardName->count() > 0) {
			ui.cbBoardName->setCurrentIndex(0);
		}
	}	

	// get list of serial ports
	// to do: use QSerialPort

	ui.cbSerialPort->clear();
	ui.cbSerialPort->addItem("N/A");

	QSerialPortInfo serial;
	for (int i=0; i < serial.availablePorts().count();i++) {
		ui.cbSerialPort->addItem(serial.availablePorts().at(i).portName());
	}
	
	/*ui.cbSerialPort->addItem("COM 1");
	ui.cbSerialPort->addItem("COM 2");
	ui.cbSerialPort->addItem("COM 3");
	ui.cbSerialPort->addItem("COM 4");
	ui.cbSerialPort->addItem("COM 5");
	ui.cbSerialPort->addItem("COM 6");
	*/
	ui.cbSerialPort->setCurrentIndex(0);
	for (int i=0; i < ui.cbSerialPort->count(); i++) {
		if (project->serialPort == ui.cbSerialPort->itemText(i)) {
			ui.cbSerialPort->setCurrentIndex(i);
		}
	}

	// populate programmers list
	ui.cbExternalProgrammer->clear();
	map <QString, ProgrammerDef>::iterator prog;
	for (prog = config.programmers.begin(); prog != config.programmers.end(); prog++) {
		ui.cbExternalProgrammer->addItem(prog->first);
		if (prog->first == project->programmer) {
			ui.cbExternalProgrammer->setCurrentIndex(ui.cbExternalProgrammer->count()-1);
		}
	}
	if (ui.cbExternalProgrammer->currentIndex() < 0) {
		if (ui.cbExternalProgrammer->count() > 0) {
			ui.cbExternalProgrammer->setCurrentIndex(0);
		}
	}	

	if (project->programmer == "") {
		ui.rbNoExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(false);
	} else {
		ui.rbYesExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(true);
	}

	exec();

	if (ok == false) {
		return false;
	}

	project->serialPort = ui.cbSerialPort->itemText(ui.cbSerialPort->currentIndex());
	if (project->serialPort == "N/A") {
		project->serialPort = "";
	}

	if (ui.rbNoExternalProgrammer->isChecked()) {
		project->programmer = "";
	} else {
		project->programmer = ui.cbExternalProgrammer->itemText(ui.cbExternalProgrammer->currentIndex());
	}

	project->boardName = ui.cbBoardName->itemText(ui.cbBoardName->currentIndex());
	
	return true;
}
Esempio n. 17
0
bool sortPorts(const QSerialPortInfo &s1, const QSerialPortInfo &s2)
{
    return s1.portName() < s2.portName();
}
Esempio n. 18
0
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. 19
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);
}
bool BlinkyPendantUploader::startUpload(BlinkyController &controller,
                                        QList<PatternWriter> &patternWriters)
{
    // TODO: push the image conversions into here so they are less awkward.
    #define PIXEL_COUNT 10

    // Probe for the blinkypendant version
    // TODO: Update the firmware first!
    QSerialPortInfo portInfo;
    if (!controller.getPortInfo(portInfo)) {
        errorString = "Couln't get port information!";
        return false;
    }

    int version = getVersionForDevice(portInfo.vendorIdentifier(),
                                      portInfo.productIdentifier());

    QByteArray data;
    if (version == BLINKY_PENDANT_VERSION_1) {
        qDebug() << "Using version 1 upload mechanism, please update firmware!";

        // Make sure we have an image compatible with the BlinkyPendant
        if (patternWriters.front().getLedCount() != 10) {
            errorString = "Wrong pattern size- must be 10 pixels high!";
            return false;
        }
        if (patternWriters.front().getEncoding() != PatternWriter::RGB24) {
            errorString = "Wrong encoding type- must be RGB24!";
            return false;
        }

        if(patternWriters.front().getFrameCount() > 255) {
            errorString = "Pattern too long, must be < 256 frames";
            return false;
        }

        // Create the data structure to write to the device memory
        data.append((char)0x13);    // header
        data.append((char)0x37);
        data.append((char)patternWriters.front().getFrameCount());  // frame count
        data += patternWriters.front().getData();       // image data (RGB24, uncompressed)
    } else {
        // Create the data structure to write to the device memory
        // Animation table

        QByteArray patternData;

        data.append((char)0x31);    // header
        data.append((char)0x23);
        data.append((char)patternWriters.size()); // Number of patterns in the table
        data.append((char)PIXEL_COUNT);     // Number of LEDs in the pattern

        foreach (PatternWriter pattern, patternWriters) {
            // Make sure we have an image compatible with the BlinkyPendant
            if (pattern.getLedCount() != 10) {
                errorString = "Wrong pattern size- must be 10 pixels high!";
                return false;
            }
            if (pattern.getEncoding() != PatternWriter::RGB24) {
                errorString = "Wrong encoding type- must be RGB24!";
                return false;
            }

            if(pattern.getFrameCount() > 65535) {
                errorString = "Pattern too long, must be < 65535 frames";
                return false;
            }

            // Animation entry
            data.append((char)0);             // Encoding type (1 byte) (RGB24, uncompressed) (TODO)
            data += encodeInt(patternData.length());        // Data offset (4 bytes)
            data += encodeWord(pattern.getFrameCount());   // Frame count (2 bytes)
            data += encodeWord(0);                          // Frame delay (2 bytes) TODO

            // Make sure we have an image compatible with the BlinkyPendant
            patternData += pattern.getData();       // image data (RGB24, uncompressed)
        }

        data += patternData;
    }

    // TODO: Check if the data can fit in the device memory

    // Set up the commandQueue using the serial descriptor, and close the tape connection
    controller.close();
    commandQueue.open(portInfo);

    setProgress(0);

    // Queue the following commands:
    // 1. start write
    commandQueue.enqueue(BlinkyPendantCommands::startWrite());

    // 2-n. write data (aligned to 1024-byte sectors, 64 bytes at a time)
    commandQueue.enqueue(BlinkyPendantCommands::writeData(data));

    // n+1 stop write
    commandQueue.enqueue(BlinkyPendantCommands::stopWrite());

    return true;
}
Esempio n. 21
0
/*!
    Sets the port stored in the serial port info instance \a serialPortInfo.

    \sa portName(), QSerialPortInfo
*/
void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo)
{
    Q_D(QSerialPort);
    d->systemLocation = serialPortInfo.systemLocation();
}
Esempio n. 22
0
/*!
    Sets the port stored in the serial port info instance \a serialPortInfo.

    \sa portName(), QSerialPortInfo
*/
void QSerialPort::setPort(const QSerialPortInfo &serialPortInfo)
{
    Q_D(QSerialPort);
    d->systemLocation = QSerialPortPrivate::portNameToSystemLocation(serialPortInfo.systemLocation());
}
bool Cooller_ModBusController::equalPredicat(QSerialPortInfo& first, QSerialPortInfo& second)
{
    return first.portName() == second.portName();
}