A dirty and quick example of serial port communication in Android

Since I released UsbSerial I have received good feedback about its performance but I also have received messages with some legit doubts about how to use it. I finally overcame laziness and I have publish a little example of how to use UsbSerial correctly in a real app. Here it is the source code, just two java source code files 🙂

Disclaimer: If you are looking for a serial terminal for Android, DroidTerm is what you need, this is just a quick example

An overall description of how it works:
– UsbService.java contains a Service to isolate all Usb operations. Interesting things happens there. If you need to change baud rate, stop bits and son those lines are located there. It is a good pattern to implement open connections in a Service so I encourage you to do it this way.

– When App starts, UsbService is created and will try to connect with an attached usb device. if there is one device compatible it will connect with it and data will be able to be sent and received. If no devices are attached, it will inform the user through a toast. The app will be still listening for new usb attached devices.

– Data received will appear in the white box, Send button will send the data wrote into the EditText.

Screenshot_2015-01-09-17-52-48

Although pretty simple and it does not have any particular goal (besides being an explanatory app), it could have some bugs so If you find something just let me know opening an issue on github.

Happy coding!

Advertisement

DroidTerm v6.2 USB Serial port for Android

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

I start this new year with a new DroidTerm update. Every month this little utility is getting more and more useful and reliable. Today I am going to present two new features I added some weeks ago but I didn’t document anywhere.

-Profile logs
Since v5.0 DroidTerm allows to create connection profiles avoiding annoying configuration setup each time you connect your devices.
Screenshot_2014-10-16-21-34-44
DroidTerm v6.2 creates a log file each time a connection profile is created and that file is updated (opened, written and closed, so synchronization with cloud services like Dropbox is possible) every time something is received. It is still possible to save logs the same way, even if you are working within a connection profile.

Keyboard input options
DroidTerm v6.2 has an option to change the way it sends an end of line. There are three options
Screenshot_2015-01-05-17-49-15

New year proposals
Like loosing weight and giving up smoking, I am thinking about a couple of major improvements I should do as a new year proposal. One of them is a kind of scripting language(and a graphic interface to code easily from the device) and the other is adding support to emulate ANSI escape codes (VT100). Just proposals 🙂