Unsolved SerialCommunication on QtAndroid
-
Hello,
I'm trying to exchange date between and Arduino board and a Qt App on an Android Device.
Once my Arduino board is connected to my Smartphone with an OTG cable and running my app, using the QSerialPortInfo class I can get all the information about the port (vendorIdentifier, productiIdentifier....).
The problem is that when I try to connect to the port using QSerialPort class (open()) is like Android has no permissions to access to the port:arduino->setPortName(portToOpen); arduino->setBaudRate(QSerialPort::Baud9600); arduino->setDataBits(QSerialPort::Data8); arduino->setFlowControl(QSerialPort::NoFlowControl); arduino->setParity(QSerialPort::NoParity); arduino->setStopBits(QSerialPort::OneStop); if(arduino->open(QIODevice::ReadWrite)) setIsConnected(true); else qInfo() << arduino->errorString();
When I check if the port is open, it always return an error message saying that the file is locked and the port is not opened:
qInfo() << arduino->errorString();
The error message is:
Permission error while creating lock file
So, what it can be done to solve this situation?
Any help will be very appreciated,
Thank you -
So, what it can be done to solve this situation?
It is impossible if your smartphone is not rooted (as I know). You can try following (if you have a root access):
- startup your application as root (but I don't know how to do it)
or
- write special "initialisation" file or script on your Android FS to change permissions of serial port (as I remember, there is possible to do something like this).
UPD:
Permission error while creating lock file
Ah, seems, that "/data/local/tmp" directory has not read/write access for you. Maybe we need fix it to replace with QStandardPaths::writableLocation(QStandardPaths::TempLocation). You can try to replace it (or just comments out creation of a lock file) from source code and re-build library).
Anyway, I suspect, that next error will be "permission error", related to the serial port itself (about I wrote before) :)
-
@kuzulis
Hi, first of all, thank you very much.
Then, I don't understand exactly what I have to do:
Maybe we need fix it to replace with QStandardPaths::writableLocation(QStandardPaths::TempLocation). You can try to replace it (or just comments out creation of a lock file) from source code and re-build library).
I just add in my main file this code:int main(int argc, char *argv[]) { QApplication a(argc, argv); QStandardPaths::writableLocation(QStandardPaths::TempLocation); MainWindow w; w.show(); return a.exec(); }
But the same error is shown: Permission error while creating lock file
On the debug console it also can be seen this info:
W libterminal.so: (null):0 ((null)): The following directories are not readable or writable for detaling with lock files 06-05 00:42:29.161 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /var/lock 06-05 00:42:29.162 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /etc/locks 06-05 00:42:29.162 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /var/spool/locks 06-05 00:42:29.162 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /var/spool/uucp 06-05 00:42:29.162 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /tmp 06-05 00:42:29.162 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /var/tmp 06-05 00:42:29.163 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /var/lock/lockdev 06-05 00:42:29.163 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /run/lock 06-05 00:42:29.163 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): /data/local/tmp 06-05 00:42:29.163 17410 17437 W libterminal.so: W libterminal.so: (null):0 ((null)): Failed to create a lock file for opening the device
Thank you very much.
-
I just add in my main file this code:
You should modify a source code of QtSerialPort module, rebuild and reinstall it. Please, take a look on this code. You should try to replace QStringLiteral("/data/local/tmp") with QStandardPaths::writableLocation(QStandardPaths::TempLocation) (or just to append QStandardPaths::writableLocation(QStandardPaths::TempLocation) after QStringLiteral("/data/local/tmp") ).
-
@kuzulis
Excuse me for my ignorance, but I don't know how to rebuild and reinstall the module. Once I try to build the module (but I don't know if I' doing it properly) this error appears:Cannot find application binary /home/carles/Qt/5.9/Src/build-qtserialport-Android_for_armeabi_v7a_GCC_4_9_Qt_5_9_0_for_Android_armv7-Release/tests/auto/qserialport/libtst_qserialport.so. 23:05:21: The process "/home/carles/Qt/5.9/android_armv7/bin/androiddeployqt" exited with code 2. Error while building/deploying project qtserialport (kit: Android for armeabi-v7a (GCC 4.9, Qt 5.9.0 for Android armv7))
Thank you.
-