One pet project of mine is random number generator. It is actually quite simple: PIC generates random number from noise and then uses FT232RL to transfer it. On micro-controller side it is standard USART and to Windows it looks like it is USB-to-serial converter. To get random number, program just needs to read a byte from serial port. How hard can it be?
I tried device under Windows 7 and computer suddenly started shutdown. Not a crash mind you, proper shutdown. I checked event logs and everything pointed just to normal shutdown. I plugged device again and my mouse went wild. It started clicking, moving, re-sizing, cursing (ups, that was me). As soon as I pulled device out everything returned to normal. I plugged device back in and found no issues. For a while. And then mouse started going wild again. My guess is that it was this what did shutdown in first place. Mouse was just at the right place at the right time.
If I would open serial port as soon as device was plugged in, everything was normal. However, if device was left for a while, mouse dance would commence. I did remember that PS/2 could cause some similar issues but it didn’t quite match what I was seeing. What I was seeing seemed a lot like reports of serial GPS devices being treated as mouse. Actually it seemed totally same.
It seems that Windows will sample bytes from any connected serial device to check whether it is mouse on other side. Exact heuristics are not known to me but I bet that it checks whether data is sent all the time (like I do for my device) and whether data changes (like random numbers tend to). If both these requirements are satisfied it will search for some byte sequence to be sure. Since random number generator will (given enough time) create every sequence there is, I was fooling that check also.
Actual fix is rather simple. Under
HKLM\SYSTEM\CurrentControlSet\Services\sermouse we change property
0x04. That causes service start option to be changed from manual to disabled. That also means that there is no support for serial mice on your computer. That is, if you manage to find one anywhere…
As for my device, I have no idea what to do. Forcing everybody to change registry in order for it to work does not seem user friendly. Putting it in readme.txt seems like sure way for nobody to even know about issue. Waiting for command before generating random number kills simplicity. Converting all to hex kills bandwidth, simplicity and I cannot be sure that problem will not resurface later…
There is probably no ideal solution but I will not let small thing like that prevent me from trying to find it.
P.S. Registry file for disabling serial mouse is available for download.