Click here to get back home

Please help on win32::serialport

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Please help on win32::serialport jis 07-13-2007
Posted by jis on July 13, 2007, 12:41 pm
Please log in for more thread options


I have got a very strange looking issue. I have a perl code which
reads the serial port.
I have the following configuration for the port

#!/usr/bin/perl

use strict;
use warnings;
use Win32::SerialPort;

sub openPort($);
sub closePort($);

my $DEVICE = "COM1";
my $data;
my $labeldata;
my $myfile="C:\perl123\scan.txt";

my $serial =openPort($DEVICE);

while(1)
{
$data="";
$labeldata="";
while(!($data=~/\r/))
{
$data=$serial->input();
$labeldata=$labeldata.$data ;

}
}

closePort($DEVICE);

sub openPort($)
{
my ($device) = @_;
my $serial = Win32::SerialPort->new ($device, 1);
die "Can't open serial port $serial: $^E\n" unless
($serial);

$serial->databits(7) || die" could not set databits";
$serial->baudrate(9600) || die" could not set baud rate";
$serial->parity("even")|| die" even parity";
$serial->stopbits(1) || die" stop bits";

$serial->handshake("none")|| die" could nt set handshake";

return $serial;
}

sub closePort($)
{
my ($serial) = @_;
$serial->close();
}


Now the code was not reading serial port . So I open a VB window and
wrote a code using commport and my serial port works fine.

Now I tried my perl code again. The perl code could read the serial
port now and it works fine after that!!!!

I compared the difference. I couldnt find a significant difference.

Anybody has any clue why this is so?

regards,
jis


Posted by Ekki Plicht (DF4OR) on July 13, 2007, 1:21 pm
Please log in for more thread options


jis wrote:

> I have got a very strange looking issue. I have a perl code which
> reads the serial port.
> I have the following configuration for the port

[...code...]

> Now the code was not reading serial port . So I open a VB window and
> wrote a code using commport and my serial port works fine.
>
> Now I tried my perl code again. The perl code could read the serial
> port now and it works fine after that!!!!

Sounds to me like some initialization issue.

When I use Device::SerialPort (same as Win32:SerialPort, but for Linux) I
use the following statements for complete init of the serial device:

$ser->baudrate($baud) || die 'fail setting baudrate, try -b
option';

$ser->parity("none") || die 'fail setting parity to none';
$ser->databits(8) || die 'fail setting databits to 8';
$ser->stopbits(1) || die 'fail setting stopbits to 1';
$ser->handshake("none") || die 'fail setting handshake to none';
$ser->datatype('raw') || die 'fail setting datatype raw';
$ser->write_settings || die 'could not write settings';
$ser->error_msg(1); # use built-in error messages
$ser->user_msg(1); #
$ser->read_const_time(100); # important for nice behaviour,
otherwise hogs

cpu
$ser->read_char_time(100); # dto.

Especially the write_settings seems to be missign in your code. AFAIUI this
routine actually sets the previously selected values.

Cheers,
Ekki







Posted by jis on July 13, 2007, 1:48 pm
Please log in for more thread options


> jis wrote:
> > I have got a very strange looking issue. I have a perl code which
> > reads the serial port.
> > I have the following configuration for the port
>
> [...code...]
>
> > Now the code was not reading serial port . So I open a VB window and
> > wrote a code using commport and my serial port works fine.
>
> > Now I tried my perl code again. The perl code could read the serial
> > port now and it works fine after that!!!!
>
> Sounds to me like some initialization issue.
>
> When I use Device::SerialPort (same as Win32:SerialPort, but for Linux) I
> use the following statements for complete init of the serial device:
>
> $ser->baudrate($baud) || die 'fail setting baudrate, try -b
option';
> $ser->parity("none") || die 'fail setting parity to none';
> $ser->databits(8) || die 'fail setting databits to 8';
> $ser->stopbits(1) || die 'fail setting stopbits to 1';
> $ser->handshake("none") || die 'fail setting handshake to
none';
> $ser->datatype('raw') || die 'fail setting datatype raw';
> $ser->write_settings || die 'could not write settings';
> $ser->error_msg(1); # use built-in error messages
> $ser->user_msg(1); #
> $ser->read_const_time(100); # important for nice behaviour,
otherwise hogs
> cpu
> $ser->read_char_time(100); # dto.
>
> Especially the write_settings seems to be missign in your code. AFAIUI this
> routine actually sets the previously selected values.
>
> Cheers,
> Ekki

Ekki,

You are absaolutely correct. write_settings solved my problem. Thanks
a lot. It did save a lot of time.
regards,
Jis


Similar ThreadsPosted
Need help with Win32::SerialPort August 13, 2004, 5:43 am
help on win32::serialport June 4, 2007, 5:12 pm
problem in using win32::SerialPort September 7, 2007, 2:27 am
Win32::serialport and Windows NT 4 July 31, 2007, 6:08 pm
win32::SerialPort are_match just won't work February 15, 2006, 8:05 pm
No response from printer using Win32::SerialPort October 11, 2006, 11:36 am
hiding Win32::SerialPort->start( ... ) error messages April 19, 2005, 2:27 am
need help with "SerialPort" module April 25, 2006, 11:34 pm
SerialPort error July 7, 2007, 10:58 pm
SerialPort write question October 28, 2004, 11:52 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap