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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.