Usb library problem with B4A2.2

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

A working 2.0 demo does not work anymore in 2.2. It is a demo that uses the Usb library together with a Mega ADK.

This line gives me trouble: _permission = _device_usbman.HasAccessoryPermission((android.hardware.usb.UsbAccessory)(_r.GetField("accessory")));

This is actually a solution that you proposed in the forums for version 2.0. Any suggestions?
 

bluedude

Well-Known Member
Licensed User
Longtime User
Here you go, this happens during compilation:

Compiling code. 0.22
Compiling layouts code. 0.50
Generating R file. 1.00
Compiling generated Java code. Error
B4A line: 59
Permission= device_UsbMan.HasAccessoryPermission(r.GetField(\
javac 1.6.0_26
src\com\thingstank\apps\arduino\main.java:385: HasAccessoryPermission(anywheresoftware.b4a.objects.usb.UsbManagerWrapper.UsbAccessoryWrapper) in anywheresoftware.b4a.objects.usb.UsbManagerWrapper cannot be applied to (android.hardware.usb.UsbAccessory)
_permission = _device_usbman.HasAccessoryPermission((android.hardware.usb.UsbAccessory)(_r.GetField("accessory")));
^
1 error
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hmm, does not work but maybe i'm doing it wrong.

Dim device_UsbAcc As UsbAccessory
Dim device_UsbMan As UsbManager

B4A line: 58
Permission= device_UsbMan.HasAccessoryPermission(device_UsbAcc)
javac 1.6.0_26
src\com\thingstank\apps\arduino\main.java:380: inconvertible types
found : anywheresoftware.b4a.objects.usb.UsbManagerWrapper.UsbAccessoryWrapper
required: android.hardware.usb.UsbAccessory
_permission = _device_usbman.HasAccessoryPermission((android.hardware.usb.UsbAccessory)(_device_usbacc));
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
One for Erel I think. The xml says it wants an Android UsbAccessory

<name>HasAccessoryPermission</name>
<parameter>
<name>Accessory</name>
<type>android.hardware.usb.UsbAccessory</type>
</parameter>


whereas the code wants a basic4android UsbAccessoryWrapper :signOops:

public boolean HasAccessoryPermission(UsbAccessoryWrapper Accessory)
{
return manager.hasPermission(Accessory.accessory);
}
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

I updated the library but still have a problem:

B4A line: 69
device_UsbMan.RequestAccessoryPermission(device_UsbAcc)
javac 1.6.0_26
src\com\thingstank\apps\arduino\main.java:397: inconvertible types
found : anywheresoftware.b4a.objects.usb.UsbManagerWrapper.UsbAccessoryWrapper
required: android.hardware.usb.UsbAccessory
_device_usbman.RequestAccessoryPermission((android.hardware.usb.UsbAccessory)(_device_usbacc));

I have done this Dim device_UsbAcc As UsbAccessory so that would be the one to check the permission for right?

Not sure anymore.
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
I actually think this whole piece of sample code isn't very good, it always shows me the dialog twice:

'initialize Usb Manager
device_UsbMan.Initialize
'create an accessory collection
Dim listAccessories () As UsbAccessory

' get accessories, main throw exception
Try
listAccessories = device_UsbMan.GetAccessories
For i = 0 To listAccessories.Length - 1
If listAccessories(i).Description = "thingstank" Then
device_UsbAcc = listAccessories(i)
End If
Next

If device_UsbAcc <> Null Then
Dim Permission As Boolean
Permission= device_UsbMan.HasAccessoryPermission(device_UsbAcc)
If Permission==True Then
device_UsbMan.OpenAccessory(device_UsbAcc)
If device_Stream.IsInitialized==False Then
Try
device_Stream.Initialize(device_UsbAcc.InputStream,device_UsbAcc.OutputStream,"deviceStream")
Catch
End Try
Else
End If
Else
device_UsbMan.RequestAccessoryPermission(device_UsbAcc)
Permission= device_UsbMan.HasAccessoryPermission(device_UsbAcc)
If Permission Then
device_UsbMan.OpenAccessory(device_UsbAcc)
Else
End If
If device_Stream.IsInitialized==False Then
Try
device_Stream.InitializePrefix(device_UsbAcc.InputStream,False,device_UsbAcc.OutputStream , "deviceStream")
Catch
End Try
Else
End If
End If
Else
End If
Catch
'do nothing
ToastMessageShow ("Could not get connected accessories!",False)
End Try
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…