termios and pyserial

1,449 views
Skip to first unread message

fvl

unread,
Jun 8, 2012, 12:18:23 PM6/8/12
to python-...@googlegroups.com
Hi, 

I've been trying to get pyserial running on android and it's failing due to a dependency on the termios module.  It seems that in src/blacklist.txt "lib-dynload/termios.so" is listed under "unused binaries python modules" which is why the module is missing.  So I commented out that line and now I'm getting this error when I try to import termios: 
Cannot load library: link_image[1995]: failed to link termios.so 

So I'm wondering: 
1. Is there a better approach to getting pyserial on Android? 
2. Why is termios blacklisted? 
3. Why might termios be failing with that load library error? 
4. Is there any other way to do serial communications from Android with python? 

Any other ideas or help anyone could offer would be very much appreciated. 

Thanks, 
fvl

getitzack

unread,
Jun 11, 2012, 4:36:57 PM6/11/12
to python-...@googlegroups.com
Hi,
I got exactly the same problem.
I want to access my motor modules by opening the serial interface using pyserial.
I compiled the /dev/ttyACMx kernel driver for Android 2.6.32.9 and deployed them by insmod.
Because I also got the termios library error when using pyserial I tried to open the /dev/ttyAVM0 directly.
This seems to be possible but I don't get the expected results.
Did you made some progress in meantime?

Regards
getitzack


Fred Lionetti

unread,
Jun 11, 2012, 4:48:06 PM6/11/12
to python-...@googlegroups.com
Hi getitzack,

It looks like another project porting python to android py4a
(http://code.google.com/p/python-for-android/) which is part of the
android scripting (http://code.google.com/p/android-scripting/)
includes termios.so support and works quite well with pyserial - at
least on my device. Unfortunately, it's a different version of python
which does not support kivy.

So my current plan, while terrible, is to run both of these python
interpreters in separate processes. One python will be the py4a
version and include pyserial support while the other one will be the
"kivy" python-for-android version and thus include kivy support. The
two processes are communicating over sockets. Although this is kind
of awful and introduces a lot of overhead, the idea idea has some
appeal in that it will keep the serial part of my app and the user
interface part of my app in completely separate processes so they are
unable to mess each other up.

-fvl

Mathieu Virbel

unread,
Jun 11, 2012, 8:04:52 PM6/11/12
to python-...@googlegroups.com
Hi,

Wait, what is missing exactly?
I don't have any serial device, so i can't really work on that. But if
you need help for compiling missing extension etc, then tell me.
If termios fail to load, please post the message of the error :)

As for the initial answer (i was sure to send it before..):
>>> 1. Is there a better approach to getting pyserial on Android?
dunno

>>> 2. Why is termios blacklisted?
not really used by default, blacklist is a preference blacklist, you can
edit and add/remove module as you wish

>>> 3. Why might termios be failing with that load library error?
dunno, the error message would help maybe

>>> 4. Is there any other way to do serial communications from Android with
not as i know


Mathieu

Fred Lionetti

unread,
Jun 11, 2012, 8:11:37 PM6/11/12
to python-...@googlegroups.com
Hi Mathieu,

Thanks for replying. I was thinking only you might be able to bail me
out of this problem. If I remove termios.so from the blacklist and
recompile I get this message from "import termios":
"Cannot load library: link_image[1995]: failed to link termios.so"

Since pyserial relies on termios, I don't think it's possible to use
pyserial until this is resolved...

-Fred

Mathieu Virbel

unread,
Jun 11, 2012, 8:12:37 PM6/11/12
to python-...@googlegroups.com
Ok for the failed to link, but you don't get any error message before?
Did you put your tablet in debug mode?

Mathieu

Fred Lionetti

unread,
Jun 11, 2012, 8:17:42 PM6/11/12
to python-...@googlegroups.com
I didn't see any error message before. I'm using adb to send and
receive files on my device - other than that I'm not sure about
running in debug mode.

Mathieu Virbel

unread,
Jun 11, 2012, 8:23:11 PM6/11/12
to python-...@googlegroups.com
Are you using python-for-android, or the kivy launcher?
Can you connect on irc?

http://webchat.freenode.net/?nick=kvuser.&channels=kivy&uio=d4

my nick is tito, let's fast debug this issue together :)

Mathieu Virbel

unread,
Jun 11, 2012, 8:50:13 PM6/11/12
to python-...@googlegroups.com
Ok,

I didn't try to run it on my android tablet, but i think i got the
issue, if i try manually to link the termios library:

$ arm-linux-androideabi-ld -d termios.so -rpath
../../../../libs/armeabi/ -rpath
~/code/android/./android-ndk-r7/platforms/android-14/arch-arm/usr/lib/

I got the error:
termios.so: undefined reference to `tcdrain'

And if you google "tcdrain android", the first link goes on
android-scripting, with:

#if 0 // No tcdrain defined for Android.
PyDoc_STRVAR(termios_tcdrain__doc__,
...
#endif

I'm pushing a fix...



On 12/06/2012 02:17, Fred Lionetti wrote:

Fred Lionetti

unread,
Jun 12, 2012, 12:43:42 PM6/12/12
to python-...@googlegroups.com
I can confirm that Mathieu's fix worked. Pyserial (and termios) are
now working for me from Android. Just don't forget to remove
termios.so from blacklist.txt when compiling.

Thanks!

getitzack

unread,
Jun 13, 2012, 6:16:27 AM6/13/12
to python-...@googlegroups.com

Hello Fred,

great to know pyserial is working now!

Thanks also for the workaround solution sketch.

 I miss some information to get it running in my environment.

Sorry I'am new to this and hope you can give some hints how to proceed.

That's what I did: 

1. Comented out "lib-dynload/termios.so" line within " ../python-for-android/src/blacklist.txt"

2. Added "pyserial-2.6-py2.6.egg" into the ../python-for-android/src/buildlib.

   Comment: Previously I created a serial-0.1.win32.kex extension, which seems to work.

3. Downloaded the "Python-2.7.2-android.patch" and placed  it into “../python-for-android/recipes/python/patches”.

   Comment: Did I get the right patch? “http://android-python27.googlecode.com/hg-history/bcee3f88e8495e3a6695b6a1004828155db01937/python-build/patch/Python-2.7.2-android.patch

4. Running "distribute and build. This produced an .apk which still complains "missing link to termios.so" showed by “>adb logcat.

I don't know if it is sufficient to place a patch into the patch-dir to apply it?

Thanks

Ralph Zacharias

Mathieu Virbel

unread,
Jun 13, 2012, 6:56:38 AM6/13/12
to python-...@googlegroups.com
You don't need to download another patch from an unknow website
For beginner, best is to restart from the start (git clone ...)
And it will work :)
> <http://code.google.com/p/python-for-android/>) which is part of the
> android scripting (http://code.google.com/p/android-scripting/
> <http://code.google.com/p/android-scripting/>)

getitzack

unread,
Jun 13, 2012, 1:28:41 PM6/13/12
to python-...@googlegroups.com
Hi Mathieu,
pushed means already at git...ok! :). Thanks a lot.
Termios is working now. That makes me happy.

Yurij Mikhassiak

unread,
Apr 12, 2013, 6:08:00 AM4/12/13
to python-...@googlegroups.com
Hm.. can anybody share pyserial module wich will work with kivy?
I tried to use one from py4a but problem with termios still present. 

Also latest kivyluncher can't import sqlite3. Module not found. If I bring my linux sqlite3 module to my app project it has some internal import problems ( can't import _sqlite3 in dbapi2.py).

Please help! I am so sad! I wrote CNC controller app. On linux laptop everythyng works ok but on android no multiprocessing, pyserial, sqlite.. I thought all builtin cpython modules are supported on android too :( 

Regards, Yurij
 

Mathieu Virbel

unread,
Apr 18, 2013, 5:28:06 PM4/18/13
to python-...@googlegroups.com
Hi,

Multiprocessing is not gonna to work, because android have also their
own limitation, and the process seperation is not working the same at
all. fork() is not prohibed, but you can find on the net that lot of
android-experts are saying you should not use it. Android services is
the right way to do, or threads. But not multiprocessing.

Sqlite 3 should work, if not, then report the issue. And maybe try to
help for that. As the python-for-android project said:
http://python-for-android.readthedocs.org/en/latest/faq.html#sqlite3-so-not-found

Pyserial is not a cpython module, so no, it's not included. If
compilation is required, then submit a recipe and/or report an issue
about it.

Don't loose your hope, we can make the world better :)

Mathieu

Le 12/04/2013 12:08, Yurij Mikhassiak a �crit :
> Hm.. can anybody share *pyserial* module wich will work with kivy?
>
> I tried to use one from py4a but problem with termios still present.
>
> Also latest kivyluncher can't import *sqlite3*. Module not found. If I
> bring my linux sqlite3 module to my app project it has some internal
> import problems ( can't import _sqlite3 in dbapi2.py).
>
> Please help! I am so sad! I wrote CNC controller app. On linux laptop
> everythyng works ok but on android no multiprocessing, pyserial,
> sqlite.. I thought all builtin cpython modules are supported on android
> too :(
>
> Regards, Yurij
>
>
> --
> Vous recevez ce message, car vous �tes abonn� au groupe Google
> Groupes Python For Android.
> Pour vous d�sabonner de ce groupe et ne plus recevoir d'e-mails le
> concernant, envoyez un e-mail � l'adresse
> python-androi...@googlegroups.com.
> Pour plus d'options, visitez le site
> https://groups.google.com/groups/opt_out .
>
>

Fred Lionetti

unread,
Apr 18, 2013, 5:35:24 PM4/18/13
to python-...@googlegroups.com
I don't believe pyserial required any special compilation - it's just pure python.  The only problem I had was that it imports termios which failed for me until Mathieu applied his fix on 11/June/2012.  The only thing special I remember doing is removing termios.so from blacklist.txt when compiling.

Fred


On Thu, Apr 18, 2013 at 2:28 PM, Mathieu Virbel <txp...@gmail.com> wrote:
Hi,

Multiprocessing is not gonna to work, because android have also their
own limitation, and the process seperation is not working the same at
all. fork() is not prohibed, but you can find on the net that lot of
android-experts are saying you should not use it. Android services is
the right way to do, or threads. But not multiprocessing.

Sqlite 3 should work, if not, then report the issue. And maybe try to
help for that. As the python-for-android project said:
http://python-for-android.readthedocs.org/en/latest/faq.html#sqlite3-so-not-found

Pyserial is not a cpython module, so no, it's not included. If
compilation is required, then submit a recipe and/or report an issue
about it.

Don't loose your hope, we can make the world better :)

Mathieu

Le 12/04/2013 12:08, Yurij Mikhassiak a écrit :
> Hm.. can anybody share *pyserial* module wich will work with kivy?
>
> I tried to use one from py4a but problem with termios still present.
>
> Also latest kivyluncher can't import *sqlite3*. Module not found. If I
> bring my linux sqlite3 module to my app project it has some internal
> import problems ( can't import _sqlite3 in dbapi2.py).
>
> Please help! I am so sad! I wrote CNC controller app. On linux laptop
> everythyng works ok but on android no multiprocessing, pyserial,
> sqlite.. I thought all builtin cpython modules are supported on android
> too :(
>
> Regards, Yurij
>
>
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google
> Groupes Python For Android.
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le
> concernant, envoyez un e-mail à l'adresse
> python-androi...@googlegroups.com.
> Pour plus d'options, visitez le site
> https://groups.google.com/groups/opt_out .
>
>

--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "Python For Android".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/python-android/VlcNlF6R4lE/unsubscribe?hl=fr.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse python-androi...@googlegroups.com.

Yurij Mikhassiak

unread,
Apr 18, 2013, 6:31:42 PM4/18/13
to python-...@googlegroups.com
hey! thanks for reply. 
I've rewrote my program to use threading module. Hope it will work. 
Still have some strange errors with startup on android. Hope to fix them by clean rebuild and then I'll report about my success.
I see that starting android service is possible only using pyjnius. So code which we will start in this service also have to written in Java? So i can't use pyserial and must use Java modules in this service?
Regards, Yurij


On Fri, Apr 19, 2013 at 12:28 AM, Mathieu Virbel <txp...@gmail.com> wrote:
Hi,

Multiprocessing is not gonna to work, because android have also their
own limitation, and the process seperation is not working the same at
all. fork() is not prohibed, but you can find on the net that lot of
android-experts are saying you should not use it. Android services is
the right way to do, or threads. But not multiprocessing.

Sqlite 3 should work, if not, then report the issue. And maybe try to
help for that. As the python-for-android project said:
http://python-for-android.readthedocs.org/en/latest/faq.html#sqlite3-so-not-found

Pyserial is not a cpython module, so no, it's not included. If
compilation is required, then submit a recipe and/or report an issue
about it.

Don't loose your hope, we can make the world better :)

Mathieu

Le 12/04/2013 12:08, Yurij Mikhassiak a écrit :
> Hm.. can anybody share *pyserial* module wich will work with kivy?
>
> I tried to use one from py4a but problem with termios still present.
>
> Also latest kivyluncher can't import *sqlite3*. Module not found. If I
> bring my linux sqlite3 module to my app project it has some internal
> import problems ( can't import _sqlite3 in dbapi2.py).
>
> Please help! I am so sad! I wrote CNC controller app. On linux laptop
> everythyng works ok but on android no multiprocessing, pyserial,
> sqlite.. I thought all builtin cpython modules are supported on android
> too :(
>
> Regards, Yurij
>
>
> --
> Vous recevez ce message, car vous êtes abonné au groupe Google
> Groupes Python For Android.
> Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le
> concernant, envoyez un e-mail à l'adresse
> python-androi...@googlegroups.com.
> Pour plus d'options, visitez le site
> https://groups.google.com/groups/opt_out .
>
>

--
Vous recevez ce message car vous êtes abonné à un sujet dans le groupe Google Groupes "Python For Android".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/python-android/VlcNlF6R4lE/unsubscribe?hl=fr.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse python-androi...@googlegroups.com.

Yurij Mikhassiak

unread,
Apr 18, 2013, 6:35:20 PM4/18/13
to python-...@googlegroups.com
Fred Lionetti thanks!
But I undertand i need to copy pyserial(from py4a is ok?) and sqlite3(from linux install?) modules into my app folder?
Regards, Yurij

Kuba Raczkowski

unread,
Nov 24, 2016, 9:36:42 AM11/24/16
to Python For Android
Hi, I got termios working in the APK, but the only way I found till now to get access to the actual port is to change the low level permissions (chmod 666 /dev/ttyACM0).
Is there any way this could work with non-rooted device? Accessing serial port via pyjnius and the normal android API perhaps?
Did you have some other solution?

Best regards,
Kuba
Reply all
Reply to author
Forward
0 new messages