Multiple Pens / One PC
Yes, we even used a paperclip...
Motivation
If you're using multiple digital pens to stream coordinate data over Bluetooth, you've probably encountered the limit of one pen per PenServer... The accepted solution thus far has been to use a separate physical computer for each pen, which is quite inconvenient! We would much rather use a single computer to handle as many pens as needed. We happen to know that Anoto has developed some means of accomplishing this result, but the solution is extremely proprietary and they're not sharing it. Therefore, we've had to MacGyver it... and it works exactly like you'd expect!
Overview
In this tutorial, you'll see how we connect multiple digital pens to a single Java application running on a single PC. This is accomplished using multiple Bluetooth adapters and virtual machines. All software used is free, except the copies of Windows. In a nutshell, each individual pen is paired with a separate Bluetooth adapter, which is then associated with an individual virtual machine, which runs a copy of the PenServer and waits for connections. Our sample Java application then connects to each of the "virtual" PenServers and receives coordinate data.
NOTE: The authors' particular needs demanded four pens, so this example uses... four pens! If you need a different number (N) of pens, s/four/N/g.
Physical Setup
Requirements
- Four digital pens (obviously).
- We're using Nokia SU-1Bs.
- Four Bluetooth adapters.
- We're using all Zoom Model 4320A, as described here.
- One beefy PC, running Windows XP Pro.
- Our test machine is a dual-processor Xeon with a few GB of RAM, which seems to do just fine. We would also recommend using multiple monitors, so you can easily keep track of your virtual machines.
NOTE: We've found it very helpful to color code everything and this tutorial reflects that, so here's some photos of our setup.
Virtual Machines
We're using VMWare Player, which is a free download and is therefore not capable of creating images. Fortunately, that's no problem! There are a variety of ways to make your virtual machines... The general idea is to create a .vmx file (machine specs) and .vmdk (disk image). You can even download VMWare Workstation and use it to create these files (don't forget to change virtualHW.version to "3" in the resulting .vmx). Note that Player (which can play but not create) and Workstation (which can create but not play, without a serial number) won't install over each other; a minor inconvenience. But, the process really isn't that hard, and you can easily piece together your .vmx from snippets online and grab an empty .vmdk from one of the many examples online.
We found it easiest to create a single "base" machine, appropriately named Zero. Its .vmx file looks like this:
config.version = "8"
virtualHW.version = "3"
ide0:0.present = "TRUE"
ide0:0.filename = "semlabVirtual0.vmdk"
memsize = "256"
MemAllowAutoScaleDown = "FALSE"
ide1:0.present = "TRUE"
ide1:0.fileName = "auto detect"
ide1:0.deviceType = "cdrom-raw"
ide1:0.autodetect = "TRUE"
floppy0.present = "FALSE"
ethernet0.present = "TRUE"
usb.present = "TRUE"
sound.present = "TRUE"
sound.virtualDev = "es1371"
displayName = "Semlab Virtual 0"
guestOS = "winxppro"
nvram = "semlabVirtual0.nvram"
MemTrimRate = "-1"
ide0:0.redo = ""
tools.syncTime = "TRUE"
ide1:0.startConnected = "TRUE"
tools.remindInstall = "TRUE"
ethernet0.connectionType = "nat"
You can ignore most of these... but pay attention to ide0:0.filename, memsize, displayName, guestOS, and ethernet0.connectionType.
So, starting with a blank .vmdk, we installed Windows and got the Widcomm stack and Tools Of The Trade installed. We then duped the .vmx and .vmdk files to make a total of four virtual machines, numbered (gasp) 1-4. Be sure to change the computer name in each copy of Windows, obviously.
Now, connect one Bluetooth dongle to each VM (preferably by plugging adapters in one at a time and noting their hardware IDs). Your host machine should show no Bluetooth devices, and each VM should show one. At this point, we modified each VM's desktop color and displayName to match the color of its adapter. It really helps!
Networking
You may have noticed that we're using NAT for the VMs. This is not a requirement, and it makes some things harder in favor of making other things easier. Our network is restricted by MAC address, so it's much easier for us to NAT the VMs and let the (already registered) host gateway for them... If you don't have a problem with adding new VMs to your local network, you can skip this section! (But you might want to read it anyway because later sections assume you did.)
VMWare Networking Basics
Since our Java application will be running on the real machine (or otherwise generally outside the virtual machines), we need to be able to see the PenServer from outside NAT. This is easily set up by assigning each VM a static internal IP (192.168.whatever.*, we used .16-.19 for some reason) and port-forwarding from the host machine using VMWare (We forwarded localhost ports 11116-11119 to .16-.19:11025).
The VMWare network config utility doesn't get its own Start Menu shortcut upon installation, but it's in the install directory! Look for vmnetcfg.exe, then choose NAT, then Edit, then Port Forwarding.
Code
For the sake of testing, we'll just be using PenCoordinateDebugger.java, but now we want to connect to multiple pens (note the convenient color coding!):
final Pen greenPen = new Pen("Green", "localhost", 11116);
greenPen.startLiveMode();
greenPen.addLivePenListener(new DebuggingPenListener("Green"));
final Pen bluePen = new Pen("Blue", "localhost", 11117);
bluePen.startLiveMode();
bluePen.addLivePenListener(new DebuggingPenListener("Blue"));
final Pen yellowPen = new Pen("Yellow", "localhost", 11118);
yellowPen.startLiveMode();
yellowPen.addLivePenListener(new DebuggingPenListener("Yellow"));
final Pen redPen = new Pen("Red", "localhost", 11119);
redPen.startLiveMode();
redPen.addLivePenListener(new DebuggingPenListener("Red"));
Putting It All Together
- Get each pen paired with each VM and put into streaming mode, as described here.
- Start a PenServer on each VM using PenServer.bat
- Start your new PenCoordinateDebugger.java on the host machine
- Cross your fingers!
If all goes well, you should see coordinate data from all four pens appear on the console of your host machine!
Our example results in this screenshot. Your mileage may vary...
In case you're wondering, the paper clip is helpful for resetting the pens.
Troubleshooting
We initially encountered problems with the multiple BT adapters and VMs, where it appeared that the USB BT adapters would disconnect and reconnect from their VM every 2-3 seconds. This appears to be somewhat random, but we were able to, through trial and error, come up with a procedure that seems to avoid it. We suspect that the issue is related to USB enumeration ordering, but don't have a definite answer.
- Restart virtual machine's host server. This is just a standard "clean slate" step.
- Start the VMs separately, in a pre-defined order (ours are numbered as well as color coded). Do not start the next machine until the prior has completely booted and acquired its USB BT dongle (BT tray icon is blue/white).
- We strongly recommend doing full boots of the VMs ("Start" -> "Shutdown" instead of suspending the VM).
- Do a sanity check: All BT dongles should have been acquired by virtual machines. Each virtual BT tray icon is blue/white, and the host's BT tray icon is blue/red.
At this point, there should be no disconnecting/reconnecting BT dongles (easy to check by listening for the default XP "insert"/"remove" device sounds).
Other random notes:
- Pens apparently cannot be "powered off" (placing cap over pen tip) while in streaming mode (they do buzz slightly when the cap is removed, but appear to stay in streaming mode even when the cap is on), and will not enter streaming mode if being charged via the cable.
- If a VM "forgets" the Pen's BT passcode, and asks you to re-enter it, the passcode is the last 4 digits of the pen serial number. This appears to happen semi-randomly, but doesn't appear to have any consequences.
- Using the pidgits can be a little tricky; hold the pen at a normal angle and lightly tap the tip at the bottom-right corner of the dark area on the pidgit.
Comments (0)
You don't have permission to comment on this page.