Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm receiving a date (mm dd yy yy) via RS232 port sent by another device which looks like this:
02 22 20 22I'd like to increment the year from 2022 to 2023 and send it back to the device.
The code in funny squares within Komodo should look like this:
+-----++-----++-----++-----+ | 0 0 || 0 0 || 0 0 || 0 0 | | 0 2 || 2 2 || 2 0 || 2 3 | +-----++-----++-----++-----+
The device accepts manually created (incremented) expiration data:
my $send="\x02\x22\x20\x23"; my $ob->($send);
These are the lines in my script:
my $received="02 22 20 22"; my($month,$day,$year1,$year2)=unpack("A2xA2xA2xA4",$received); $year2++; my $send=$month.$day.$year1.$year2; $ob->write($send);
The received code on the other side is:
30 32 32 32 32 30 32 33Which are the ASCII codes of the sent code.
I've tried to convert the code with pack and the closest I get is this:
$month=pack("c",$month); $day=pack("c",$day); $year1=pack("c",$year1); $year2=pack("c",$year2);
The other side receives the hex intrepretation of the sent codes:
02 16 14 17It's the hexadecimal interpretation of the sent code. At this point I'm out of ideas.
I'll appreciate your help.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Code conversion
by Corion (Patriarch) on Feb 22, 2022 at 08:41 UTC | |
|
Re: Code conversion
by Anonymous Monk on Feb 22, 2022 at 08:39 UTC | |
|
Re: Code conversion
by davido (Cardinal) on Feb 22, 2022 at 17:43 UTC |