Java Question Create a B4A library from a Java source

krokiz

Member
Licensed User
Longtime User
Hi, Marcob
I just read your post, and am going to test your library. I want to appreciate your work, definately! I still want to explain my project and ask some questions:
I am having an external piece of a hardware, equipped with FT232RL and a microcontroller, which is sending (continuously) packets of 581 bytes, with a about 1 msec pause between the packets. The Android app needs to receive these packets WHENEVER they arrive, without constantly polling for them (the arriving packets are like interrupting events to the software). With your library, I probably need to use a timer, which would take over once in a 10 mSec and read the incoming data (if there is data: the hardware may be switched off from time to time). In case there is a data received, it should be processed further.
I used to use UsbSerial Library from B4A (AGraham) and it uses AsyncStreams class, which uses methods like:
...astreams.Initialize(usb.GetInputStream, usb.GetOutputStream, "astreams")
...Sub Astreams_NewData (Buffer() As Byte)
...Sub Astreams_Terminated
...Sub AStreams_Error
in this implementation, the most valuable method for me is Astreams_NewData, which gives me the received data, WHENEVER it arrives
and there is no need to repeatedly poll for data.
So my questions are:
If there is no chance for you incorporate AsyncStreams to work with your library, would it be better solution for me to use a timer and repeatedly ask for data (mSerial.read(buf)) ?
Why there is a chance to have data lost? (perhaps this questions requires a long answer, so just please answer:) What if my packets are 581 bytes long, and would there be data lost since the USB packets are (are they?) 64 bytes long?
Thanks in advance for your answers!
I am starting tests with your library right now and will keep you informed.
Best regards: Krokiz

to Toley:
Quote: "Hi krokiz, can you tell us what do not work for you in the usbserial 2.3 library ?"
I used the UsbSerial library by AGraham, and it kept giving me an error ("Expected at least 2 bytes (IOexception.....)") when working with FT232RL, UNLIKE when using CP2102, it works perfectly with the latter chip. So I got sad, because I have used and intent to continue to use FTDI chip in my hardware. Here is why I am asking so much for this NEW FTDriver Library.

Best regards: Krokiz
 

Marcob

Member
Licensed User
Longtime User
Just curious. Did you use the same JAVA code from your original post and wrap it? or Did you find a different JAVA code?

Yes, I used the original post and I followed the suggestions of agraham. The key point was to write a dedicated method (Initialize) through which it is now possible to pass the parameters requested by the original FTDriver constructor.
 

Marcob

Member
Licensed User
Longtime User
If there is no chance for you incorporate AsyncStreams to work with your library, would it be better solution for me to use a timer and repeatedly ask for data (mSerial.read(buf)) ?

Hi krokiz,
Unfortunately I currently have neither the time or the skills to do it, perhaps in the next future...
Anyway, I think your program could use a dedicated thread (see Threading library) to poll the receiving buffer and then trigger a call to your main as soon as the whole packet is received.
For example, you can start a thread in a dedicated module of your program and inside it you can manage as you wish the incoming data bytes and then trigger a CallSub(module,eventName). In your main you will arrange a sub named eventName that will be automaticaly invoked every time you get a complete data packet (and perhaps this will be for you even better than Astreams_NewData() because now each invocation correspond exactly to a complete packet :)).

Why there is a chance to have data lost? (perhaps this questions requires a long answer, so just please answer:) What if my packets are 581 bytes long, and would there be data lost since the USB packets are (are they?) 64 bytes long?

I don't know now, but I'm going to discover it soon because I'm also developing an application that needs to receive data packets larger than 64 bytes. I will let you know...
 

Jaime Ramirez

Member
Licensed User
Longtime User
I am trying to use the FTDI
Hello,

after some attemps I was able to implement FTDriver in a B4A library.

This library should support the following FTDI devices:

- FT232RL
- FT232H
- FT2232C
- FT2232D
- FT2232HL
- FT4232HL
- FT230X

I have tested it with FT230X and it works (tested on Zopo C2, Android 4.2.1).

Attached you find the library and a simple example on how to use it.

If you test the library, please post a feedback reporting the android device/version used.

Disclaimers: this is the first release, I'm not a Java/B4A Veteran and of course there is no warranty that it works flawlessly...

I hope this helps :)
Hello,

after some attemps I was able to implement FTDriver in a B4A library.

This library should support the following FTDI devices:

- FT232RL
- FT232H
- FT2232C
- FT2232D
- FT2232HL
- FT4232HL
- FT230X

I have tested it with FT230X and it works (tested on Zopo C2, Android 4.2.1).

Attached you find the library and a simple example on how to use it.

If you test the library, please post a feedback reporting the android device/version used.

Disclaimers: this is the first release, I'm not a Java/B4A Veteran and of course there is no warranty that it works flawlessly...

I hope this helps :)
Hi:

I am trying to use your library with no success android4.1.2 on a samsung i9070 phoe to communicate with an FTDI FT232 device, I am getting a "can not connect" error regardless of the comm speed set, Do I have to add something to the manifest editor?, any help is truly welcome.
 

raphaelcno

Active Member
Licensed User
Longtime User
I am trying to use the FTDI
I am trying to use your library with no success android4.1.2 on a samsung i9070 phoe to communicate with an FTDI FT232 device, I am getting a "can not connect" error regardless of the comm speed set, Do I have to add something to the manifest editor?, any help is truly welcome.

Did you try the newer UsbSerial library that includes support for FTDI ?
http://www.b4x.com/android/forum/threads/usbserial-library-2-0-supports-more-devices.28176/
 
Top