Help with com port

Discussion in 'Perl Misc' started by Jeremy, Nov 26, 2003.

  1. Jeremy

    Jeremy Guest

    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
     
    Jeremy, Nov 26, 2003
    #1
    1. Advertising

  2. Jeremy

    Ben Morrow Guest

    (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, Nov 26, 2003
    #2
    1. Advertising

  3. Jeremy

    Dave Weaver Guest

    On Wed, 26 Nov 2003 19:47:48 +0000 (UTC),
    Ben Morrow <> wrote:

    > (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.
     
    Dave Weaver, Nov 28, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John T. Goodman

    Overhead of 4-port over 2-port SRAM

    John T. Goodman, Jan 25, 2005, in forum: VHDL
    Replies:
    0
    Views:
    638
    John T. Goodman
    Jan 25, 2005
  2. Sean Wolfe
    Replies:
    1
    Views:
    2,296
    Joerg Jooss
    Apr 28, 2005
  3. b3ny
    Replies:
    11
    Views:
    946
    Babu Kalakrishnan
    Nov 20, 2004
  4. Gerald Klix
    Replies:
    0
    Views:
    1,311
    Gerald Klix
    Oct 26, 2005
  5. Pom
    Replies:
    2
    Views:
    1,766
    Bas-i
    Jan 31, 2007
Loading...

Share This Page