DroidTerm v4.0 USB Serial port for Android

Last information about the current state of DroidTerm. Please check it out

Some weeks ago I uploaded a new version of DroidTerm with some improvements. One of these improvements was a log system to save your session. Well I made some changes that allow view your logs inside your app. Press “Log Viewer” and choose your log.
Screenshot_2014-08-28-21-18-33

I added a new way to send data. In prior versions users had to click on terminal and send one character at a time. This way is not gone but now it is possible to send more data at a time.
Just connect your device, start your session with your settings, press option button and select “Send bulk data”
Screenshot_2014-08-28-21-19-17

DroidTerm is getting more complete each month and I almost lack of missing features. If you are using it and you have a good idea I would love to hear it 🙂

Happy crafting!

Speeding up SQLite insertions for Android developers

SQLite is a very important asset of every Android programmer. It offers a really easy to use solution to cache all your data. As a local database, most of the time, it is not going to suffer of heavy insertions. But sometimes you are going to have to insert a lot of rows and, if you are not very well informed, you are going to discover in a painful way that the common way of insert data using Android api is astoundingly slow. I had to deal with that blow when programming DroidTerm because I needed a local database of USB vids and pids (Naively I started to look for REST api or something like that. Eventually I found something…that was merely a web hosted text file).

These examples are based on code I wrote working on this and code is available here.

Mainstream insertions
This is what you are going to find first time you have to populate a SQLite database in Android.

private SQLiteDatabase db;
/*
...............
*/
public long insertEntryVersion(String version, String date)
{
    ContentValues values = new ContentValues();
    values.put(VERSION_COLUMN, version);
    values.put(DATE_COLUMN, date);
    values.put(ID_VERSION, currentVersion);
    return db.insert(VERSION_TABLE, null, values);
}

It is an easy way using Bundle-like ContentValues class to store data per column and inserting through SQLiteDatabase.insert(String table, String nullHack, ContentValues values) without messing with your own SQL statement, nice huh? Well, most of the times I use this and works fine but if you are going to perform a heavy insertion you are going to discover that inserting…let´s say… thousands of rows can last for more than a minute or even more!

But it is not a big deal when you know what you need to speed up insert operations. Compiled statements, and even more important, SQL transactions are going to save the day.

Not all is lost
Compile your insert instructions as follows:

private SQLiteDatabase db;
/*...*/
private static final String INSERT_VENDOR = "insert into vendorTable(vid,vid_name) values(?,?)";
/*... */
insertVendor = db.compileStatement(INSERT_VENDOR);

Our SQL statement is now compiled so We are going to create a function to handle it.

public void insertEntryVendor(String vid, String vidName)
{
    insertVendor.bindString(1, vid);
    insertVendor.bindString(2, vidName);
    insertVendor.execute();
    insertVendor.clearBindings();
}

And it is all ready to insert all our data much faster!

String[] vidPid = new String[2];
db.beginTransaction();
while(vidPid != null)
{
    vidPid = vidPidGenerator(); // Returns null when no more vid and pids are available
    if(vidPid != null)
    {
        insertEntryVendor(vidPid[0], vidPid[1]);
    }
}
db.setTransactionSuccessful();
db.endTransaction();

It is that simple! I hope you found this little help useful 🙂

Happy crafting!

DroidTerm v3.0 USB Serial Port for Android

Last information about the current state of DroidTerm. Please check it out

I uploaded a new version of DroidTerm some days ago with some changes I would like to share with you. First of all, I decided to drop Bluetooth SPP (Serial Port Profile) support from DroidTerm. I did not consider it my first goal when I started to develop my app. I was struggling to find a great replacement in Android for Putty as a serial terminal so that became my first objective and, eventually, I decided to add support of Bluetooth SPP because it would be a not difficult task. Months later I spent hours refining the USB serial interface of DroidTerm adding devices, fixing bugs… so now It is pretty stable. Unfortunately I almost forgot completely about bluetooth. So it was not so stable at all and I have decide to focus on USB stuff.

Now the good things! You can generate logs of your sessions and keep them for further study. Saving a log of your session is easy:
– Connect your USB-Serial device and configure it as you want.
– Press options button whenever you want.
Screenshot_2014-08-14-17-19-24
– Select “Save Log” and your session will be saved in a folder called DroidTerm in your SD card. Files follow this name convention:

YYYY_MM_DD__HH__MM_SS.txt

The text files generated by DroidTerm save not only raw data (Text or Hex representation as We will see next) but metadata of session too.

#Date: 2014/08/06 13:58:19
#Device Name: FT232 USB-Serial (UART) IC
#Baud rate: 9600
#Data bits: 8
#Stop bits: 1
#Parity: None
#Flow: None

0x6C 0x6B 0x6B 0x6C 0x6B 0x6B 0x6C 0x6A 0x64 0x64 0x61 0x61 0x61 0x61 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x41 0x20 0x4D 0x65 0x20 0x6C 0x6C 0x61 0x6D 0x6F 0x20 0x46 0x65 0x6C 0x69 0x70 0x65 0x20 0x79 0x20 0x65 0x6F 0x73 0x20 0x66 0x69 0x66 0x6A 0x64 0x6E 0x20 

The next improvement, as you may noticed before, is a Hexadecimal representation of received data. I missed that really useful feature when you are debugging, or gaining understanding of a protocol and you need the raw data.

Here an example received from a scrollable LED with String representation:

Screenshot_2014-08-14-17-51-36

Obviously except first bytes information is not encoded at all. So Hex mode is necessary to study how this scrollable Led communicates with host:

Screenshot_2014-08-14-17-52-12

I have more improvements in mind but They will have to wait for a next release.

Happy craft!