woodycm has asked for the wisdom of the Perl Monks concerning the following question:

Hello all,

First question asked, so please bear with me...

I am using Win32::SerialPort to communicate (ie print) with a PAXAR 9855 printer. I can poll the printer status using Windows Terminal and PAXAR's own gui tool, but cannot get a response from my perl program (attached below). The print part works fine, it's the read that doesn't work. Actually when SerialPort.pm runs, the got_p scalar, which is where I believe the response from the device is populated, is blank (as in null/nothing).

Any help in pointing me to where I have gone wrong, would be greatly appreciated.
Thanks
#!c:\perl\bin\perl require 5.002; use Win32; use Win32::SerialPort; use Win32::API; $SerialPort = "COM1"; $ENQ = "^E"; $Port = Win32::SerialPort->new($SerialPort); $Port->baudrate(9600) || die "failed setting baudrate"; $Port->parity("none") || die "failed setting parity"; $Port->databits(8) || die "failed setting databits"; $Port->stopbits(1) || die "failed setting databits"; $Port->handshake("xoff") || die "failed setting handshake"; $flowcontrol = $Port->handshake || die "failed setting flowcontrol"; $Port->user_msg(1); $Port->error_msg(1); $Port->debug(1); $Port->write_settings || die "no settings"; #Write Immediate command to allow for Polling. print "Send Immediate Command\n"; $Port->write('{I,E,"~123~044~034~124~125~126~094"|}'); #Print Label $record_to_print = ''; $record_to_print = $record_to_print.'{F,26,A,R,E,600,400,"FMT26"|'; $record_to_print = $record_to_print.'C,400,50,0,50,16,16,O,L,0,0,"CART +ON",0|}'; $record_to_print = $record_to_print.'{B,26,N,1|}'; $Port->write($record_to_print); sleep 2; #Read from Printer undef $msg; ($count, $msg) = $Port->read(4); # Read string 1 $code1 = substr($msg,1,1); $code2 = substr($msg,2,1); print "DATA = $msg | COUNT = $count\n"; print "CODE1 = $code1\n"; print "CODE2 = $code2\n"; sleep 2; #Print ENQ to poll printer $Port->write("^E"); #Read from Printer undef $msg; $msg = $Port->read(3); # Read string 1 $code1 = substr($msg,1,1); $code2 = substr($msg,2,1); print "DATA = $msg\n"; print "CODE1 = $code1\n"; print "CODE2 = $code2\n"; exit;

Replies are listed 'Best First'.
Re: No response from printer using Win32::SerialPort
by grep (Monsignor) on Oct 10, 2006 at 17:43 UTC
    I don't understand Win32::SerialPort but I know serial printers.

    What languages does the printer use (I'm guessing Barcode printer)? (proprietary, ESC/P2, ...) - If it's proprietary can you post what the stings are and what they're supposed to do?

    Are you supposed to sending '~' as part of the printer language? Most languages use ESC (\e or \x1B) to begin a command string.

    Sorry if I am missing something Win32::SerialPort does with ~ in the background.



    grep
    One dead unjugged rabbit fish later
      I'm using PAXAR's proprietary language, I think they call it PCL or NCL.

      The string that includes the ~ character
      $Port->write('{I,E,"~123~044~034~124~125~126~094"|}');
      is exactly what the PAXAR printer is expecting (copied directly from their user manual)to turn on what they call "Immediate Commands". The Immediate Commands allow for the "^E" (this is the polling character) to post an empty "write" to the port, which then puts the printer status on the port to be read.

      I don't think Win32::SerialPort does anything with the ~. As far as I can tell it just treats the entire string (including the ~) as a string.

      The following lines of code are more examples of the PCL and are to just simply print the word CARTON on a label.
      $record_to_print = $record_to_print.'{F,26,A,R,E,600,400,"FMT26"|'; $record_to_print = $record_to_print.'C,400,50,0,50,16,16,O,L,0,0,"CART +ON",0|}'; $record_to_print = $record_to_print.'{B,26,N,1|}';
      Thanks for your reply and your time...
        One thing - I'm pretty sure '^E' shouldn't be the literal string 'caret' and 'cap E'. The caret is usally used in printer code to denote a control code. In this case \x05 or ENQ.

        From the manual it's actually not PCL - it's MPCL. It also does explain that '~' is used by the printer for decimal ascii codes - so that seems ok. I'm guessing the big problem is the Ctrl Codes. You can get more info here.



        grep
        One dead unjugged rabbit fish later