Archive for April, 2012

Solved: Can’t connect to high (>10) Windows COM ports / cleaning out unused COM ports

Problem: Windows, and many Windows apps that use serial (COM) ports, have various problems accessing “high” numbered COM ports. I cannot find an authoritative or quantatative definition of “high” (and it may depend on your app), but I have seen apps start failing after COM8, COM9, COM15… anything in the 20s is asking for trouble. If you are a developer and routinely plug in different “serial” devices (including USB gadgets with virtual COM support, Bluetooth dongles, Arduinos etc.) Windows will happily assign a new port number to each one until something breaks and you go hunting for this post.

Depending on the application, the “s**t-the-bed” breakover often depends on a hardcoded number (e.g. only supports up to COM8), or going to double digits, etc.

Solution1: Some apps may let you enter the COM port number in a special way (UNC path) that lets higher-number COM ports be used, e.g: \\.\COM25
(that is, precede the port name with a double backslash, dot, and then another backslash). If the app uses backslashes as an escape character, try doubling the backslashes, e.g. \\\\.\\COM37

Why this form? Why only some applications? Why does the number where this form becomes necessary differ between applications? (avrdude.exe requires it for COM10 and higher; pyserial will work without it up to at least COM15 or so, but not COM25. Of course, this all may just depend on the phase of the moon and your results may vary.) Beats the hell outta me. If anyone knows what this is all about, please post in the comments!

Solution2: Clean out those rusty, dusty old unused COM port numbers (you know, for that silly dongle you plugged in exactly once years ago and never touched again) so you can recover those “working” low COM port numbers for new devices. Trouble is Windows will not show it in Device Manager unless the device is plugged in, which is a problem if the thing got lost or broke long ago. To see the hidden allocations and remove them:

1. Open a command prompt as Administrator. (Start->Run, type cmd ). Or, right-click Start->Programs->Accessories->Command Prompt and choose “Run as administrator”

2. At the command prompt type set devmgr_show_nonpresent_devices=1

3. At the command prompt type start devmgmt.msc to start Device Manager. For this to work you MUST start it from this command prompt – don’t mouseclick your way into it or try to use an already open copy.

4. When device manager opens, select View -> Show hidden devices

Now when you expand the COM ports section, every COM port ever allocated will be shown (all the ones for nonexistent devices will be grayed out). Now you can right-click all the defunct ones and uninstall them.

NOTE: Without the magic incantations above, you will still have a View -> Show hidden devices option, but it won’t actually show the nonexistent COM port eating devices.

Solved: SL4A force close when calling recognizeSpeech

Problem: SL4A crashes upon the first call to recognizeSpeech() : com.googlecode.android_scripting stopped unexpectedly (Force Close).

The corresponding Android log via adb shell #logcat:

D/AndroidRuntime( 2785): Shutting down VM
W/dalvikvm( 2785): threadid=1: thread exiting with uncaught exception (group=0x4
0018560)
I/ActivityManager( 1429): Starting: Intent { act=android.speech.action.RECOGNIZE
_SPEECH } from pid 2785
E/AndroidRuntime( 2785): FATAL EXCEPTION: main
E/AndroidRuntime( 2785): java.lang.RuntimeException: Unable to start activity Co
mponentInfo{com.googlecode.android_scripting/com.googlecode.android_scripting.ac
tivity.FutureActivity}: android.content.ActivityNotFoundException: No Activity f
ound to handle Intent { act=android.speech.action.RECOGNIZE_SPEECH }
E/AndroidRuntime( 2785): at android.app.ActivityThread.performLaunchActiv
ity(ActivityThread.java:1768)

(etc.)

Solution: Install Google’s free Voice Search app from the app marketplace. This app provides the activity android.speech.action.RECOGNIZE_SPEECH.