Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Help with com port

Reply
Thread Tools

Help with com port

 
 
Jeremy
Guest
Posts: n/a
 
      11-26-2003
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
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      11-26-2003

http://www.velocityreviews.com/forums/(E-Mail Removed) (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.
(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Dave Weaver
Guest
Posts: n/a
 
      11-28-2003
On Wed, 26 Nov 2003 19:47:48 +0000 (UTC),
Ben Morrow <(E-Mail Removed)> wrote:

> (E-Mail Removed) (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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
EMUTEL 15 port BRI / 2 port PRI ISDN simulator help wanted z400d3 Cisco 0 02-07-2005 10:19 AM
Overhead of 4-port over 2-port SRAM John T. Goodman VHDL 0 01-25-2005 04:27 PM
Port-security on 16-port FastEthernet module (NM-ESW-16) Dmitry Cisco 0 04-01-2004 06:38 PM
Port security on a Catalyst 4000 - fails to shut down port Jon Whitear Cisco 2 11-04-2003 11:01 PM
about "match ip rtp starting-port-number port-range" Weiguang Shi Cisco 1 10-25-2003 07:14 AM



Advertisments