Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Please help on win32::serialport
July 13, 2007, 4:41 pm
rate this thread
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
my $DEVICE = "COM1";
my $serial =openPort($DEVICE);
my ($device) = @_;
my $serial = Win32::SerialPort->new ($device, 1);
die "Can't open serial port $serial: $^E\n" unless
$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";
my ($serial) = @_;
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?
Re: Please help on win32::serialport
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
$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->read_const_time(100); # important for nice behaviour,
$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.