This is pretty hard to do that on USB printer connected to windows. You have to have bidirectional driver for your printer and somehow read it (there is no that option in win32 printing). There is no bidirectional windows drivers for most of printers.

It is much easier to ReadBack from printer connected to network. You can do that with simple app called PCL Paraphernalia
http://www.pclparaphernalia.eu/index.html

ReadBack from USB printer on Linux is possible! Printer is installed as a character device (you can read and write to it).

Some tips:

  • After read printer send to them ESCAPE character. If not, next send and work will not work.
    echo -e "\e" > /dev/usb/lp0
  • My printer does not respond nothing for @PJL INQUIRE *_* – no respond from printer for variables with underscore example: @PJL INQUIRE TOTALPAGE_LMT (probably total page limit) and others:
    ONLYFOR_PANEL
    TOTALPAGE_LMT
    COUNTPAGEPF1_LMT
    COUNTPAGEPFM_LMT
    A4PAGES_LMT
    LEGALPAGES_LMT
    JISB5PAGES_LMT
    A5PAGES_LMT
    A6PAGES_LMT
    MONARCPAGES_LMT
    PLAINPAGES_LMT
    THICKPAGES_LMT
    ENVELOPESPAGES_LMT
    POSTCARDPAGES_LMT
    LABELPAGES_LMT
  • You can try to check device is busy but it not work correctly. You should do the command in loop until you read more than zero length reponse (or set timeout in looop to next try)
    while true
            do
               fuser -s /dev/usb/lp0
               if [ $? -ne 0 ]
               then
                  break
               fi
    done
  • Send PJL:
    echo -e "\e%-12345X@PJL\r\n@PJL INFO ID \r\n\e%-12345X" > /dev/usb/lp0
  • Read PJL – I do not know when you should read and when the response is ready. So i try to read in loop or few cat commands, read or dd.
    #1way
    response=$(dd if=/dev/usb/lp0 of=temp.txt 2>&1)
    echo "$response"
    echo -e "\e" > /dev/usb/lp0
     
    #2way
    while IFS= read -r -n1 char
    do
     printf "$char"
    done < /dev/usb/lp0 echo -e "\e" > /dev/usb/lp0
     
    #3way
    cat /dev/usb/lp0
    echo -e "\e" > /dev/usb/lp0
  • Example script to read the printer ID:
    #!/bin/bash
     
    PRINTER=/dev/usb/lp0
    ESCAPE=$(echo -e "\e")
    FF=$(echo -e "\x0C")
    char=""
    IFS=""
    echo "" > temp.txt
     
    	while true
    	do
    		sleep 0.5
    		#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 INFO ID \r\n\e%-12345X" > "$PRINTER" 
    		#TRY TO READ IMMEDIATELY
    		char=$(dd if="$PRINTER" of=temp.txt 2>&1)
    		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
    				echo "" > temp.txt
    				break
    			else
    				printf "."
    			fi
    		fi
    		char=""
    	done

    the response:
    @PJL INFO ID
    "Brother HL-1110 series:84UE03:Ver1.08"