Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Help with com port (http://www.velocityreviews.com/forums/t883880-help-with-com-port.html)

Jeremy 11-26-2003 07:17 PM

Help with com port
 
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

Ben Morrow 11-26-2003 07:47 PM

Re: Help with com port
 

jeremyk@crescentmfg.com (Jeremy) wrote:
> 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

<schtuff>
> 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

--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
ben@morrow.me.uk

Dave Weaver 11-28-2003 09:19 AM

Re: Help with com port
 
On Wed, 26 Nov 2003 19:47:48 +0000 (UTC),
Ben Morrow <usenet@morrow.me.uk> wrote:

> jeremyk@crescentmfg.com (Jeremy) wrote:
>
> > 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

^^^^
\x2c is a comma - probably not what was intended...

\x02c0000

> \x2M1000
> \x2a

^^^^

\x02a

--
Cheers,
Dave.



All times are GMT. The time now is 10:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.