Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

How to use the WritePrinter / ReadPrinter method to read/write data from zebra printer GX420t using C#

$
0
0

i am trying to send a ZPL (Zebra Programming Language) command to my Zebra GX420t printer to check its status if it available, offline, ready or pause etc. i can send a command to write to printer but please tell me how i can read response from the printer ?

is there any way to send zpl through c# and then read the resposne.

i have alreay tried the link below but my ReadPrinter function is not returning any data in the "out" parameter and the method always return false:

https://msdn.microsoft.com/en-us/library/windows/desktop/dd162895(v=vs.85).aspx

http://stackoverflow.com/questions/25669403/how-to-send-a-raw-zpl-to-zebra-printer-using-c-sharp-via-usb?rq=1

http://stackoverflow.com/questions/2044676/net-code-to-send-zpl-to-zebra-printers

my code is as follows:

/////////To send data to printer i have used 

             string s = "^XA~HQES^XZ\n";
            var bytes = Encoding.ASCII.GetBytes(s);
            RawPrinterHelper.SendStringToPrinter("ZDesigner GX420t (Copy 1)", s);

////////////////////////////////////////////////////////////////////////////////////

//////This is my method to send request and then get response 

public static bool SendBytesToPrinter(string szPrinterName, IntPtr pBytes, Int32 dwCount)
        {
            Int32 dwError = 0, dwWritten = 0;
            IntPtr hPrinter = new IntPtr(0);
            DOCINFOA di = new DOCINFOA();
            bool bSuccess = false; // Assume failure unless you specifically succeed.

            di.pDocName = "MTOlive label";
            di.pDataType = "RAW";

            // Open the printer.
            if (OpenPrinter(szPrinterName.Normalize(), out hPrinter, IntPtr.Zero))
            {
                // Start a document.
                if (StartDocPrinter(hPrinter, 1, di))
                {
                    // Start a page.
                    if (StartPagePrinter(hPrinter))
                    {
                        // Write your bytes.
                        bSuccess = RawPrinterHelper.WritePrinter(hPrinter, pBytes, dwCount, out dwWritten);
                        StringBuilder sbData = new StringBuilder();
                        bool aSuccess = ReadPrinter(hPrinter, out sbData, dwWritten, out dwWritten);
                        EndPagePrinter(hPrinter);
                    }
                    EndDocPrinter(hPrinter);
                }
                ClosePrinter(hPrinter);
            }
            // If you did not succeed, GetLastError may give more information
            // about why not.
            if (bSuccess == false)
            {
                dwError = Marshal.GetLastWin32Error();
            }
            return bSuccess;
        }

/////////////////////////////////////


Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>