PJL status readback commands

1.8k Views Asked by At

How to receive respond on Windows from printer after send PJL command?

I tried to spy network printer with WireShark and read printer socket directly but nothing work.

2

There are 2 best solutions below

1
On

On windows is only possible with network printers with Paraphernalia. There is no bidirectional printer drivers for common models. So i have installed linux on virtualmachine.

I used the bidirectional USB driver on linux (the same drivers is on mint, *buntu distro) and execeute a pjl command from cmd.txt with this bash script below.

But i still cannot recognize when to read PJL Respond. Using fuser command to recognize /dev/usb/lp0 busy state does not work so i try to read in a loop with dd and check size of readback. It works but sometimes has to send PJL few times before got response.

#!/bin/bash

PRINTER=/dev/usb/lp0
ESCAPE=$(echo -e "\e")
FF=$(echo -e "\x0C")
char=
IFS=""
SSKIP=0

echo "" > a.txt
echo "" > b.txt
echo "" > temp.txt

while read p; do
    echo -e "#######BEGIN$p-\r\n" >> a.txt
    echo $p

    while true
    do
        #WAIT FOR NOT BUSY
        while true
        do
            fuser -s $PRINTER
            if [ $? -ne 0 ]
            then
                break
            fi
        done
        #send PJL to printer
        echo -e "\e%-12345X@PJL\r\n@PJL INQUIRE $p \r\n\e%-12345X" > $PRINTER 
        #TRY TO READ IMMEDIATELY
        char=$(dd if=$PRINTER of=temp.txt 2>&1)
        #send escape after read
        echo -e "\e" > "$PRINTER"
        #CHECK THAT dd READ ANY BYTES
        echo "$char" | grep "bytes copied" > /dev/null
        if [ $? -ne 0 ]
        then
            printf "."
        else
            echo "$char" | grep "^0 bytes copied" > /dev/null
            if [ $? -ne 0 ]
            then
                cat temp.txt >> b.txt
                echo "" > temp.txt
                break
            else
                printf "."
            fi
        fi
        char=""
    done
    echo 
    echo -e "#######END$p-\r\n" >> a.txt
done <cmd.txt
0
On

I personally use WSL and the "nc" command:

nc <printer's IP> 9100

You get redirect your input and output using the usual "<" and ">" characters:

nc <printer's IP> 9100 <pjl_script.pjl

nc <printer's IP> 9100 <pjl_script.pjl >answer_from_printer.txt