Reduce CPU time while polling serial port

Discussion in 'Perl Misc' started by jis, Sep 6, 2007.

  1. jis

    jis Guest

    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
     
    jis, Sep 6, 2007
    #1
    1. Advertising

  2. jis

    Guest

    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
     
    , Sep 7, 2007
    #2
    1. Advertising

  3. jis

    Guest

    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
     
    , Sep 7, 2007
    #3
  4. 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
     
    Ekki Plicht (DF4OR), Sep 7, 2007
    #4
  5. jis

    jis Guest

    On Sep 6, 6:34 pm, 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
     
    jis, Sep 8, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg Pedder
    Replies:
    0
    Views:
    2,033
    Greg Pedder
    Feb 8, 2004
  2. Pom
    Replies:
    2
    Views:
    1,796
    Bas-i
    Jan 31, 2007
  3. pavunkumar

    How , system cpu and user cpu times calculates

    pavunkumar, Feb 27, 2009, in forum: C Programming
    Replies:
    1
    Views:
    377
  4. msalerno
    Replies:
    3
    Views:
    442
    Ilmari Karonen
    Jul 14, 2005
  5. Ajinkya
    Replies:
    3
    Views:
    180
    The Magpie
    Jan 7, 2008
Loading...

Share This Page