Monks, your wisdom is required
I am writing to an embedded system over a serial port. The system is extremely limited and writing to it any faster than 50ms per character causes data to be dropped/lost.
My code is as follows
sub configPort($,$){
my $port = ($_[0]);
my $refConfigHash = ($_1);
$$port->baudrate($refConfigHash->{portBaudRate}) || die "Cannot Set Baud Rate \n";
$$port->databits($refConfigHash->{portData}) || die "Cannot Set Data Bits \n";
$$port->stopbits($refConfigHash->{portStopBits}) || die "Cannot Set Stop Bits \n";
$$port->parity($refConfigHash->{portParity}) || die "Cannot Set Parity \n";
$$port->handshake("none");
$$port->read_char_time(0); # don't wait for each character
$$port->read_const_time(1000); # 1 second per unfulfilled "read" call
$$port->get_tick_count;
$$port->write_settings;
}
sub subSerialPortWrite($,$){
my $port = ($_[0]);
my $buffer = $_1;
my $i;
$$port->write("\r");
for($i=0;$i<=length($buffer);$i++){
$$port->write(substr($buffer,$i,1));
Time::HiRes::usleep(50000);
}
}
What I believe is happening is that each character gets buffered and finally the entire string gets spit out to the serialport at once, which of course cannot respond fast enough.
My questions are
1. Am I right?
2. If so, how do I work around it?
3. If not, what is my problem and how do I fix it?
I'm using perl version 5.10.0
Please help
Thanks
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.