Reduce CPU time while polling serial port

Reduce CPU time while polling serial port

am 07.09.2007 00:18:04 von jis

Hi,

I am using Win32::serialport for reading a data through a scanner
which is connected to the serial port.
I use polling as below.But this consumes 99% of my CPU time. and
slows down the system.
while(!($data=~/\r/))
{
$data=$Scanner->input(); #read the scanner port
$labeldata=$labeldata.$data; #append
}


Is there any way I implement interrupts or events using perl. Or is
there any other method to solve this issue.
I use WIndows NT4(its old..but i have to...)


Pls share your ideas.


Cheers,
jis

Re: Reduce CPU time while polling serial port

am 07.09.2007 01:34:19 von xhoster

jis wrote:
> Hi,
>
> I am using Win32::serialport for reading a data through a scanner
> which is connected to the serial port.
> I use polling as below.But this consumes 99% of my CPU time. and
> slows down the system.
> while(!($data=~/\r/))
> {
> $data=$Scanner->input(); #read the scanner port
> $labeldata=$labeldata.$data; #append
> }
>
> Is there any way I implement interrupts or events using perl.

Have you looked into the "lookfor" feature of Win32::SerialPort?
I have used it, but this seems to be what it is there for.

Also, appends should be done like this:

$labeldata .= $data;


Xho

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

Re: Reduce CPU time while polling serial port

am 07.09.2007 06:06:54 von Justin Allegakoen

On Sep 7, 6:18 am, jis wrote:
> Hi,
>
> I am using Win32::serialport for reading a data through a scanner
> which is connected to the serial port.
> I use polling as below.But this consumes 99% of my CPU time. and
> slows down the system.
> while(!($data=~/\r/))
> {
> $data=$Scanner->input(); #read the scanner port
> $labeldata=$labeldata.$data; #append
> }
>
> Is there any way I implement interrupts or events using perl. Or is
> there any other method to solve this issue.
> I use WIndows NT4(its old..but i have to...)
>
> Pls share your ideas.
>
> Cheers,
> jis

You could also stick a sleep statement into your while loop.

use Win32;

Win32::Sleep(300);

HTH,
Just in

Re: Reduce CPU time while polling serial port

am 07.09.2007 06:09:44 von Petr Vileta

jis wrote:
> Hi,
>
> I am using Win32::serialport for reading a data through a scanner
> which is connected to the serial port.
> I use polling as below.But this consumes 99% of my CPU time. and
> slows down the system.
> while(!($data=~/\r/))
> {
> $data=$Scanner->input(); #read the scanner port
> $labeldata=$labeldata.$data; #append
> }
>
>
> Is there any way I implement interrupts or events using perl. Or is
> there any other method to solve this issue.
> I use WIndows NT4(its old..but i have to...)
>
>
You can use Perl/Tk or Win32::GUI, create "timer" and look for
$Scanner->status periodically, say evey 50 miliseconds.
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)

Re: Reduce CPU time while polling serial port

am 07.09.2007 13:50:16 von df4or

jis wrote:

> Hi,
>
> I am using Win32::serialport for reading a data through a scanner
> which is connected to the serial port.
> I use polling as below.But this consumes 99% of my CPU time. and
> slows down the system.
> while(!($data=~/\r/))
> {
> $data=$Scanner->input(); #read the scanner port
> $labeldata=$labeldata.$data; #append
> }
>
>
> Is there any way I implement interrupts or events using perl. Or is
> there any other method to solve this issue.
> I use WIndows NT4(its old..but i have to...)

Set the avaiblabe parameters of [Device|Win32]::SerialPort correctly:

my $ser = Device::SerialPort->new ($conf{dev}, 0, '') || die "Can open
$conf{dev}: $!";
[...]
$ser->read_const_time(2000); # important for nice behaviour, otherwise
hogs cpu
$ser->read_char_time(2000); # dto.

Rgds,
Ekki

Re: Reduce CPU time while polling serial port

am 08.09.2007 02:37:29 von jis

On Sep 6, 6:34 pm, xhos...@gmail.com wrote:
> jis wrote:
> > Hi,
>
> > I am using Win32::serialport for reading a data through a scanner
> > which is connected to the serial port.
> > I use polling as below.But this consumes 99% of my CPU time. and
> > slows down the system.
> > while(!($data=~/\r/))
> > {
> > $data=$Scanner->input(); #read the scanner port
> > $labeldata=$labeldata.$data; #append
> > }
>
> > Is there any way I implement interrupts or events using perl.
>
> Have you looked into the "lookfor" feature of Win32::SerialPort?
> I have used it, but this seems to be what it is there for.
>
> Also, appends should be done like this:
>
> $labeldata .= $data;
>
> Xho
>
> --
> --------------------http://NewsReader.Com/------------------ --
> Usenet Newsgroup Service $9.95/Month 30GB

Thanks for that information.
Does lookfor read the data till postamble character. They say polling
until data ready. I am not sure what data ready means.
I tried . It reads the data till postamble character.
am i ok?
my $gotit = "";
until ("" ne $gotit) {
$labeldata = $Scanner->lookfor; # poll until data ready
die "Aborted without match\n" unless (defined $gotit);
last if ($labeldata);

sleep 1; # polling sample time

}
chop($labeldata);
Looking forward to your reply.

Cheers,
Jis