Using serial with FTDI

I had a look at the driver:

Name of device: What is directly available from the library is the driver name like ”com.physicaloid_ai.lib.usb.driver.UartWinCH34x”. This can easily be added to the extension.

For performance: try the function that returns all available bytes in a list. I accidentally gave it the name ReadSerialHexList() (will be renamed). Also next version will be compiled as release with debug logging inhibited.

When we initiate a serial connection in the application, android asks for permission. The content of the permit includes the name of the device, eg "Bridge USB to UART CP2102". I thought this name could be returned.

From what I can see it’s hidden inside the library now. The solution to this has to wait until later.

For example, the USB Terminal application which also uses this driver has the function of displaying the device name.

@rkl099 Just circling back to this. Please let me know if you'd be interested in offering this as an improvement over the existing Serial component.

I will be glad to contribute to Appinventor. I will soon contact you about the best way to integrate the new library and serial component.

I have now updated SerialOTG as discussed earlier. This is the first release version of the extension and can be found at:


The previous version can be found at:

Is it possible to add an intent to the manifest file and a list of xml devices to which the application should react from the extension level?
I do this by editing the APK but maybe it is possible to do it automatically?

Hi, I've been experimenting with SerialOTG having had no luck reading data from a sensor device using the standard App Inventor Serial blocks.
If you are open to adding additional functions, I would really appreciate the ability to read a message with user defined start and end characters. In my particular application, a meassage can come in varying numbers of bytes but each message begins with a SOT (Hex 02) character and ends with an EOT (Hex 03) character. Alternatively, could you suggest how I could adapt your SerialOTG sample to collect such messages individually.
Many thanks. You've done a great job with this component and I would support it replacing the current Serial component in App Inventor.
Great job!

1 Like

I understand your problem. It’s a common way to send messages.
A problem with this implementation of Appinventor and SerialOTG is that they are executed in the same thread. The result is that you have to use polling of incoming bytes, otherwise the UI will be locked. Even if I expose the callback function that is implemented in the library, I will just be notified that x number of bytes have been received.

There is one simple solution to your problem if you only use 7-bit ASCII between the STX/ETX characters. I can maybe make the end character in readBytes() selectable (I considered this but preferred to make it simple). Then you can poll for an incoming message with a timer, delete all character up to STX and you have your message.

In general you must use state machine to solve this kind of problem. Something like this:

In timer activated routine:
State 1, poll until STX. Wen found, goto state 2
State 2, collect characters until ETX, goto state 3
State 3, notify consumer that message is received.

Consumer:
take care of message, reset to state 1

If you have arbitrary bytes between STX/ETX, than you need some handling of an escape character.
ESC-STX replaces STX, ESC-ESC replaces ESC and ESC-ETX replaces ETX. This make it more complicated.

2 Likes

How long is your data? If not too long then you can do it with the available blocks, read data byte by byte with the clock.

Could be 2k - 3k per message with some messages only about 100 bytes.

The library buffer is 1024b, so if you have a 3k message then you have to read multiple bytes in a loop or with a short timer period to avoid overrun. Maybe it’s impossible at a high baudrate.
ReadBytes() to list is the fastest method. It will read all bytes received and return a list. List length shows the number of bytes received.

1 Like

Thanks. That is helpful. The transmitting baud rate I need to handle is 115200. I can read the data OK using SerialOTG but my challenge is identifying the SOT and EOT characters to split out individual messages. I'll follow your advice and see how I get on. Thanks for your help.

Interesting to hear about advanced applications. Please let me know how it goes.

If you have problems with blocks, feel free to ask.

Src for Appinventor suggested new Serial component, SerialOTG extension, src and precompiled libraries are now available at:

I've put together some blocks that seem to correctly extract messages enclosed between STX and ETX characters from individual strings that include full or partial messages.
My challenge for another day is to adapt them to read bytes from a list populated by using the ReadBytes() procedure on a serial port as suggested by rkl099. I presume I may need to stop and start the timer clock used to poll the serial port to allow my blocks to extract, decode and process messages? Oh for a "GetMessage" function in a serial component. SerialOTG has certainly helped me make more progress than I thought I would when trying to use the App Inventor standard serial component.

Yes. The serial embedded component has deficiencies in the drivers. It will soon be replaced by an extension created by @rkl099

1 Like

After some requests and learning more about PhysicaloidLibrary, I have added support for more CDC ACM devices:
Feather M0 VID 239A, Teensy 4.0 VID 16C0, OpenCR VID 0483.
The updated extension can be found in a debug version at:

Are there any more requests?