Fix invalid writes

Adapter index from OSCam is zero-based numbered.
The commit fixes this and also adds a sanity check.