bool QSerialPortPrivate::open(QIODevice::OpenMode mode) { rwMode = mode; qCDebug(AndroidSerialPortLog) << "Opening" << systemLocation.toLatin1().data(); QAndroidJniObject jnameL = QAndroidJniObject::fromString(systemLocation); cleanJavaException(); deviceId = QAndroidJniObject::callStaticMethod<jint>( kJniClassName, "open", "(Landroid/content/Context;Ljava/lang/String;I)I", QtAndroid::androidActivity().object(), jnameL.object<jstring>(), (jint)this); cleanJavaException(); isReadStopped = false; if (deviceId == BAD_PORT) { qWarning() << "Error opening %s" << systemLocation.toLatin1().data(); q_ptr->setError(QSerialPort::DeviceNotFoundError); return false; } if (rwMode == QIODevice::WriteOnly) stopReadThread(); return true; }
static void cleanup() { stopUserThread(); stopReadThread(); s_userThread->join(); s_remoteThread->join(); /* The threads MUST be stopped before the event system is * closed, since the threads continously access the event * system. */ closeEventSystem(); }
void QSerialPortPrivate::newDataArrived(char *bytesA, int lengthA) { Q_Q(QSerialPort); int bytesToReadL = lengthA; // Always buffered, read data from the port into the read buffer if (readBufferMaxSize && (bytesToReadL > (readBufferMaxSize - readBuffer.size()))) { bytesToReadL = readBufferMaxSize - readBuffer.size(); if (bytesToReadL <= 0) { // Buffer is full. User must read data from the buffer // before we can read more from the port. stopReadThread(); return; } } char *ptr = readBuffer.reserve(bytesToReadL); memcpy(ptr, bytesA, bytesToReadL); emit q->readyRead(); }