Help with com port

J

Jeremy

This is a program I wrote a long time ago in quick basic that sets up a label
printer and prints the variables of line1 and line2.

line1$ = "Some stuff"
line2$ = "other stuff"
OPEN "COM1:9600,N,8,1,ASC" FOR RANDOM AS #15
PRINT #15, CHR$(2) + "c0000"
PRINT #15, CHR$(2) + "M1000"
PRINT #15, CHR$(2) + "a"
PRINT #15, CHR$(2) + "V0"
PRINT #15, CHR$(2) + "O0500"
PRINT #15, CHR$(2) + "QCCLEAR"
PRINT #15, CHR$(2) + "XCGAAAA"
PRINT #15, CHR$(2) + "L"
PRINT #15, "C0030"
PRINT #15, "R0000"
PRINT #15, "D19"
PRINT #15, "H11"
PRINT #15, "PE"
PRINT #15, "SE"
PRINT #15, "A0"
PRINT #15, "Q0001"
PRINT #15, "322100000000300" + line1$
PRINT #15, "322100000550275" + line2$
PRINT #15, "W"
PRINT #15, "E"
PRINT #15, CHR$(2) + "QCCLEAR"
CLOSE #15



I have re written it in perl and can not get it to work. I have tried to do this:


$line1="some stuff\n";
$line2="other stuff\n";
open (port,"+>COM1") or die "$!\n";
print port chr 2;
print port "c0000\n";
print port chr 2;
print port "M1000\n";
print port chr 2;
print port "a\n";
print port chr 2;
print port "V0\n";
print port chr 2;
print port "o0500\n";
print port chr 2;
print port "QCCLEAR\n";
print port chr 2;
print port "XCGAAAA\n";
print port chr 2;
print port "L\n";
print port "c00030\n";
print port "R0000\n";
print port "D19\n";
print port "H11\n";
print port "PE\n";
print port "SE\n";
print port "A0\n";
print port "Q001\n";
print port "322100000000300";
print port "$line1\n";
print port "322100000550275";
print port "$line2\n";
print port "W\n";
print port "E\n";
print port chr 2;
print port "QCCLEAR\n";
close (port);


Help!!!!!!!!!!!!!!!1
 
B

Ben Morrow

This is a program I wrote a long time ago in quick basic that sets up a label
printer and prints the variables of line1 and line2.

line1$ = "Some stuff"
line2$ = "other stuff"
OPEN "COM1:9600,N,8,1,ASC" FOR RANDOM AS #15
CLOSE #15

I have re written it in perl and can not get it to work. I have
tried to do this:

How does it fail? What does it do or not do that you didn't expect?
$line1="some stuff\n";
$line2="other stuff\n";
open (port,"+>COM1") or die "$!\n";

It is conventional to use UPPERCASE for filehandles; also, it is
usually better to use lexical filehandles.

I believe (but am not sure) that the name for the serial port is
"COM1:"? Also, the "9600,N,8,1,ASC" from the above is not here: I
suspect it is important.

Don't put "\n" on the end of die messages. It suppresses important
information about where the error occurred.

open my $PORT, "+>COM1:9600,N,8,1,ASC" or die "can't open COM1: $!";

or, if this fails because "COM1:..." is incorrect syntax, you'll need
to do

open my $PORT, "+>COM1:" or die "can't open COM1: $!";

and then set 9600 baud, no parity, 8 data bits, 1 stop bit, XON/XOFF
(I presume that's how that decodes?) with POSIX::Termios or some
appropriate ioctls.
print port chr 2;
print port "c0000\n";
print port chr 2;
print port "M1000\n";
print port chr 2;
print port "a\n";
<snip>

I would do this with a here-doc:

print $PORT <<EOF;
\x2c0000
\x2M1000
\x2a
etc...
EOF
close (port);

Particularly with things like terminals, you *must* check the return
of close.

close $PORT or die "close of COM1 failed: $!";

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top