Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Porting Android Java applications


This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 7 - Last Post: Jul 26, 2016 8:57 PM Last Post By: John Dammeyer
John Dammeyer

Posts: 17
Registered: 10/2/02
Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 23, 2016 5:57 PM
I have a java application for Android that I'd like to port to Delphi Berlin 10.1.
There are two files.

GPIODemoActivity.java

"package com.GPIODemo" includes these.
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ToggleButton;
 
import com.GPIODemo.R.drawable;


And the FT311GPIOInterface.java which includes
package com.GPIODemo; 
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
 
import android.app.Activity;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbAccessory;
import android.hardware.usb.UsbManager;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.widget.Toast;


The point of the application is to communicate with the FTDI FT311D device connected to the USB port. The sample APP works with the hardware so my starting point is at least good hardware. But I'd like to write the entire thing in Delphi or be able to include the java libraries.

How do I start?

Edited by: John Dammeyer on Jul 23, 2016 6:03 PM
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 23, 2016 7:17 PM   in response to: John Dammeyer in response to: John Dammeyer
John Dammeyer

Posts: 17
Registered: 10/2/02
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2016 5:13 PM   in response to: Eli M in response to: Eli M

Thank you. That was very helpful. Unfortunately the github link is missing over 2000 files but I'm sure it's probably available somehow.

I did download the winsoft demo and managed to get it to echo characters with tx looped back to rx. However, and this will be a question for winsoft, I ran into two issues.
Really hard to debug the Delphi app on the tablet when the app needs the FT311D connected to the USB port. I think that has to be filed under "that's life". Too bad the tablet doesn't have two USB ports.

The real problem I ran into was the Open/Close Button operation. The port opened and closed but then that was it. Since the code looks like the port should re-open the question was how to figure out what was happening. The text on the Open/Close button also didn't change.

Ultimately I commented out the FTDI winsoft/android code and added a windows target to the project. A message added to the TMemo object every time the button was pressed showed the code worked and the button toggled correctly. Next, deploy it to the table with the android stuff enabled but still all references to FTDI and winsoft disabled. Again the TButton code correctly toggled the text on the button.

Re-enable the winsoft FTDI and once again the application locks up on the close operation. In fact switch to another app and then try and bring back the demo and it's locked up. At one point only by disconnecting the USB cable was I able to unlock the entire tablet.

So something in the CloseAccesssory function is badly broken since the demo application never makes it back to change the text to 'Open Port'.

  if FDoClose then
  begin
    FTracking := False;
    FComPort.CloseAccessory;
    ButtonOpenClose.Text := 'Open Port';
    FDoClose := False;
  end


I'll port results of my research when I have it.
John Dammeyer

Posts: 17
Registered: 10/2/02
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2016 7:15 PM   in response to: John Dammeyer in response to: John Dammeyer
I'll port results of my research when I have it.

Great response from WINSOFT and an answer that makes sense. For now I'll consider this question answered.

"it's the known limitation of FT311: there is no way to detect whether some
character is available, so read method has to be called on input stream.
However, there is also no way to cancel this call without reading some
character. So to avoid locking you need to receive extra character
after calling close, so the last read method can be completed. I've tried
to find some workaround, but without success. The registered version
contains full source code, so it can be used for debugging and testing."

Eli M

Posts: 1,346
Registered: 11/9/13
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2016 9:59 PM   in response to: John Dammeyer in response to: John Dammeyer
Not missing. Just not shown in that list. You can get at them via search or by download the whole thing.

John Dammeyer wrote:
Thank you. That was very helpful. Unfortunately the github link is missing over 2000 files but I'm sure it's probably available somehow.
John Dammeyer

Posts: 17
Registered: 10/2/02
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 24, 2016 10:39 PM   in response to: Eli M in response to: Eli M
Eli M wrote:
Not missing. Just not shown in that list. You can get at them via search or by download the whole thing.

John Dammeyer wrote:
Thank you. That was very helpful. Unfortunately the github link is missing over 2000 files but I'm sure it's probably available somehow.

Thanks for the feedback.

Here's the issue in the code direct from FTDI app note.

"The issue occurs when an application comes to an end due to the user putting it to the background
or running another application. The read thread holding the FileInputStream does not clean up and
exit, because the FileInputStream.read() is still in block-reading, and not able to return as
expected. One way to overcome this limitation is to send an END request defined by users and
have the connected UART device respond with an OK signal to let the read() return."

I really want to use the Delphi concept of one application, multiple targets. But the target OS ultimately decides what has to happen.

Truthfully I miss the days of the CUA document that stipulated what a user interface should look like so that users didn't have to deal with 100 different flavours of interacting with their computer.

Anyway, if I can get the WINSOFT app to not crash when it's minimized (so to speak) then I think that will be the solution.

John
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 26, 2016 8:22 PM   in response to: John Dammeyer in response to: John Dammeyer
John Dammeyer

Posts: 17
Registered: 10/2/02
Re: Porting Android Java applications  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 26, 2016 8:57 PM   in response to: Eli M in response to: Eli M

Not possible as I understand.
"FileInputStream.read() is still in block-reading"

To get it out the attached device has to send a character. The easiest way is to have the attached embedded system issue a periodic heartbeat character.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02