1

I need to send Ascii commands to TRITON 60 SERIES 60 mm MINI-KIOSK and want to get status using C# code

Eg: "DLE EOT SOH" this is the ascii code for getting the printers real time status, How can i send this command to printer using C# and get the status of the printer.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vishnu
  • 192
  • 13

1 Answers1

1

According to an Axiohm TRITON 60 data sheet I found online, this printer is compatible with the ESC/POS command set over either USB or RS232.

A guy called Nicholas Piasecki has a blog where he talks about sending data to a printer that supports this command set. From a blog entry of his is this code (see "Sending the document to the printer" near the end):

private static void Print(string printerName, byte[] document)
{
    NativeMethods.DOC_INFO_1 documentInfo;
    IntPtr printerHandle;

    documentInfo = new NativeMethods.DOC_INFO_1();
    documentInfo.pDataType = "RAW";
    documentInfo.pDocName = "Bit Image Test";

    printerHandle = new IntPtr(0);

    if (NativeMethods.OpenPrinter(printerName.Normalize(), out printerHandle, IntPtr.Zero))
    {
        if (NativeMethods.StartDocPrinter(printerHandle, 1, documentInfo))
        {
            int bytesWritten;
            byte[] managedData;
            IntPtr unmanagedData;

            managedData = document;
            unmanagedData = Marshal.AllocCoTaskMem(managedData.Length);
            Marshal.Copy(managedData, 0, unmanagedData, managedData.Length);

            if (NativeMethods.StartPagePrinter(printerHandle))
            {
                NativeMethods.WritePrinter(
                    printerHandle,
                    unmanagedData,
                    managedData.Length,
                    out bytesWritten);
                NativeMethods.EndPagePrinter(printerHandle);
            }
            else
            {
                throw new Win32Exception();
            }

            Marshal.FreeCoTaskMem(unmanagedData);

            NativeMethods.EndDocPrinter(printerHandle);
        }
        else
        {
            throw new Win32Exception();
        }

        NativeMethods.ClosePrinter(printerHandle);
    }
    else
    {
        throw new Win32Exception();
    }
}

It's basically a bunch of P/Invoke calls (he provides a link to sample code in his blog article) that let you send the raw data to a named printer (presumably over USB if that's how the printer is connected). I know the printer model is different to yours but hopefully the communication technique is similar.

I would suggest reading his article and downloading and examining his sample code to see if there's anything there that might help you. In particular he has links to the ESC/POS command and programming guides which might prove useful if you don't already have them.

Steven Rands
  • 5,160
  • 3
  • 27
  • 56
  • From this method we can only write commands to the printer, we cannot get the status returned – Vishnu Jan 13 '15 at 12:59
  • @Vish: OK, the answers to this SO question [(Reading status from Zebra Printer)](http://stackoverflow.com/questions/1846340/reading-status-from-zebra-printer) might help. It uses the CreateFile/WriteFile/ReadFile API to communicate with the printer instead of using a spooled print job. – Steven Rands Jan 13 '15 at 13:37
  • @Vish: Alternatively, there's an email address for Nicholas Piasecki on his blog, you could try emailing him and asking if he has any ideas. [He's also on SO](http://stackoverflow.com/users/32187/nicholas-piasecki) – Steven Rands Jan 13 '15 at 13:39