Hello,

I'm receiving a date (mm dd yy yy) via RS232 port sent by another device which looks like this:

02 22 20 22

I'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 33

Which 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 17

It's the hexadecimal interpretation of the sent code. At this point I'm out of ideas.

I'll appreciate your help.


In reply to Code conversion by Anonymous Monk

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.