Reduce CPU time while polling serial port

J

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
 
X

xhoster

jis said:
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
 
J

justin.allegakoen

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
 
E

Ekki Plicht (DF4OR)

jis said:
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
 
J

jis

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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top