CuriousMark has asked for the wisdom of the Perl Monks concerning the following question:
Sending a data string from Perl script that requires Start (0x02) and End (0x03) of Text data string layout is
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"#### 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)
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";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help adding STX and ETX to data string in Perl
by jwkrahn (Abbot) on Jul 19, 2022 at 05:19 UTC | |
|
Re: Help adding STX and ETX to data string in Perl
by AnomalousMonk (Archbishop) on Jul 19, 2022 at 04:45 UTC | |
|
Re: Help adding STX and ETX to data string in Perl
by etj (Priest) on Jul 19, 2022 at 14:39 UTC | |
|
Re: Help adding STX and ETX to data string in Perl
by BillKSmith (Monsignor) on Jul 20, 2022 at 22:48 UTC | |
by cavac (Prior) on Jul 21, 2022 at 06:22 UTC | |
by BillKSmith (Monsignor) on Jul 21, 2022 at 13:02 UTC | |
|
Re: Help adding STX and ETX to data string in Perl
by jmlynesjr (Deacon) on Jul 19, 2022 at 22:54 UTC |