We are in need of a working code example in C# that uses the Zebra.Printing.UsbPrinterConnector to query the printer status f...

J James Sack 3 years 7 months ago
1813 3 0

We use the following to print:
 
             // Zebra KR403 Receipt Printer
            var enumDevices = Zebra.Printing.UsbPrinterConnector.EnumDevices();
            if (enumDevices.Keys.Count > 0)
            {
                string key = enumDevices.Keys[0];
                Zebra.Printing.UsbPrinterConnector connector = new Zebra.Printing.UsbPrinterConnector(key);
 
                string command1 = @"^XA^PW464~SD15" +
                @"^FO05,100^A0N,32,32^FB450,1,0,C^FDTest Line^FS ";
 
                command1 = command1 +
                @"^CN1
                ^PN0        
                ^XZ";
 
                byte[] buffer1 = ASCIIEncoding.ASCII.GetBytes(command1);
                connector.IsConnected = true;
                connector.Send(buffer1);
 
                // Read paper status
                string spaperout = "^XA~HQES^XZ\n";
                byte[] buffer2 = new byte[];
                buffer2 = ASCIIEncoding.ASCII.GetBytes(spaperout);
                connector.Send(buffer2);
                byte[] buffer3 = new byte[];
                int bytesread = connector.Read(buffer3, 0, 512);
        }
 
We encounter errors while trying to read the low paper status.
 
Jim

Please Register or Login to post a reply

3 Replies

J James Sack

Robin,

Have you been able to identify the correct Zebra.Printing.UsbPrinterConnector that has the SendAndWaitFor Response method?

Jim

E Efkan YILMAZ

Hi Jim,
What errors are you getting?
Also not all Zebra printers support a low paper sensor.  Most will only give a paper out error.  Which printer are you using?
Robin

J James Sack

Robin,

The printers we are using in all of our kiosks is the KR403 unit with the paper sensor option.

The errors we are getting occur in the Zebra.Printing.UsbPrinterConnector.Read  function.  It is telling us the buffer is not large enough.  I have tried making buffer size as large as 8192 when I call this function.  Is my approach even correct?  I am really looking for a proper example how to read the status in C# using this.

The code from the UsbPrinterConnector.Read function is below.

        public override int Read(byte[] buffer, int offset, int count)
        {
            // USB 1.1 ReadFile in block chunks of 64 bytes
            // USB 2.0 ReadFile in block chunks of 512 bytes
            uint read;

            if (readBuffer == null)
                readBuffer = new byte[ReadBufferSize];

            AutoResetEvent sg = new AutoResetEvent(false);
            NativeOverlapped ov = new NativeOverlapped();
            ov.OffsetLow = 0;
            ov.OffsetHigh = 0;
            ov.EventHandle = sg.Handle;

            if (!FileIO.ReadFile(usbHandle, readBuffer, ReadBufferSize, out read, ref ov))
            {
                if (Marshal.GetLastWin32Error() == FileIO.ERROR_IO_PENDING)
                    sg.WaitOne(ReadTimeout, false);
                else
                    throw new Win32Exception(Marshal.GetLastWin32Error());
            }
            FileIO.GetOverlappedResult(usbHandle, ref ov, out read, true);

            Array.Copy(readBuffer, 0, buffer, offset, read);
            return (int)read;
        }

CONTACT
Can’t find what you’re looking for?