http://qs1969.pair.com?node_id=11140605


in reply to RS232, parity, program flow

From the docs "The write_settings method writes a new Device Control Block to the driver. The write_settings method will return true if the port is ready for access or undef on failure. Ports are opened for binary transfers. A separate binmode is not needed. The USER must release the object if write_settings does not succeed.

I doubt that you need to save the configuration to the $CONF file. But this: write_settings() or die "port fail! $!"; looks important. That would be a normal paradigm, (1)change a bunch of stuff then (2)say, I'm done, make all of those changes effective. I would imagine that you have to make sure that the serial port is in an "idle state" no characters pending to be send when you fiddle with it's configuration settings. How to do that I don't know, but look carefully at docs. Basically don't screw with the serial port's brain while it is busy.

I would suppose that $obj->write("\xa1\xa2"); would work? Port is already open for binmode.

Your code appears to be deviating from my previous advice about async I/O and "not freezing the GUI". Not sure what is going on there. Remember that in the computer's time frame, it will be a very long time before a buffer of chars are actually sent by the port.