The Update 2 is closer to the actual issue. There is a purge_all when the port is closed (close is also called from DESTROY). When I look at the TK example I put into the CPAN distribution (eg/demo7.plx), I see a blocking write near the beginning with the comment:
# "write" first to init "write_done"
and explicit checks of write_done(0) around the Tk callbacks to prevent beginning new writes while an old one is in progress. That demo also ran with no handshaking.
In the code given, it is not clear which internal operations are blocking/non-blocking. But he does comment on handshaking and buffer management (and uses the is_xx_limit parameters).
I have to speculate a bit about the state information. It is not stored explicitly, although when he closes the app with characters remaining in the write buffer - but blocked by the handshaking - they are actually in the serial driver's buffer (during an "overlapped", i.e. non-blocking TO PERL background write). It is not clear if both Perl and Tk are closed before restarting. He may be holding an OS handle open. But I don't know for sure.
I do think flushing the buffer on close (e.g. by setting handshake to 'none' or doing a blocking write) will fix the problem.
-bill
Edit by tye: Preserve formatting |