Error using pyjnius with bluetooth-to-serial device on Android

215 views
Skip to first unread message

dumpm...@gmail.com

unread,
Sep 9, 2013, 12:47:00 PM9/9/13
to pyjni...@googlegroups.com
Hi,

I'm developing an Kivy application that uses a cash register printer with a serial interface.
To connect to android I use a bluetooth-to-serial device via jnuis.
Everything works as expected, except, whenever a character is being send above the value of 127 an exception is being thrown:

[WARNING           ] stderr:   File "/mnt/sdcard/kivy/kassa/serialAndroid.py", line 88, in write
[WARNING           ] stderr:     self._outStream.write(data)
[WARNING           ] stderr:   File "jnius_export_class.pxi", line 827, in jnius.jnius.JavaMultipleMethod.__call__ (jnius/jnius.c:18715)
[WARNING           ] stderr:   File "jnius_export_class.pxi", line 553, in jnius.jnius.JavaMethod.__call__ (jnius/jnius.c:15573)
[WARNING           ] stderr:   File "jnius_conversion.pxi", line 94, in jnius.jnius.populate_args (jnius/jnius.c:5181)
[WARNING           ] stderr:   File "jnius_conversion.pxi", line 434, in jnius.jnius.convert_pyarray_to_java (jnius/jnius.c:8202)
[WARNING           ] stderr: OverflowError: value too large to convert to signed char

I'm testing this using Kivy Launcher 1.7.2 on Android 4.2
The data is being writen as a string like:
data = chr(100)+chr(28)+chr(128).
outStream.write(data)

It looks like the conversion of string data which contains a value over 127 to a java string is responsible for this.
Is this a programming error or a bug in pyjnius?

If this is a programming error then please tell me how do I send the data to pyjnius because the data for the printer contains can be in the range of 0 to 255?
Any help is appreciated.

Regards,
Willem

David Carrillo

unread,
Mar 31, 2014, 4:30:13 AM3/31/14
to pyjni...@googlegroups.com
Hi Willem,

I am having the same problem. Could you solve this?

Thanks,
David

Dewald du Plooy

unread,
Apr 21, 2014, 7:33:09 AM4/21/14
to pyjni...@googlegroups.com
Hi David,

I had the same problem, and solved/circumvented it by sending each character separately. This is probably not the optimal solution, but at least I got it working this way.

            # at the moment the conversion from byte array (data) to java byte array does not work nicely
            # but this approach seem to be ok
            for c in data:
                if ord(c) < 256:
                    outStream.write(ord(c))

Best Regards,
Dewald
Message has been deleted

David Carrillo

unread,
Apr 22, 2014, 7:03:18 AM4/22/14
to pyjni...@googlegroups.com
Hi Dewald,
Thank you for your response.I was able to work around it by converting the characters to integers between -128 and 127. Like this:

[ord(b) if ord(b) <= 127 else ord(b)-256 for b in bstr]

The problem is caused because java uses sign bytes as chars.

David

Dewald du Plooy

unread,
May 6, 2014, 5:05:27 AM5/6/14
to pyjni...@googlegroups.com
Hi David,

Ah ok, thanks for the feedback and explanation! :)

Best Regards,
Dewald
Reply all
Reply to author
Forward
0 new messages