Java Question Create a B4A library from a Java source

warwound

Expert
Licensed User
Longtime User
That looks like a Java library which could be made into a B4A library.

BUT i'd say if this is your first attempt at creating a B4A library then start with something much simpler just to get to know how to create a library and how the library code interacts with your B4A project.

What are your Java skills like?

I'd suggest you use the B4A AbsObjectWrapper when you progress to writing the FTDriver library.

Martin.
 

Toley

Active Member
Licensed User
Longtime User
Thank you Martin,

Unfortunately my Java skills are very low... I will take a look at the tutorial you sent. But I probably rather wait for a more experienced programmer to port it.
 

Toley

Active Member
Licensed User
Longtime User
Yes for sure. USB Serial Monitor use this library and it works very well.

https://github.com/ksksue/Android-USB-Serial-Monitor-Lite

https://play.google.com/store/apps/...GwsMSwxLDEsImpwLmtza3N1ZS5hcHAudGVybWluYWwiXQ..

Edit : I've try to inform agraham of the existence of this library via a reply to this post http://www.b4x.com/forum/basic4andr...connecting-external-usb-device.html#post81506 but I believe he missed it.
BTW I'm ready to donate a small amount to anyone who port this library to B4A, and I'm sure I'm not the only one.
 
Last edited:

agraham

Expert
Licensed User
Longtime User
I did miss it as the forum has not been posting notifications to me (Erel has now fixed this).That Serial Monitor library appears to use the FTDI Android library which I cannot run as it errors on my Xoom. Both Erel and I have tried to use that FTDI library and failed for different reasons, Erel sent me his FTDI module when it didn't work for him and I couldn't get it to work either. See http://www.b4x.com/forum/basic4andr...connecting-external-usb-device.html#post81506. If I can summon up the will I might try again but the flaky Android USB support has caused me so much grief that I'm not sure I can ever be bothered to try again.
 

Marcob

Member
Licensed User
Longtime User
Hello, one year has elapsed from the previous post, is there nothing new about it ?

I would like to interface a FTDI FT230X but unfortunately the UsbSerial v2.3 doesn't support it.

I found a driver and an example (here attached) of a Java code that compiles and works with eclipse and I would like to port it on B4A. I tried to make a B4A library by myself but after getting some error messages I realize to have an insufficient knowledge of Java for this.

Is there someone here that could make an attempt ?

This library will work with a lot of newer FTDI devices and I think it would be useful for many others.
 

Attachments

  • FTDriver.zip
    54.7 KB · Views: 557
  • FTDriverTutorial1.zip
    110 KB · Views: 586

giga

Well-Known Member
Licensed User
Longtime User
Hello, one year has elapsed from the previous post, is there nothing new about it ?

I would like to interface a FTDI FT230X but unfortunately the UsbSerial v2.3 doesn't support it.

I found a driver and an example (here attached) of a Java code that compiles and works with eclipse and I would like to port it on B4A. I tried to make a B4A library by myself but after getting some error messages I realize to have an insufficient knowledge of Java for this.

Is there someone here that could make an attempt ?

This library will work with a lot of newer FTDI devices and I think it would be useful for many others.

Here you go ***NOT TESTED COMPLETELY***USE AT YOUR RISK*** I am not 100% familiar with this JAVA code but I got it to recognize in B4A. GOOD LUCK.
If it does not work Please advise and I will request removal. :sign0089:
Library removed due to errors
 
Last edited:

Marcob

Member
Licensed User
Longtime User
Thank you for your library.
Unfortunately it doesn't work.

When you try to instance FTDriver:

B4X:
Sub Globals   

   Dim mSerial As FTDriver
   
End Sub

You get the following error:

B4X:
javac 1.7.0_21
src\b4a\example\main.java:323: error: constructor FTDriver in class FTDriver cannot be applied to given types;
mostCurrent._mserial = new jp.ksksue.driver.serial.FTDriver();
                       ^
  required: UsbManager
  found: no arguments
  reason: actual and formal argument lists differ in length
1 error

I think the constructor of FTDriver class expects to receive the following parameter:

(UsbManager)getSystemService(Context.USB_SERVICE)

but I don't know how to pass it.
I read in some old posts that someone had the problem of passing parameters to a constructor of a custom library and there seems to be a way to do it.

I hope we can receive here some hints about this specific issue :)
 

giga

Well-Known Member
Licensed User
Longtime User
Marcob "Quote: I tried to make a B4A library by myself but after getting some error messages"

Originally When you tried an received errors was this in Eclipse or did you get it into B4A and get errors?

I can check the current JAVA code and try to see what this error is
B4X:
javac 1.7.0_21src\b4a\example\main.java:323: error: constructor FTDriver in class FTDriver cannot be applied to given types;
mostCurrent._mserial = new jp.ksksue.driver.serial.FTDriver();                       
^  required: UsbManager  
found: no arguments 
 reason: actual and formal argument lists differ in length1 error

can't guarantee but will try.
 

Marcob

Member
Licensed User
Longtime User
Hello giga, the code I have attached on post #7 compiles and works fine on Eclipse.

I tried (as you did) to make a B4A library but then I had to stop because of the error I mentioned in my previous post.
This is an error issued by the B4A environment and has nothing to do with Eclipse.

The reason of this this failure lies in the constructor call; if you look at the Java code of the example program (FTDriverTutorial1.zip) you will see that the instance is created with:

mSerial = new FTDriver((UsbManager)getSystemService(Context.USB_SERVICE));

Using B4A we need at the same way to pass the UsbManager object (created by calling getSystemService(Context.USB_SERVICE)) to the FTDriver constructor but I don't know how to do it.
Perhaps that could be done with some tricks (wrapping FTDriver class in a B4A AbsObjectWrapper ?), I feel this can be a trivial thing to a B4A "guru" but unfortunately I currently are not able to solve :(
 

agraham

Expert
Licensed User
Longtime User
You are trying to implement the driver directly instead of wrapping it. I would have the driver as a private class and the public FTDriver would have a private field of type ActualFTDriver (or whatever) and I would create that in an Initialize method and expose the fields and methods of that ActualFTDriver instance through the properties and methods of my public FTDriver class.
 

giga

Well-Known Member
Licensed User
Longtime User
You are trying to implement the driver directly instead of wrapping it. I would have the driver as a private class and the public FTDriver would have a private field of type ActualFTDriver (or whatever) and I would create that in an Initialize method and expose the fields and methods of that ActualFTDriver instance through the properties and methods of my public FTDriver class.

I will revisit it and try to correct this.
 

krokiz

Member
Licensed User
Longtime User
FTDI library for B4A

Yes for sure. USB Serial Monitor use this library and it works very well.

https://github.com/ksksue/Android-USB-Serial-Monitor-Lite

https://play.google.com/store/apps/...GwsMSwxLDEsImpwLmtza3N1ZS5hcHAudGVybWluYWwiXQ..

Edit : I've try to inform agraham of the existence of this library via a reply to this post http://www.b4x.com/forum/basic4andr...connecting-external-usb-device.html#post81506 but I believe he missed it.
BTW I'm ready to donate a small amount to anyone who port this library to B4A, and I'm sure I'm not the only one.


Hello, you guys,
I personally greet you for trying to make this project true!
I recently bought the B4A for the purpose of writing an Android App for a FTDI equipped hardware. The app I made uses the standard UsbSerial library that comes with the B4A, but it happen to work only with CP2102, but not with the FTDI chip (I tried only these 2 chips). I really need the FTDI support for my app, since I sell devices which are equipped with FTDI, and wanted to surprise my old customers, and the new ones (of course), giving them an Android app to use.

I want to confirm that this App:
https://play.google.com/store/apps/...GwsMSwxLDEsImpwLmtza3N1ZS5hcHAudGVybWluYWwiXQ..
works great on my MP777, Android 4.1.1, so it would worth if had a library for B4A for FTDI chips. More: many FTDI chips are supported, new ones, and many people would use them in the near future.

I hope you will succeed !
Krokiz
P.S. I am authorized to make a small donation to a person who make this one working.
 

krokiz

Member
Licensed User
Longtime User
FTDriver

Hello, guys
Is there any progress on creating a B4A library for the FTDI (FTDriver) ?
I hope your efforts are still on.
Still this projects (USB Serial Monitor Lite by KSKSUE), is most probably based on his FTDRIVER project, and it proved to be working fine with FTDI chips like FT232RL, I really hope it the B4A Library will be quite useful to many people, including me !
Don't Give Up, Guys ! You are my only hope :)
Please, keep me posted on your progress and success.
best regards, Krokiz
 

Toley

Active Member
Licensed User
Longtime User
Hi krokiz, can you tell us what do not work for you in the usbserial 2.3 library ?
 

Marcob

Member
Licensed User
Longtime User
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 :)
 

Attachments

  • FTDriver_Example.zip
    234.8 KB · Views: 549
  • FTDriver_v10.zip
    15.2 KB · Views: 510
Top