The best my memory can supply this is ALMOST correct.
All that looks wrong to me is the buffer needs to be a null-pointer.
So the port_write_bytes should be port_write_bytes(hPort, &testz, 1, 500);
Otherwise the logic and syntax looks fine to me.
As for it being a windows7 issue, Ive not had access to anything higher than XP-sp3.
I think someone tested it OK in Vista, but I think your the first Win7 person.
But seeing as it works happily bufore the plug-unplug thing, I would say its a
Win7 'quirk', and I cant do anything about it myself till I get around to
building a Win7 test-box.
But I'll keep me eye here in case anyone comes up with anything I can tweak without win7.