Win32 SerialPort

Discussion in 'Perl Misc' started by jabidof, May 8, 2006.

  1. jabidof

    jabidof Guest

    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
     
    jabidof, May 8, 2006
    #1
    1. Advertising

  2. jabidof

    Bob Walton Guest

    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?

    ....

    > jpc
    >



    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, May 13, 2006
    #2
    1. Advertising

  3. jabidof

    jabidof Guest

    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;
    }
     
    jabidof, May 13, 2006
    #3
  4. jabidof

    Bob Walton Guest

    jabidof wrote:

    > 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).

    --
    Bob Walton
    Email: http://bwalton.com/cgi-bin/emailbob.pl
     
    Bob Walton, May 13, 2006
    #4
  5. jabidof

    jabidof Guest

    Thanks Bob!

    Got it! I was only looking at the Win32::SerialPort module :-(
    Everything's clear now.
     
    jabidof, May 14, 2006
    #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. Stephan Kämper

    ruby-serialport on Win32

    Stephan Kämper, Feb 3, 2004, in forum: Ruby
    Replies:
    9
    Views:
    198
    Stephan Kämper
    Feb 6, 2004
  2. Stephan Kämper

    Usability of Ruby/SerialPort on Win32

    Stephan Kämper, Feb 10, 2004, in forum: Ruby
    Replies:
    0
    Views:
    122
    Stephan Kämper
    Feb 10, 2004
  3. Richard S Beckett

    Problem installing Win32::SerialPort

    Richard S Beckett, Jul 7, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    402
    Richard S Beckett
    Jul 7, 2003
  4. Schmigz

    win32::SerialPort; Sending Raw Data

    Schmigz, Jan 26, 2004, in forum: Perl Misc
    Replies:
    2
    Views:
    303
    Schmigz
    Jan 26, 2004
  5. Klaus Kleiner

    Setting RTS with Win32::SerialPort

    Klaus Kleiner, Feb 14, 2005, in forum: Perl Misc
    Replies:
    1
    Views:
    240
    Ron Savage
    Feb 16, 2005
Loading...

Share This Page