Git Product home page Git Product logo

usb4a's Introduction

usb4a

PayPal Donate PyPI version Downloads

Python package for Android USB host.

Android platform related classes:

PythonActivity

Context

Intent

PendingIntent

USB related classes:

UsbConstants

UsbRequest

USBError

Helper classes:

ByteBuffer

Helper functions:

get_usb_manager

get_usb_device_list

get_usb_device

has_usb_permission

request_usb_permission

build_usb_control_request_type

arraycopy

This package can be used for implementing USB device driver for Android USB host, like USB serial port drivers.

How to use it:

If not in need to build a dedicated app:

It works for Android 6.0+.

Get Pydroid apps from here.

Or get the latest versions on Google Play.

In Pydroid, go to Menu->Pip.

Install usb4a.

Open example.py and run it.

Go to Menu->Graphical program output.

Scroll to the last line, it should list all the USB devices connected to the Android phone/tablet with vendor id, vendor name, product id and product name.

If a dedicated app is needed to be built with buildozer:

It works for Android 4.0+.

Grab the contents of the xml/ folder within this repo. Put them into a similar folder within your project. The files work as they are. It is recommended to run the app first without modifying them. They can later be modified as deemed suitable.

Modify the buildozer.spec:

In buildozer.spec add termios.so to the whitelist.

Include usb4a in requirements.

# (list) python-for-android whitelist
android.p4a_whitelist = lib-dynload/termios.so

# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy, pyjnius, usb4a

# (str) Extra xml to write directly inside the <manifest> element of AndroidManifest.xml
# use that parameter to provide a filename from where to load your custom XML code
android.extra_manifest_xml = manifest/extra_manifest.xml

# (str) XML file to include as an intent filters in <activity> tag
android.manifest.intent_filters = manifest/intent-filter.xml

# (list) Copy these files to src/main/res/xml/ (used for example with intent-filters)
android.res_xml = manifest/device_filter.xml

That's it, build the app and deploy it, everything should work now.

Change log

Version 0.3.0

Since Android API Version >= 31 (Android 12), it requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent. Some code is modified to meet this requirement. Thank vgrimaldi848 for reporting the issue and suggesting the solution. Thank troscianko for testing the code with Android 12 devices.

Version 0.2.0

Service context is added so that the app can run in background. Thank rambo for adding service context support to the package.

Version 0.1.0

Initial release.

usb4a's People

Contributors

jacklinquan avatar rambo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

usb4a's Issues

data in arduino

Hi, I cannot able to get the data transfer to arduino when i try to print what it is receiving as message i get only b' '.how to solve it?

Direct Device Access

I've heard one can get much faster communication speed with devices if directly accessing the linux usb devices with system calls, rather than going through the android java API. This is the approach used for libusb's android support, once the android api is used to get permission to access the device handles. Just an idea to share, for future thoughts.

USB Read Issues

Hi,
`
usb_device_list = usb.get_usb_device_list()
device = usb_device_list[1]
device1 = usb_device_list[1].getDeviceName()

while True:
if usb.has_usb_permission(device) == True:
while True:
connection = mavutil.mavlink_connection(device1, port=57600, autoreconnect=True,input=True,broadcast=True)
else:
usb.request_usb_permission(device1)
`

I cannot read/write USB data.

device filter issue

hi,
I cannot able to create my app with the usb4a. when i follow the steps that you have mentioned. After creating the devicefilter.xml when i run the buildozer android debug it shows and error that the devicefilter.xml is not found and the some of the gradle functions are depreceated. can you help me solve it and i am running this package in vm with ubuntu20.0.
Below i am attaching my error text file.

error.txt
4

Cannot be used from a service context

https://github.com/jacklinquan/usb4a/blob/master/usb4a/usb.py#L55 fails when used in a service (https://python-for-android.readthedocs.io/en/latest/services/) and user cannot just monkeypatch that:

09-29 15:48:53.919 27737 27754 I GNSSService: Hello world! from gnssserv_entrypoint.py
09-29 15:48:54.651 27737 27754 I GNSSService: *** monkey-patching usb4a context ***
09-29 15:48:54.652 27737 27754 I GNSSService: Traceback (most recent call last):
09-29 15:48:54.653 27737 27754 I GNSSService:   File "/home/rambo/devel/augnss_buildozer/android/app/gnssserv_entrypoint.py", line 22, in <module>
09-29 15:48:54.653 27737 27754 I GNSSService:   File "jnius/jnius_export_class.pxi", line 130, in jnius.jnius.MetaJavaClass.__setattr__
09-29 15:48:54.653 27737 27754 I GNSSService:   File "jnius/jnius_export_class.pxi", line 485, in jnius.jnius.JavaField.__set__
09-29 15:48:54.653 27737 27754 I GNSSService:   File "jnius/jnius_export_class.pxi", line 662, in jnius.jnius.JavaField.write_static_field
09-29 15:48:54.654 27737 27754 I GNSSService:   File "jnius/jnius_conversion.pxi", line 414, in jnius.jnius.convert_python_to_jobject
09-29 15:48:54.654 27737 27754 I GNSSService:   File "jnius/jnius_utils.pxi", line 205, in jnius.jnius.check_assignable_from
09-29 15:48:54.654 27737 27754 I GNSSService: jnius.jnius.JavaException: Invalid instance of 'org/kivy/android/PythonService' passed for a 'org/kivy/android/PythonActivity'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.