ultibuzz has asked for the wisdom of the Perl Monks concerning the following question:
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 ;)
|
---|