USB communication, Android phone with special hardware (with phone modul and usb/bluetooth)

Hello I need information if the current version of xamarin.Android contains the implementation USB communication with other devices. I found it no examples or documentation (the documentation is solved USB for debugging, but it is not my case).

Currently I Commissioning communication with the target device via bluetooth (BluetoothAdapter, BroadcastReceiver, get bluetooth device form intent.GetParcelableExtra (BluetoothDevice.ExtraDevice) etc.).

I guess that the USB communication should be like bluetooth.

I found some info regarding UsbManager, UsbDevice, UsbAccessory, but it works differently and I'm not able to make it work.

Thank you for more info

Tagged:

Best Answer

Answers

  • MichalFrantaMichalFranta CZMember ✭✭

    Hi, i find that the problem was in Android version on my Phone. If i test tablet and other phone with android version 4.4.2 than it find usb device correctly.
    In doccumentation
    androidapi.xamarin.com/index.aspx?link=N%3AAndroid.Hardware.Usb writes that it shall works on 3.1 and newer but MyPhone has 4.1.1 and does not work well. I will use newer version android and it will be OK.

    This question is answered and can be closed.

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    @JamieHouston I have to send some characters to the Device discovered... I can I do? Do I have to use UsbEndpoint?
    Thanks

  • YassineMAMAYassineMAMA Member ✭✭

    Hello,
    im working in android xamarin project , and i want send a string data ("WR11100_r") to serial port, so currently i can find my dvice and i can open it but i cant't send data i think i must set control Trasnfer before sending data, the config of my dvice is :
    Baud rate 9600 bits per second
    Data bits 8
    Stop bit 1
    Parity None
    Flow control No
    so i tried this code, but its dosent work :
    string cmd = "WR11100/n";
    byte[] buff = System.Text.Encoding.ASCII.GetBytes(cmd);

                        deviceConnection.ControlTransfer(0, 0, 0, 0, null, 0, 0);// reset
                        deviceConnection.ControlTransfer(0, 2, 0, 0, null, 0, 0);// flow  control none   
                        deviceConnection.ControlTransfer(UsbAddressing.Out, 3, 16696, 0, null, 0, 0);
                        deviceConnection.ControlTransfer(0, 4, 8, 0, null, 0, 0);
    
    
                        deviceConnection.BulkTransfer(usbEndpoint, buff, 0, 8, 0);
    

    when the bulkTransfer instrucion is exectued the buff[0] = 0 and the buff[1] = 96 so i think there is a probleme in my config can you help me plz such you was working working on a project that uses the Android device as a USB Host to connect to a separate USB device

Sign In or Register to comment.