Sending a data string from Perl script that requires Start (0x02) and End (0x03) of Text data string layout is

#### STX 1 byte (0x02) #### byte count 8 bytes, leading zeros, inclusive + of wrapper (payload length + 18) #### reserved 8 bytes, all zeros (required and +reserved for future use) #### payload (Data record to send) #### ETX 1 byte (0x03)
Results of code below are not STX = 0x02 and ETX = 0x03 but $hex02_ascii = E2 98 BB $hex02_ascii = E2 99 A5 example: ☻0000052500000000<payload>♥ Note "byte count" is correct as is the "reserved"

my $hex02 = 0x2; my $hex03 = 0x3; my $hex02_ascii = sprintf "%c", $hex02; my $hex03_ascii = sprintf "%c", $hex03; my $MsgLgth = 0; my $Message = " "; chomp $Message; $Message = $_; # Calculate Length of Message $MsgLgth = length($_)+18; if ( $MsgLgth < 100 ) { $Message = $hex02_ascii . '000000' . $MsgLgth . '00000000' . $Message +. $hex03_ascii; }elsif ( $MsgLgth < 1000 ) { $Message = $hex02_ascii . '00000' . $MsgLgth . '00000000' . $Message +. $hex03_ascii; }elsif ( $MsgLgth < 10000 ) { $Message = $hex02_ascii . '0000' . $MsgLgth . '00000000' . $Message +. $hex03_ascii; }elsif ( $MsgLgth < 100000 ) { $Message = $hex02_ascii . '000' . $MsgLgth . '00000000' . $Message +. $hex03_ascii; }elsif ( $MsgLgth < 1000000 ) { $Message = $hex02_ascii . '00' . $MsgLgth . '00000000' . $Message +. $hex03_ascii; }else{ # Max length is 300000 # If hit here, too long ... by a LOT print "Formated Message exceeds MaxMessageLength\n\n";

In reply to Help adding STX and ETX to data string in Perl by CuriousMark

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.