There are a number of things that could be causing disconnection issues:
- Power issues (common if sharing an unpowered USB hub with other devices)
- Electrical interference (likely if you have nearby electrically noisy devices like mechanical relays- try testing the same program in an isolated environment)
- Bad USB connection
If you enable logging
and send us the log file, we may be able to narrow things down.
In the meantime, you can change your program to be able to recover from these kinds of events. In the position change handler, save the current position in a global variable. In the attach handler for the encoder object, you can use setPosition to set it back to that value.