Hi.

Thanks to NERDVANA and soonix and afoken. With respect to access to the RS232 serial, the module I am accessing is an OBD2 automotive module with a USB to serial chip embedded within a plastic sealed module. The handskaking on the serial port is switched off ("none" as indicated with the serial initialisation). Also, the initialisation also seems to suggest a buffering of 256 bytes in both directions.

I have tried changing the size of the write (shorted and longer) but the issue still follows how the data is written to the sub Serial_TrxRcv($parameter). I have a "yucky" work around where I avoid taking the $ccmd (command) directly from the hash, but copy to a $newcmd variable in a very specific way. This is in the following code presentation.

sub ProcessPIDs { # print "Inside ProcessPIDs \n"; # Process the input arguments my ( $nickname, $ref_nicknametocommand ) = @_; my %InSubNickNameToCommand = %{$ref_nicknametocommand}; # De-ref +rence the reference to an hash my $ccmd; $ccmd = $InSubNickNameToCommand{ $nickname }; # need E +RROR checking here !!!!!! my $newcmd ; if ($ccmd eq '0101') { $newcmd = '0101'; } elsif ($ccmd eq '0103') { $newcmd = '0103'; } elsif ($ccmd eq '0104') { $newcmd = '0104'; } elsif ($ccmd eq '0105') { $newcmd = '0105'; } elsif ($ccmd eq '0106') { $newcmd = '0106'; } elsif ($ccmd eq '0107') { $newcmd = '0107'; } elsif ($ccmd eq '010c') { $newcmd = '010c'; } elsif ($ccmd eq '010d') { $newcmd = '010d'; } elsif ($ccmd eq '010e') { $newcmd = '010e'; } elsif ($ccmd eq '010f') { $newcmd = '010f'; } elsif ($ccmd eq '0110') { $newcmd = '0110'; } elsif ($ccmd eq '0111') { $newcmd = '0111'; } elsif ($ccmd eq '0113') { $newcmd = '0113'; } elsif ($ccmd eq '0114') { $newcmd = '0114'; } elsif ($ccmd eq '0115') { $newcmd = '0115'; } elsif ($ccmd eq '011c') { $newcmd = '011c'; } elsif ($ccmd eq '0121') { $newcmd = '0121'; } elsif ($ccmd eq '012e') { $newcmd = '012e'; } elsif ($ccmd eq '012f') { $newcmd = '012f'; } elsif ($ccmd eq '013c') { $newcmd = '013c'; } elsif ($ccmd eq '0142') { $newcmd = '0142'; } elsif ($ccmd eq '0143') { $newcmd = '0143'; } elsif ($ccmd eq '0144') { $newcmd = '0144'; } elsif ($ccmd eq '0145') { $newcmd = '0145'; } elsif ($ccmd eq '0149') { $newcmd = '0149'; } elsif ($ccmd eq '014a') { $newcmd = '014a'; } elsif ($ccmd eq '014c') { $newcmd = '014c'; } else { print "Warning; failed to match $ccmd\n"; die "AMEN !\n"; } # my $newcmd = $ccmd; # this does not work print "\$ccmd; $ccmd ".length($ccmd). " \$newcmd; $newcmd ".length +($newcmd)."\n"; my $response = Serial_TrxRcv($newcmd); my $result; .... etc ...

As indicated in the code above, I could not just copy with "my $newcmd = $ccmd" but had to involve an if statement. In this circumstance the $newcmd can be passed to the sub without the buffer error occurring.

If the $newcmd is copied from a constant in the program then it works.

It's hard to known if the issue is from a very fine timing problem with the serial port treatment or related to how perl reads from a simple scaler embedded with a hash. Please consider issues ?

Regards JC....


In reply to Re^6: Win32::SerialPort, buffer overflow by jmClifford
in thread Win32::SerialPort, buffer overflow by jmClifford

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.