• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

FT232 Sample program does not work

kilohercas

Lurker
Apr 8, 2021
1
0
Hello,
I am trying to create program where I use FT2232H in SPI mode. For that I need MPSSE.

So what i need is to open USB, get handle, and when read/write data to chip. I am constantly using this chip with C# and visualBasic

FTDI give example how to use it. Tested on my phone, works very well. Because I am very new with android, I don't know what I am doing wrong.
Using Visual Studio

http://www.ftdichip.com/Support/SoftwareExamples/Androi/TN_147_Java_D2xx_for_Android_Demo_Source.zip

1) Created simple project with empty activity, added button, and text filed, generated interrupt. Goal is press button, connect to USB, or read any data, like how many device channels are connected, since i am using FT2232H, i should get response 2.

2) Copied android manifest lines that are related to USB:
<uses-feature android:name="android.hardware.usb.host" />
<intent-filter>
<action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
</intent-filter>

<meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />

3) In correct location created device_filter file, so my application would trigger if VID/PID match, this is my understanding. And after compiling it does, when I connect USB, android ask what program should i use for USB, so no problem here.


<?xml version="1.0" encoding="utf-8"?>
<resources>
<usb-device vendor-id="1118" product-id="688"></usb-device>
<usb-device vendor-id="1027" product-id="24577" /> <!-- FT232RL -->
<usb-device vendor-id="1027" product-id="24596" /> <!-- FT232H -->
<usb-device vendor-id="1027" product-id="24592" /> <!-- FT2232C/D/HL -->
<usb-device vendor-id="1027" product-id="24593" /> <!-- FT4232HL -->
<usb-device vendor-id="1027" product-id="24597" /> <!-- FT230X -->
<usb-device vendor-id="1412" product-id="45088" /> <!-- REX-USB60F -->
</resources>

4) So in main activity I have button and text field. All I need to do is to check how many channels of high speed USB devices I have. On create I do init.

@override
public void onCreate(Bundle savedInstanceState)
{
try
{
ftD2xx = D2xxManager.getInstance(this);
} catch (D2xxManager.D2xxException ex)
{
ex.printStackTrace();
}
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_layout);
if(!ftD2xx.setVIDPID(0x0403, 0xada1))
{
Log.i("ftd2xx-java","setVIDPID Error");
}

IntentFilter filter = new IntentFilter();
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
filter.setPriority(500);
this.registerReceiver(mUsbReceiver, filter);
}

5) OnClick event I want to read some USB related data;
static Context DeviceInformationContext;
D2xxManager ftdid2xx;
int devCount = 0;
devCount = ftdid2xx.createDeviceInfoList(DeviceInformationContext);
Log.i("FtdiModeControl","Device number = " + Integer.toString(devCount));

Well, here program simply goes to break, and I don't know what I am doing wrong. I don't understand what DeviceInformationContext is, and how do I get it, or what to do with it ? Initialization works ok, no breaks detected.

Any idea what I am doing wrong ? And how to fix it ?

Thank you for any help :)
 

Attachments

  • TN_147_Java_D2xx_for_Android_Demo_Source.zip
    1,006 KB · Views: 201

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones