Android Question Usb connection

Pesciolina

Active Member
Licensed User
Goodmorning everyone,

I have to connect via USB to a device that the manufacturer has released only an example of a Python code, it is possible to use it for B4A. In my current project I use the Usb 0.98 library and the UsbSerial 2.4
Thanks
Marco
Python:
# example python connection to Timy via USB
#
# pre-requisites:
#    Python >= 2.6
#    pyusb >= 1.0    http://sourceforge.net/apps/trac/pyusb/
#    libusb >= 1.0    http://www.libusb.org/wiki/libusb-1.0
#

import usb.core
import time

TIMY_VEND = 0x0c4a    # USB Vendor ID
TIMY_PROD = 0x0889    # USB Product ID
READEP = 0x81        # Interrupt input endpoint ID
WRITEEP = 0x01        # Interrupt output endpoint ID

dev = usb.core.find(idVendor=TIMY_VEND, idProduct=TIMY_PROD)
dev.set_configuration()
cmds = ['TIMYINIT', 'NSF', 'KL0', 'CHK1', 'PRE4',
        'RR0', 'BE1', 'DTS00.02', 'DTF00.02', 'EMU0',
        'PRIIGN1', 'PRILF', 'DTP------------',
        'PS1', 'PROG', 'CLR',
       ]
try:
    dev.write(WRITEEP, '\r')
    while True:
        try:
            if len(cmds) > 0:
                cmd = cmds.pop(0)
                dev.write(WRITEEP, cmd + '\r')
                print(bytearray(dev.read(READEP, 32, timeout=100)))
            print(bytearray(dev.read(READEP, 32, timeout=100)))
            # sleep here to simulate 'work' on host pc
            #time.sleep(0.1)
        except usb.core.USBError as e:
            if e.args[0] == 'Operation timed out':
                pass
            else:
                raise e
finally:
    dev.reset()
 
Top