Hello,
I'm working with a Serial device which has some built in special funktions.
Those functions are initiated via special characters like "ESC J".

Some of those functions take options with them which can be HEX or DEC characters,
some must be dec characters,bitmask sums for example.

Below are some examples,in BASIC and perl.
Beware that the CHR function does not work as defined with LPRINT and serial connection.
It DOES NOT convert the DEC to ASCII table character, CHR(120) is submitted as DEC 120.
99 percent work just fine just 2 things give me a headache.

use warnings; use strict; use Fcntl; use IO::Handle; my $PORT = 'COM8'; sysopen(USB, $PORT, O_WRONLY | O_APPEND) or die "ERROR: $!\n"; USB->autoflush(1); print USB "hello world\n"; print USB "\x1BJ"; print USB "\x96"; print USB "\x1Bi\n"; close(USB);
LPRINT "hello world"; CHR$(&HA); LPRINT CHR$(&H1B);"J"; LPRINT CHR$(150); LPRINT CHR$(&H1B);"i";

Both program run fine,
the problem happens if i would do
print USB "150";
the device only takes the 1 and would put 50 in the buffer for printing.
Is there a way to encapsulate DEC values in perl like i can do with HEX values ?.

\x1B is treated as 1 character 150 is treated as 3 DEC characters BASIC CHR$(150) is treated as 1 DEC character

In the above example i can counter the problem via submitting 150 as HEX, the real problem lies in functions where they demand DEC or STRING as options, like "L1".
Is there a way to encapsulate 150 DEC or L1 string,as it works with BASIC ?

kind regards
alex

ps: i need this raw low level access,and the device is troubled by more complex communications ;)
psps the device tells me exactly what it received, and how it treated it ;)


In reply to serial raw write problem with multidigit decimal and strings by ultibuzz

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.