Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, Ill explain my problem then hopefully someone will be able to assist (fingers crossed) Basically, i have a linux box (Centos 5) and i am using Perl to make ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2

    Printing with Perl - HELP PLEASSSSSE


    Hi,

    Ill explain my problem then hopefully someone will be able to assist (fingers crossed)

    Basically, i have a linux box (Centos 5) and i am using Perl to make a program and web interface etc. It must use Perl and nothing else, so im only interested in people who can help me with this and perl really thanks.

    I am trying to print to network printers, ive tried Net:LPR and Net:Printer, bot of which send data to the printer, but not the data string, it just sends 'lp', i have configured them correctly from what i can tell but wondered if anyone else could help.

    Im trying to make receipts come out on my Epson Tm-L90 thermal receipt printer and also other documents come out on my HP deskjet printer.

    All i need to be able to do is really just print raw data to the receipt printer as im using escape codes etc to control it, but really struggling.

    I have looked all over the net for a week now and have not got a clue, if anyone has any ideas of how to set it up or provide me with an example based around the below data it would be very much appreciated thanks.

    The ip of the receipt printer is 10.0.2.37 on port 9100 and its called receipt.

    The perl script i have so far is as follows, but it doesnt work, it just prints receipt or lp depending on what you put in the boxes.

    ##########################################
    #!/usr/bin/perl -w

    use Net::Printer;

    # Create new Printer Object
    $lineprinter = new Net::Printer(
    filename => "/home/jdoe/myfile.txt",
    printer => "receipt",
    server => "10.0.2.37",
    port => 9100,
    lineconvert => "YES"
    );
    # Print the file
    $result = $lineprinter->printfile();

    # print a file
    $result = $lineprinter->printfile("/home/jdoe/myfile.txt");

    # Print a string
    $result = $lineprinter->printstring("test line of data");
    ##########################################

    Like i say, if i could just get it to send a simple string of data i should be ok. The above example doesnt print the file or the line of data, just prints "receipt". Both printers are connected via Ethernet also.

    I have tried the cups web interface but it keeps telling me permission denied etc, so i changed the allowed IP and then it wont restart, so maybe if someone could advise on a command line way of doing it.

    Any help very much appreciated

  2. #2
    Just Joined!
    Join Date
    Feb 2011
    Posts
    1
    I have the same issue? did you ever figure this issue out?

  3. #3
    Just Joined!
    Join Date
    Apr 2010
    Posts
    2
    Hi,

    yes I did work it out, blimey it took me ages, but it works a treat.

    Ok in my perl script, i use the open printer then print lines to it method as its a receipt printer, not sure if it will help you, but i think you will be able to bodge it about.


    open RCP, "| cat | lpr -o raw -P receipt>/dev/null"
    or die "can't fork: $!";
    local $SIG{PIPE} = sub { die "DISCONNECTED" };
    print RCP "TEST PRINT";
    close RCP or die "DID NOT PRINT: $! $?";


    Ok, the main bit that got it working, not sure what this does but in the file /etc/printcap i have the line below replacing the hostname bit with the nameserver address or hostname.

    receipt|receipt:rm=ns0.hostname.com:rp=receipt:

    this is the bit that was in /etc/cups/printers.conf

    <DefaultPrinter receipt>
    Info receipt
    DeviceURI socket://123.456.789121:9100
    State Idle
    Accepting Yes
    Filter application/vnd.cups-raw 0 -
    JobSheets none none
    QuotaPeriod 0
    PageLimit 0
    KLimit 0
    </Printer>

    This is the bit that connects to the printer, i put the IP address of the printer in and the port number. Anyway, it seems to work ok and i can send all my control characters to it without and issues, seems to do the job fine.

    If you need any help let me know, you may want to email me direct, email tdun@hotmail.com if you like and ill see if i can help, im a very experienced perl programmer and know quite a lot so will do what I can to help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •