Note that there are some explanatory texts on larger screens.

plurals
  1. POUSB host transfer Android with Spartan 6 FPGA
    primarykey
    data
    text
    <p>So I need to write an app in Android that must be able to read data that comes from a FPGA SPARTAN 6.</p> <p>My app is able to identify when the usb is connected, and can get info about interfaces and endpoints over that interfaces. But then it needs to read data that someone sends when a button is pressed, and this is when the app fails.</p> <p>My code is as follows:</p> <pre><code>package com.example.usb; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.hardware.usb.*; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.widget.TextView; public class MainActivity extends Activity { private UsbManager usbManager; private UsbDevice device; private TextView tv; Handler handler = new Handler() { public void handleMessage(Message m) { Integer datos = (Integer)m.obj; tv.setText(datos + "\n"); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView)findViewById(R.id.tv); usbManager = (UsbManager)getSystemService(Context.USB_SERVICE); } @Override protected void onResume() { super.onResume(); Intent intent = getIntent(); String action = intent.getAction(); if (action.equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) { //conectar dispositivo device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE); //muestraDatos(device); UsbInterface intf = device.getInterface(1); UsbEndpoint epIN = getIN(device); //tv.setText(epIN.getDirection() + " " + epIN.getType()); UsbDeviceConnection connection = usbManager.openDevice(device); new Thread(new Read(connection,intf,epIN,handler)).start(); } } private UsbEndpoint getIN(UsbDevice device) { UsbInterface intf = device.getInterface(1); UsbEndpoint ep = null; int numep = intf.getEndpointCount(); for (int i = 0 ; i &lt; numep ; i++) { UsbEndpoint aux = intf.getEndpoint(i); if (aux.getDirection() == UsbConstants.USB_DIR_IN &amp;&amp; aux.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { ep = aux; } } return ep; } </code></pre> <p>And the Thread Read (which is supposed to read from FPGA) is:</p> <pre><code>package com.example.usb; import android.hardware.usb.UsbDeviceConnection; import android.hardware.usb.UsbEndpoint; import android.hardware.usb.UsbInterface; import android.os.Handler; import android.os.Message; public class Read implements Runnable { private UsbDeviceConnection connection; private UsbEndpoint epIN; private Handler handler; private UsbInterface intf; public Read(UsbDeviceConnection connection,UsbInterface intf,UsbEndpoint epIN,Handler handler) { this.connection = connection; this.epIN = epIN; this.handler = handler; this.intf = intf; } public void run() { byte datos[] = new byte[50]; int read_data = 0; if (connection.claimInterface(intf,true)) { /*Message sms = new Message(); sms.obj = "Success caliming interface: " + intf.getEndpointCount(); handler.sendMessage(sms);*/ //connection.controlTransfer(0x00000080, 0x03, 0x4138, 0, null, 0, 0); while (true) { try { Thread.sleep(500); } catch(InterruptedException e){} read_data = connection.bulkTransfer(epIN, datos, datos.length, 100); datos = new byte[50]; //if (read_data &gt; -1) //{ Message sms = new Message(); sms.obj = read_data; handler.sendMessage(sms); //} } } else { Message sms = new Message(); sms.obj = "Fail claiming interface "; handler.sendMessage(sms); } } </code></pre> <p>}</p> <p>My goal here is just to show the number of bytes that are read with the function bulktransfer, but it does not show anything. Also, I belive I have to use the controlTransfer function, but the official documentation does not explain anything about the function, it is just a dark reference. I have seen posts like this <a href="https://stackoverflow.com/questions/9938729/android-4-0-3-usb-host-sending-data-via-controltransfer">Android 4.0.3. USB Host - sending data via controlTransfer</a> and this <a href="https://stackoverflow.com/questions/12669093/serial-to-usb-android-application-with-health-device">Serial to USB Android application with health device</a> but it is not very clear about what is the meaning of every parameter in the function. Anybody knows what Im doing wrong and/or has a good explanation about the controTransfer function?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COYou'd want to start by having a much better of idea of what operations **exactly** your hardware device requires - that's not going to be something that someone without the documentation for the particular device you are using will know, unless you are able to say that it implements some particular well known scheme. Do you really implement the USB engine directly in the FPGA (possible but uncommon) or are you using a USB interface chip?
      singulars
    2. COWell, I certanly didnt implement anything in the FPGA. The FPGA is supposed to send a string of bits, and I need to capture those bits. The person who has the FPGA implemented a read program in labview, and from that he can read what the FPGA is sending. I dont know anything of labview or electronics, Im just working with the host API that comes with Android, but again, it does not work. And I dont know what kind of operations the hardware device requires, Im completley lost here, that is why im asking for a hand. Thanx.
      singulars
    3. CONo one can help you until you provide comprehensive documentation of your custom hardware - the parts that you completely ignored in your response above. You will have to ask the board / fpga developer for information on its USB interface, without which you cannot use the board with Android *or any other USB host*.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload