Win32 SerialPort


J

jabidof

Hi All!

I'm reverse engineering some serial port protocol for a measurement
instrument. I was quiet successful by using a port sniffer and by
mirroring the found requests using perl on win32. I've used the Win32
SerialPort module.
I've got two questions:

1. How do I unset the RTS & DTS flags for serial communication (this
has more to do with the serial port i guess but i didn't find a way to
do it using the SerialPort module. It is also maybe related to next
question...

2. Compared to the software delivered with the instrument, my routine
is quiet slow. I get the correct list of points but with an average
time factor increase of 20! What can I set in the serial port comm to
speed this up?

If you think I should post my [very probably not optimized] code, just
let me know...

Thanks in advance,

jpc
 
Ad

Advertisements

B

Bob Walton

jabidof wrote:

....
I've got two questions:

1. How do I unset the RTS & DTS flags for serial communication (this
has more to do with the serial port i guess but i didn't find a way to
do it using the SerialPort module. It is also maybe related to next
question...

Hmmmm...looking at the docs, maybe the pulse_rts_on,
pulse_rts_off, pulse_dtr_on and pulse_dtr_off methods the module
inherits from the Win32API::CommPort module would help?

....
 
J

jabidof

Thanks for your input,

Still didn't solve this RTS/DTR issue.
I use a simple serial sniffer that output the serial line attributes
(RTS, etc.) and when using the software delivered with the instrument,
I clearly see that RTS & DTR turn red (off i guess).
When trying to implement this in perl using the pulse_dtr_off, etc.
methods, RTS just sticks to its state (no change) and DTR turns green
(should be red) :-( Am I doing something wrong? I post the code snippet
related to the port below.

#**************************************************************************
#* Serial functions
#**************************************************************************
sub openPort($)
{
my ($device) = @_;

my $serial = Win32::SerialPort->new ($device, 1); # on Windows
die "Can't open serial port $serial: $^E\n" unless ($serial);
$serial->pulse_rts_on;
$serial->pulse_dtr_on;
$serial->user_msg(1);
$serial->databits(8);
$serial->baudrate(9600);
$serial->parity("none");
$serial->stopbits(1);
$serial->handshake("rts");
$serial->read_interval(10); # max time between read char
(milliseconds)
$serial->read_char_time(5); # avg time between read char
$serial->read_const_time(10); # total = (avg * bytes) + const
$serial->write_char_time(5);
$serial->write_const_time(10);

# after new, must check for failure
$serial->write_settings || undef $serial;
print "Can't change Device_Control_Block: $^E\n" unless ($serial);
return $serial;
}
 
B

Bob Walton

jabidof said:
Thanks for your input,

Still didn't solve this RTS/DTR issue.
I use a simple serial sniffer that output the serial line attributes
(RTS, etc.) and when using the software delivered with the instrument,
I clearly see that RTS & DTR turn red (off i guess).
When trying to implement this in perl using the pulse_dtr_off, etc.
methods, RTS just sticks to its state (no change) and DTR turns green
(should be red) :-( Am I doing something wrong? I post the code snippet
related to the port below.

#**************************************************************************
#* Serial functions
#**************************************************************************
sub openPort($)
{
my ($device) = @_;

my $serial = Win32::SerialPort->new ($device, 1); # on Windows
die "Can't open serial port $serial: $^E\n" unless ($serial);
$serial->pulse_rts_on;
$serial->pulse_dtr_on;
$serial->user_msg(1);
$serial->databits(8);
$serial->baudrate(9600);
$serial->parity("none");
$serial->stopbits(1);
$serial->handshake("rts");
$serial->read_interval(10); # max time between read char
(milliseconds)
$serial->read_char_time(5); # avg time between read char
$serial->read_const_time(10); # total = (avg * bytes) + const
$serial->write_char_time(5);
$serial->write_const_time(10);

# after new, must check for failure
$serial->write_settings || undef $serial;
print "Can't change Device_Control_Block: $^E\n" unless ($serial);
return $serial;
}

Um, according to the docs, pulse_rts_on etc have an argument.
Maybe if you supplied the argument? Also, check out dtr_active
and rts_active in Win32API::CommPort (they take an argument also).
 
Ad

Advertisements

J

jabidof

Thanks Bob!

Got it! I was only looking at the Win32::SerialPort module :-(
Everything's clear now.
 

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

Top