FTDI d2xx driver not reading bytes on Android to communicate with MDB board to Vending Machine

androidftdiuartusb-hostusb-otg

When trying the D2xx driver from FTDI, there was no bytes being read by Android Device.

Below are the codes:

when opening a port to use (since only 1 port in android it is default to the first port in list of devices function from the UARTmanager). followed from one of the answer in this website to use restartintask

private void openFunction() throws Exception
{
    this.ftDev = UARTManager.openByIndex(SerialContext, portToUse);

    if (!ftDev.isOpen())
    {
        throw new Exception("openFunction -- SerialCommunicator: Unable To open FTDI device for communication.");
    }

    this.ftDev.restartInTask();
}

once it connected, tried sending a message:

int status = ftDev.write(byteToSend, byteToSend.length);
this.trace("send Status: " + Integer.toString(status));
  • the Problem here is the status return from the write is always 5, there is no documentation in the FTDI website that tells what meaning of each status return is after write operation. the length of bytetosend was 2

when reading from the hardware containing the FTDI chipset:

public byte serialReadByte()
{
    this.readCompleted = false;

    new ReadAsyncTask().execute();

    while(!this.readCompleted) {}

    if(this.fromSerial != null && this.fromSerial.length > 0)
    {
        return this.fromSerial[0];
    }

    return null;
}

private class ReadAsyncTask extends AsyncTask<Void, Void, Void>{

        @Override
        protected Void doInBackground(Void... arg0) {   

            int totalRead = ftDev.getQueueStatus();

            fromSerial = new byte[1];

            if(totalRead > 0)
            {
                ftDev.read(fromSerial, 1);          
            }

            readCompleted = true;

            return null;
        }

    }
  • the problem here is nothing is being return from the read. Followed from one of the answers here to put it in a thread as seen in current code

out of option here, maybe you guys have any idea about this? the FTDI model is FT230XS-R and using the FTDI Driver's UARTManager.

Searched for other driver available in the internet, only to find it only supports FT232, maybe you guys could suggest a driver that works for the FT230XS-R FTDI chipset?

Best Answer

I'm wondering where you searched for the return values, because if I type "Android D2XX FTDI" into Google it immediately and firstly returns to me this PDF.

Which very simply tells you the return values to check for in each function. In this case (page 47) it's the number of bytes written, not a status.

So it seems you are not sending just 2 bytes and not receiving any data does not have to be in your FTDI system, but can easily be in whatever you connected. Which you do not talk about. If you expect to send 2 bytes and send 5 bytes, it's possible you're also not sending the bytes you think you send.

You also say you tried different Baud rates. What does the hardware connected think of this? Did you reconfigure that? With UARTs, devices need to agree to the communication speed in detail.

It's also possible something else is going wrong in your connection that you forgot to check for, but that I cannot say, since I avoid Java like the plague. (Call it a personal preference)

On page 30 you can also see how to build up checks to prevent any untraceable errors.