Operating System - HP-UX
1753368 Members
4971 Online
108792 Solutions
New Discussion юеВ

Re: PJL script - "binary" out to printer

 
SOLVED
Go to solution
Tim Howell
Frequent Advisor

PJL script - "binary" out to printer

can someone tell me how to send "binary" commands to a printer via a shell script? I remember the old DOS trick:

copy filename /b PRN:

is there something similar I can use? According to the PJL manual I have to send the following to my printer:

%-12345X@PJL

Thanks in advance.
if only we knew...
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor

Re: PJL script - "binary" out to printer

Typically these commands arer put in the interface file in /var/spool/lp/interface/printername but the technique is simple:

echo "\033%-12345X@PJL\r"

The linefeed is emitted be default unless the echo command ends with "\c"

Look in /var/spool/lp/interface (or the model.orig directory below it) and you should find a number of examples.
If it ain't broke, I can fix that.
Tim Howell
Frequent Advisor

Re: PJL script - "binary" out to printer

Actually, I do not see any examples in /var/spool/lp/interface/

And perhaps this a forest/trees episode, but, I don't understand how to send the commands to the printer...

this is now in a script...
----------------------------------------
echo "\033%-12345X@PJL \r"
echo "@PJL ECHO 11:30:00 11-10-04 \r"
echo "@PJL INFO CONFIG \r"
echo "\033%-12345X \r"
----------------------------------------
I should recieve messages back from the printer when it gets these commands.

Thanks again...
if only we knew...
Mark Greene_1
Honored Contributor

Re: PJL script - "binary" out to printer

"And perhaps this a forest/trees episode, but, I don't understand how to send the commands to the printer..."

Once you have the command syntax for the printer squared away, you either need to pipe the commands to the HP-UX print queue, or to a file and then send the file to the print queue:

lp -d[printqueue name] [filename]

mark
the future will be a lot like now, only later
A. Clay Stephenson
Acclaimed Contributor

Re: PJL script - "binary" out to printer

Reading responses back from a printer is a whole different animal. Often ports are configured to be write-only. It's not common on UNIX boxes to write directly to a port but rather the print stream is sent to lp which invokes an interface file for your printer.

I'll give you another source of example files. Look specificall at /usr/lib/model/lp/paintjetXL300. It contains exactly your string.

This is a typical way to send commands to a printer:

F1="myfile"
TDIR=${TMPDIR:-/var/tmp)
T1=${TDIR}/P${$}_1.txt
echo "\033%-12345X@PJL EOJ\r" > ${T1}
echo "\033%-12345X@PJL enter language=pcl" >> ${T1}
cat ${T1} ${F1} | lp -o binary -dmyprinter
rm -f ${T1}

You might also need to send some commands at the end of the job so using the same mechanism, create a T2 file and echo commands to it then cat all 3 files together and send them to lp.
If it ain't broke, I can fix that.
Tim Howell
Frequent Advisor

Re: PJL script - "binary" out to printer

Well, I can't get it to work, but you did answer my overall question with the
-o binary option. I will assign points and revamp my question (in other words, try a different route)
Thanks;
if only we knew...
Steve Post
Trusted Contributor

Re: PJL script - "binary" out to printer

Yes. You can do this.
I made a remote printer using SAM.
Let's call the printer: myprinter.
I edit file /etc/lp/interfaces/myprinter.
I go to the bottom of the file.
And I see this.....

/usr/sbin/rlp -I$requestid $BSDC $BSDJ $BSDT $BSDi $BSD1 $BSD2 $BSD3 $BSD4 $BSDw
$BSDformat $BSDh $1

This line sends out the data.
Where's the filename that goes out?
It's been a while. I don't know.

But I DO know there were a pile of shift commands, and the remainder of $@ holds the names of the files. So each element in $@ is a filename.

Just ABOVE that rlp line I put....

for f in $@
do
echo '^[&l2A^M' > $f.tmp
echo '!R!^M' >> $f.tmp
echo 'MZP0,0;^M' >> $f.tmp
echo 'CALL R010;^M' >> $f.tmp
echo 'EXIT;^M' >> $f.tmp
/usr/bin/cat $f >> $f.tmp
# for very TEMP debugging....
FILE=`basename $f.tmp`
cp $f.tmp /tmp/$FILE
# end of debugging
mv -f $f.tmp $f
done

See it adds binary data to the front of each file just before it goes out.

steve


Steve Post
Trusted Contributor

Re: PJL script - "binary" out to printer

you know how to add binary data to file using vi right?

To add the escape key to a spot in a file.
vi filex
go to the spot you want the escape key.
press i for insert.
press control-v
press the escape key.

That's it. Save your file.

The control-v tells vi to treat the next key pressed literally.

steve
Bill Hassell
Honored Contributor
Solution

Re: PJL script - "binary" out to printer

PJL commands can be sent to the printer, but sending a command that requires a response is not possible using the lp spooler. The reason is that the spooler is an independent subsystem. When you type lp, the command line is processed and converted to 'tokens' that are dropped into a FIFO which lpsched reads and then schedules additional lpsched proceses to actually print the file. The basic lp spooler is a one way process so the printer may try to answer back but there's no on listening. And if you think about it, even if the spooler returned the printer responses (it would have to smart enough to know which commands require a response), where would it display the responses? You may have logged out and gone home when the spooler finally gets a chance to print on a busy printer.

Now virtually all of the PJL codes you need for HP printers are contained in the printer scripts. If this printer is conected to the LAN with an HP JetDirect card, then look at the man page for hpnpadmin to gather a lot of printer information. Then look at the example scripts in /opt/hpnpl/sh, perhaps the highest level script which is net_ljx00. Couple that with the man page for net_ljx00 and you'll see how PJL codes are sent to the printer. But none of the codes that generate responses are sent to the printer.

NOTE: If you have a JetDirect LAN card in your printer but do not have /opt/hpnpl directory, get the latest JetDirect software from:

http://h20180.www2.hp.com/apps/Lookup?h_query=jet+direct+printer+installer&h_tool=software&h_lang=en

You will probably find that everything you need to do with PJL codes is already contained in the model script net_ljx00 option list. Note also that you do NOT have to go through some PC server to print on a JetDirect LAN card--that's what the HPPI software does for you.


Bill Hassell, sysadmin