SerialPortControl::SerialPortControl(QObject *parent) :
    QObject(parent)
{
    serialPort = new QextSerialPort(QextSerialPort::EventDriven, this);
    serialEnum = new QextSerialEnumerator;
    //The following only works in OSX and Win. For other OSs use refresh button:
    serialEnum->setUpNotifications();
    buffer = new QByteArray;
    buffer->clear();
    input = new QByteArray;
    input->clear();


    //Inicializamos a los valores por defecto:
    this->set_baudRate (BAUD9600);
    this->set_dataBits (DATA_8);
    this->set_parityBits (PAR_NONE);
    this->set_stopBits (STOP_1);
    this->set_flowControl (FLOW_OFF);
    this->set_openMode (QIODevice::ReadWrite);

    connect (serialPort, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
    connect (serialEnum, SIGNAL(deviceDiscovered(QextPortInfo)) ,this
             ,SLOT(devicesListModified()));
    connect (serialEnum, SIGNAL(deviceRemoved(QextPortInfo))    ,this
             ,SLOT(devicesListModified()));
}
Example #2
0
ctkDICOMHostMainLogic::ctkDICOMHostMainLogic(ctkHostedAppPlaceholderWidget* placeHolder, ctkDICOMAppWidget* dicomAppWidget, 
                                             QWidget* placeHolderForControls) : 
  QObject(placeHolder), 
  PlaceHolderForHostedApp(placeHolder),
  DicomAppWidget(dicomAppWidget),
  PlaceHolderForControls(placeHolderForControls),
  ValidSelection(false),
  SendData(false)
{
  this->Host = new ctkExampleDicomHost(PlaceHolderForHostedApp);
  this->HostControls = new ctkExampleHostControlWidget(Host, PlaceHolderForControls);

  Data = new ctkDicomAppHosting::AvailableData;

  disconnect(this->Host,SIGNAL(startProgress()),this->Host,SLOT(onStartProgress()));
  connect(this->Host,SIGNAL(appReady()),this,SLOT(onAppReady()), Qt::QueuedConnection);
  connect(this->Host,SIGNAL(startProgress()),this,SLOT(publishSelectedData()), Qt::QueuedConnection);
  connect(this->PlaceHolderForHostedApp,SIGNAL(resized()),this,SLOT(placeHolderResized()));

  QTreeView * treeview = dicomAppWidget->findChild<QTreeView*>("TreeView");
  QItemSelectionModel* selectionmodel = treeview->selectionModel();
  connect(selectionmodel, SIGNAL(selectionChanged ( const QItemSelection &, const QItemSelection & )),
    this, SLOT(onTreeSelectionChanged(const QItemSelection &, const QItemSelection &)));

  connect(this->Host, SIGNAL(dataAvailable()), this, SLOT(onDataAvailable()));

  connect( qApp, SIGNAL(aboutToQuit()), this, SLOT(aboutToQuit()) );
}
LogParser::LogParser(SerialPort* serialPort, QObject *parent) : QObject(parent)
{
    _serialPort = serialPort;

    _receivedDataQueue = new QQueue<unsigned char>();

    connect(_serialPort, SIGNAL(readyRead()), SLOT(onDataAvailable()));
}
Example #4
0
/*
   This is called when a configuration is loaded, and updates the plugin's settings.
   Careful: the plugin is already drawn before the loadConfiguration method is called the
   first time, so you have to be careful not to assume all the plugin values are initialized
   the first time you use them
 */
void AntennaTrackGadget::loadConfiguration(IUAVGadgetConfiguration *config)
{
    // Delete the (old)port, this also closes it.
    if (port) {
        delete port;
    }

    // Delete the (old)parser, this also disconnects all signals.
    if (parser) {
        delete parser;
    }

    AntennaTrackGadgetConfiguration *AntennaTrackConfig = qobject_cast< AntennaTrackGadgetConfiguration *>(config);

    PortSettings portsettings;
    portsettings.BaudRate    = AntennaTrackConfig->speed();
    portsettings.DataBits    = AntennaTrackConfig->dataBits();
    portsettings.FlowControl = AntennaTrackConfig->flow();
    portsettings.Parity = AntennaTrackConfig->parity();
    portsettings.StopBits    = AntennaTrackConfig->stopBits();
    portsettings.Timeout_Millisec = AntennaTrackConfig->timeOut();

    // In case we find no port, buttons disabled
    m_widget->connectButton->setEnabled(false);
    m_widget->disconnectButton->setEnabled(false);

    QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
    foreach(QextPortInfo nport, ports) {
        if (nport.friendName == AntennaTrackConfig->port()) {
            qDebug() << "Using Serial port";
            // parser = new NMEAParser();

#ifdef Q_OS_WIN
            port = new QextSerialPort(nport.portName, portsettings, QextSerialPort::EventDriven);
#else
            port = new QextSerialPort(nport.physName, portsettings, QextSerialPort::EventDriven);
#endif
            m_widget->setPort(port);
            m_widget->connectButton->setEnabled(true);
            m_widget->disconnectButton->setEnabled(false);
            m_widget->connectButton->setHidden(false);
            m_widget->disconnectButton->setHidden(false);

            connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
        }
    }
    m_widget->dataStreamGroupBox->setHidden(false);
    qDebug() << "Using Telemetry parser";
    parser = new TelemetryParser();

    connect(parser, SIGNAL(position(double, double, double)), m_widget, SLOT(setPosition(double, double, double)));
    connect(parser, SIGNAL(home(double, double, double)), m_widget, SLOT(setHomePosition(double, double, double)));
    connect(parser, SIGNAL(packet(QString)), m_widget, SLOT(dumpPacket(QString)));
}
COMDevice::COMDevice()
{
    _port = new QextSerialPort();
    QObject::connect(_port, SIGNAL(readyRead()),
                     this, SLOT(onDataAvailable()));
    QObject::connect(_port, SIGNAL(dsrChanged(bool)),
                     this, SLOT(onDSRChanged(bool)));
    QObject::connect(_port, SIGNAL(bytesWritten(qint64)),
                     this, SLOT(onBytesWritten(qint64)));
    _lastError = ERR_NO_ERROR;
    _pendingBytesInWriting = 0;
}
Example #6
0
RobotInterface::RobotInterface(QObject *parent) :
    QObject(parent),
    m_leftSpeed(0),
    m_rightSpeed(0),
    m_serialPort(0),
    m_state(LOOKING_FOR_START)
{
    m_serialPort = new QextSerialPort("/dev/ttyUSB0");
    connect(m_serialPort, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
    m_serialPort->open(QIODevice::ReadWrite);
    m_serialPort->setBaudRate(BAUD115200);
}
// copied from: Adafruit_ATParser::readline
void onDataAvailable(Adafruit_ATParser& stream)
{
	stream.readline();
	if (detectUartCode(stream.buffer) != UC_NONE) {
		// no data
		return;
	}
	
	handleSerialRxChar(stream.buffer, strlen(stream.buffer));
	stream.buffer[0]= 0;	

	// s. Adafruit_ATParser::waitForOK
	return onDataAvailable(stream);
}
Example #8
0
/*
  This is called when a configuration is loaded, and updates the plugin's settings.
  Careful: the plugin is already drawn before the loadConfiguration method is called the
  first time, so you have to be careful not to assume all the plugin values are initialized
  the first time you use them
 */
void GpsDisplayGadget::loadConfiguration(IUAVGadgetConfiguration* config)
{
    // Delete the (old)port, this also closes it.
    if(port) {
        delete port;
    }

    // Delete the (old)parser, this also disconnects all signals.
    if(parser) {
        delete parser;
    }

    GpsDisplayGadgetConfiguration *gpsDisplayConfig = qobject_cast< GpsDisplayGadgetConfiguration*>(config);

    if (gpsDisplayConfig->connectionMode() == "Serial") {
        PortSettings portsettings;
        portsettings.BaudRate=gpsDisplayConfig->speed();
        portsettings.DataBits=gpsDisplayConfig->dataBits();
        portsettings.FlowControl=gpsDisplayConfig->flow();
        portsettings.Parity=gpsDisplayConfig->parity();
        portsettings.StopBits=gpsDisplayConfig->stopBits();
        portsettings.Timeout_Millisec=gpsDisplayConfig->timeOut();

        // In case we find no port, buttons disabled
        m_widget->connectButton->setEnabled(false);
        m_widget->disconnectButton->setEnabled(false);

        QList<QextPortInfo> ports = QextSerialEnumerator::getPorts();
        foreach( QextPortInfo nport, ports ) {
            if(nport.friendName == gpsDisplayConfig->port())
            {
                qDebug() << "Using Serial parser";
                parser = new NMEAParser();

#ifdef Q_OS_WIN
                port=new QextSerialPort(nport.portName,portsettings,QextSerialPort::EventDriven);
#else
                port=new QextSerialPort(nport.physName,portsettings,QextSerialPort::EventDriven);
#endif
                m_widget->connectButton->setEnabled(true);
                m_widget->disconnectButton->setEnabled(false);
                m_widget->connectButton->setHidden(false);
                m_widget->disconnectButton->setHidden(false);

                connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
            }
        }
        m_widget->dataStreamGroupBox->setHidden(false);
    } else if (gpsDisplayConfig->connectionMode() == "Telemetry") {
// copied from void Adafruit_BLE::update(uint32_t period_ms)
void SerialComClass::update(uint32_t period_ms)
{
	enum {
		EVENT_SYSTEM_CONNECT     = 0,
		EVENT_SYSTEM_DISCONNECT  = 1,

		EVENT_SYSTEM_BLE_UART_RX = 8,
		// 9 reserved

		EVENT_SYSTEM_BLE_MIDI_RX = 10,
		//  11 reserved
	};

	m_ble.println( F("AT+EVENTSTATUS") );
	m_ble.readline();
	m_ble.waitForOK();

	// parse event status system_event, gatts_event
	uint32_t system_event;
	char * p_comma = NULL;

	system_event = strtoul(m_ble.buffer, &p_comma, 16);

	//--------------------------------------------------------------------+
	// System Event
	//--------------------------------------------------------------------+
	if ( bitRead(system_event, EVENT_SYSTEM_CONNECT   ) )
	{
		onConnected();
	}
	if ( bitRead(system_event, EVENT_SYSTEM_DISCONNECT) )
	{
		onDisconnected();
	}

	if ( bitRead(system_event, EVENT_SYSTEM_BLE_UART_RX) )
	{
		m_ble.println( F("AT+BLEUARTRX") );
		onDataAvailable( m_ble );
	}
}
Example #10
0
//----------------------------------------------------------------------------
ctkExampleDicomAppLogic::ctkExampleDicomAppLogic():
ctkDicomAbstractApp(ctkExampleDicomAppPlugin::getPluginContext()), AppWidget(0)
{


  connect(this, SIGNAL(startProgress()), this, SLOT(onStartProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(resumeProgress()), this, SLOT(onResumeProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(suspendProgress()), this, SLOT(onSuspendProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(cancelProgress()), this, SLOT(onCancelProgress()), Qt::QueuedConnection);
  connect(this, SIGNAL(exitHostedApp()), this, SLOT(onExitHostedApp()), Qt::QueuedConnection);
  connect(this, SIGNAL(dataAvailable()), this, SLOT(onDataAvailable()));

  //notify Host we are ready.
  try {
    getHostInterface()->notifyStateChanged(ctkDicomAppHosting::IDLE);
  }
  catch(...)
  {
    qDebug() << "ctkDicomAbstractApp: Could not getHostInterface()";
  }
}
Example #11
0
void Serial::init()
{
    if (this->isConnected)
        port->close();
    port = new QextSerialPort(this->portStr); //we create the port

    connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));

    port->open(QIODevice::ReadWrite | QIODevice::Unbuffered); //we open the port
    if(!port->isOpen())
        throw SerialError("Unable to open the port!");

    //we set the port properties
    port->setBaudRate(BAUD9600);//modify the port settings on your own
    port->setFlowControl(FLOW_OFF);
    port->setParity(PAR_NONE);
    port->setDataBits(DATA_8);
    port->setStopBits(STOP_1);

    this->isConnected = true;
}
DeviceRS232Rubin201::DeviceRS232Rubin201()
{
    portSettings.BaudRate=BAUD9600;
    portSettings.FlowControl=FLOW_OFF;
    portSettings.Parity=PAR_NONE;
    portSettings.DataBits=DATA_8;
    portSettings.StopBits=STOP_1;
    portSettings.Timeout_Millisec=600;
    port = new QextSerialPort(portSettings);
    connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));

    name = "Рубин 201";
    descr = "Измеритель оптической мощности";
    timeout=2000;


    waitingForConnect=0;

    uniqueType=101;

}
void ArduinoDriver::run() {
	QextSerialPort port;
	thread_port = &port;
    port.setPortName(QString(m_portname.c_str()));
    port.setBaudRate(BAUD9600);

    connect(&port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));

    if(!port.open(QIODevice::ReadWrite)) {
        qDebug() << "cannot connect to " << port.portName();
        return;
    }

    arduinoSetup = true;

    exec();
    //thread ended, cleanup

    if (port.lineStatus() != 0) {
    	qDebug() << "closing port";
        port.close();
    }
}
PrincipalWindow::PrincipalWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    ui->comboChooseBaud->addItem("9600", QVariant (9600));


    //buddys and shortcuts
    ui->labelChooseBaud->setBuddy(ui->comboChooseBaud);
    ui->labelCoosePort->setBuddy(ui->comboChoosePort);
    QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Return), this);
    QObject::connect(shortcut, SIGNAL(activated()), this, SLOT(on_pushSend_clicked()));


    portSettings.BaudRate=BAUD9600;
    portSettings.FlowControl=FLOW_OFF;
    portSettings.Parity=PAR_NONE;
    portSettings.DataBits=DATA_8;
    portSettings.StopBits=STOP_1;
    portSettings.Timeout_Millisec=600;
    port = new QextSerialPort(portSettings);


        displayActivePorts();


     connect(port, SIGNAL(readyRead()), this, SLOT(onDataAvailable()));
     buffer.clear();



     //debugging script
    /* ui->comboChoosePort->setCurrentIndex(1);
     ui->lineEnterValue->setText("0x82");
     on_pushConnect_clicked();
*/
/*
     QTimer   * debug_timer  = new QTimer (this) ;
connect(debug_timer, SIGNAL(timeout()), this, SLOT(on_pushSend_clicked()));
debug_timer->start(1000);

*/

     //on_pushSend_clicked();


     //for debugging purposes;;;;

  //   dvm  = new DeviceManagerIzluchatel (this, 183, this);
//
        //dvm->currentstandid = 183;




 //Подключение слотов менеджера устройств
    // connect (dvm, SIGNAL (fireTransitMeasData(int, double, QString)), this, SLOT (slotTestDeviceManager(int, double, QString)));
     //connect (dvm, SIGNAL (fireDeviceDisconnected(int)), this, SLOT (slotDeviceManagerDeviceDisconnected(int)));

 // [turn it on!!!] ;-) //

     //my wiiiinch came today to our city!    [====] // 11.02.2014 ``~~~~~



}
void SocketListener::runListener() {

    SocketClientCollection pendingList;

    while(1) {
        SocketClientCollection::iterator it;
        fd_set read_fds;
        int rc = 0;
        int max = -1;

        FD_ZERO(&read_fds);

        if (mListen) {
            max = mSock;
            FD_SET(mSock, &read_fds);
        }

        FD_SET(mCtrlPipe[0], &read_fds);
        if (mCtrlPipe[0] > max)
            max = mCtrlPipe[0];

        pthread_mutex_lock(&mClientsLock);
        for (it = mClients->begin(); it != mClients->end(); ++it) {
            // NB: calling out to an other object with mClientsLock held (safe)
            int fd = (*it)->getSocket();
            FD_SET(fd, &read_fds);
            if (fd > max) {
                max = fd;
            }
        }
        pthread_mutex_unlock(&mClientsLock);
        SLOGV("mListen=%d, max=%d, mSocketName=%s", mListen, max, mSocketName);
        if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) {
            if (errno == EINTR)
                continue;
            SLOGE("select failed (%s) mListen=%d, max=%d", strerror(errno), mListen, max);
            sleep(1);
            continue;
        } else if (!rc)
            continue;

        if (FD_ISSET(mCtrlPipe[0], &read_fds)) {
            char c = CtrlPipe_Shutdown;
            TEMP_FAILURE_RETRY(read(mCtrlPipe[0], &c, 1));
            if (c == CtrlPipe_Shutdown) {
                break;
            }
            continue;
        }
        if (mListen && FD_ISSET(mSock, &read_fds)) {
            sockaddr_storage ss;
            sockaddr* addrp = reinterpret_cast<sockaddr*>(&ss);
            socklen_t alen;
            int c;

            do {
                alen = sizeof(ss);
                c = accept(mSock, addrp, &alen);
                SLOGV("%s got %d from accept", mSocketName, c);
            } while (c < 0 && errno == EINTR);
            if (c < 0) {
                SLOGE("accept failed (%s)", strerror(errno));
                sleep(1);
                continue;
            }
            fcntl(c, F_SETFD, FD_CLOEXEC);
            pthread_mutex_lock(&mClientsLock);
            mClients->push_back(new SocketClient(c, true, mUseCmdNum));
            pthread_mutex_unlock(&mClientsLock);
        }

        /* Add all active clients to the pending list first */
        pendingList.clear();
        pthread_mutex_lock(&mClientsLock);
        for (it = mClients->begin(); it != mClients->end(); ++it) {
            SocketClient* c = *it;
            // NB: calling out to an other object with mClientsLock held (safe)
            int fd = c->getSocket();
            if (FD_ISSET(fd, &read_fds)) {
                pendingList.push_back(c);
                c->incRef();
            }
        }
        pthread_mutex_unlock(&mClientsLock);

        /* Process the pending list, since it is owned by the thread,
         * there is no need to lock it */
        while (!pendingList.empty()) {
            /* Pop the first item from the list */
            it = pendingList.begin();
            SocketClient* c = *it;
            pendingList.erase(it);
            /* Process it, if false is returned, remove from list */
            if (!onDataAvailable(c)) {
                release(c, false);
            }
            c->decRef();
        }
    }
}
void SocketListener::runListener() {

    SocketClientCollection *pendingList = new SocketClientCollection();

    while(1) {
        SocketClientCollection::iterator it;
        fd_set read_fds;
        int rc = 0;
        int max = -1;

        FD_ZERO(&read_fds);

        if (mListen) {
            max = mSock;
            FD_SET(mSock, &read_fds);
        }

        FD_SET(mCtrlPipe[0], &read_fds);
        if (mCtrlPipe[0] > max)
            max = mCtrlPipe[0];

        pthread_mutex_lock(&mClientsLock);
        for (it = mClients->begin(); it != mClients->end(); ++it) {
            int fd = (*it)->getSocket();
            FD_SET(fd, &read_fds);
            if (fd > max)
                max = fd;
        }
        pthread_mutex_unlock(&mClientsLock);

        if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) {
            if (errno == EINTR)
                continue;
            SLOGE("select failed (%s)", strerror(errno));
            sleep(1);
            continue;
        } else if (!rc)
            continue;

        if (FD_ISSET(mCtrlPipe[0], &read_fds))
            break;
        if (mListen && FD_ISSET(mSock, &read_fds)) {
            struct sockaddr addr;
            socklen_t alen;
            int c;

            do {
                alen = sizeof(addr);
                c = accept(mSock, &addr, &alen);
            } while (c < 0 && errno == EINTR);
            if (c < 0) {
                SLOGE("accept failed (%s)", strerror(errno));
                sleep(1);
                continue;
            }
            pthread_mutex_lock(&mClientsLock);
            mClients->push_back(new SocketClient(c));
            pthread_mutex_unlock(&mClientsLock);
        }

        /* Add all active clients to the pending list first */
        pendingList->clear();
        pthread_mutex_lock(&mClientsLock);
        for (it = mClients->begin(); it != mClients->end(); ++it) {
            int fd = (*it)->getSocket();
            if (FD_ISSET(fd, &read_fds)) {
                pendingList->push_back(*it);
            }
        }
        pthread_mutex_unlock(&mClientsLock);

        /* Process the pending list, since it is owned by the thread,
         * there is no need to lock it */
        while (!pendingList->empty()) {
            /* Pop the first item from the list */
            it = pendingList->begin();
            SocketClient* c = *it;
            pendingList->erase(it);
            /* Process it, if false is returned, remove and destroy it */
            if (!onDataAvailable(c)) {
                /* Remove the client from our array */
                pthread_mutex_lock(&mClientsLock);
                for (it = mClients->begin(); it != mClients->end(); ++it) {
                    if (*it == c) {
                        mClients->erase(it);
                        break;
                    }
                }
                pthread_mutex_unlock(&mClientsLock);
                /* Destroy the client */
                int socket = c->getSocket();
                if (c->decRef()) {
                    // Note: 'c' is deleted memory at this point.
                    close(socket);
                }
            }
        }
    }
    delete pendingList;
}
void SocketListener::runListener() {

    while(1) {
        SocketClientCollection::iterator it;
        fd_set read_fds;
        int rc = 0;
        int max = 0;

        FD_ZERO(&read_fds);

        if (mListen) {
            max = mSock;
            FD_SET(mSock, &read_fds);
        }

        FD_SET(mCtrlPipe[0], &read_fds);
        if (mCtrlPipe[0] > max)
            max = mCtrlPipe[0];

        pthread_mutex_lock(&mClientsLock);
        for (it = mClients->begin(); it != mClients->end(); ++it) {
            FD_SET((*it)->getSocket(), &read_fds);
            if ((*it)->getSocket() > max)
                max = (*it)->getSocket();
        }
        pthread_mutex_unlock(&mClientsLock);

        if ((rc = select(max + 1, &read_fds, NULL, NULL, NULL)) < 0) {
            SLOGE("select failed (%s)", strerror(errno));
            sleep(1);
            continue;
        } else if (!rc)
            continue;

        if (FD_ISSET(mCtrlPipe[0], &read_fds))
            break;
        if (mListen && FD_ISSET(mSock, &read_fds)) {
            struct sockaddr addr;
            socklen_t alen = sizeof(addr);
            int c;

            if ((c = accept(mSock, &addr, &alen)) < 0) {
                SLOGE("accept failed (%s)", strerror(errno));
                sleep(1);
                continue;
            }
            pthread_mutex_lock(&mClientsLock);
            mClients->push_back(new SocketClient(c));
            pthread_mutex_unlock(&mClientsLock);
        }

        do {
            pthread_mutex_lock(&mClientsLock);
            for (it = mClients->begin(); it != mClients->end(); ++it) {
                int fd = (*it)->getSocket();
                if (FD_ISSET(fd, &read_fds)) {
                    pthread_mutex_unlock(&mClientsLock);
                    if (!onDataAvailable(*it)) {
                        close(fd);
                        pthread_mutex_lock(&mClientsLock);
                        delete *it;
                        it = mClients->erase(it);
                        pthread_mutex_unlock(&mClientsLock);
                    }
                    FD_CLR(fd, &read_fds);
                    continue;
                }
            }
            pthread_mutex_unlock(&mClientsLock);
        } while (0);
    }
}
Example #18
0
void Connection::initConnection()
{
    if (!mSocketClient->buffer().isEmpty())
        onDataAvailable(mSocketClient, std::forward<Buffer>(mSocketClient->takeBuffer()));
    send(ConnectMessage());
}
Example #19
0
void Connection::checkData()
{
    if (!mSocketClient->buffer().isEmpty())
        onDataAvailable(mSocketClient, std::forward<Buffer>(mSocketClient->takeBuffer()));
}
Example #20
0
unsigned long MemoryReadBytestream::appendData(const std::string &data) {
	m_data += data;
	onDataAvailable();
	neededData = false;
	return m_data.size();
}