3

I am developing a POS using c# with WPF. I need to check if the cash drawer is open or not to tell the user that it needs to be closed before the next sell.

My cash drawer is a dynapos connected to a receipt printer ECLine (I have no drivers installed, just using the generics from windows), this printer is connected by USB to the PC. So far I am able to print using RawPrinterHelper and open the cashdrawer using:

byte[] codeOpenCashDrawer = new byte[] { 27, 112, 48, 55, 121 };
IntPtr pUnmanagedBytes = new IntPtr(0);
pUnmanagedBytes = Marshal.AllocCoTaskMem(5);
Marshal.Copy(codeOpenCashDrawer, 0, pUnmanagedBytes, 5);
RawPrinterHelper.SendBytesToPrinter(stringPrinterName, pUnmanagedBytes, 5);
Marshal.FreeCoTaskMem(pUnmanagedBytes);

In the same way I am able to open the cash drawer, I was hoping to get the status of it by sending some bytes. I found this solution in which says:

To get the status of the drawer I need to use DLE EOT n

The problem is that I can't get to know if the bytes are the good ones since I can't get a response from the RawPrinterHelper when using the SendBytesToPrinter method.

Questions:

1) Is there a way to get this status using RawPrinterHelper?

2) If the bytes I am sending are not the correct ones, how can i determine which ones are the correct ones?

3) Do I need to install a driver for the printer? I have read about some people that does it, but I would not like to do this because each place in where my POS is installed has different hardware.

Fernando Santiago
  • 2,128
  • 10
  • 44
  • 75
  • 1) You would need the Manufacturer to tell you (Manual?). 2) as per 1. 3) Have you looked at https://learn.microsoft.com/en-us/uwp/api/windows.devices.pointofservice ? – Andrew Harris May 30 '18 at 21:25
  • You tagged the question ‘OPOS’, but unfortunately you aren’t using it. It would solve all your cash drawer issues. But then you’d have to address all your legacy printing code. OPOS is great - it turns POS hardware into a compatible commodity that lets you swap any POS device for a different vendor’s product, letting you buy from whoever puts in the best bid, and not needing application changes to handle hardware. – John Deters May 31 '18 at 12:16
  • @John Deters Do I actually need to install drivers when using OPOS? I am using OPOS for MSR, but I have to install the drivers of each MSR device which turns out to be a pain because every client has different MSR – Fernando Santiago May 31 '18 at 17:17
  • You have to install the vendor‘s provided OPOS Service Object, but once that works, your app usually just works. – John Deters Jun 05 '18 at 18:18

1 Answers1

2

With the Windows print spooler API you are using, the application can not know the printer/cash drawer status.

Depending on the vendor of the printer, you may have provided a device driver that has its own extended function to know the status.

For example, EPSON provides a status API function with the name Advanced Printer Driver. (Because English explanation page could not be found, Japanese page introduced)

Ask your vendor of your printer if these extension APIs are available.

When there is no extended API, one of the following methods is considered.

1.Switch to the printer such as EPSON where the extension API exists.
2.Switch the printer to a mode that operates as a peripheral connected to a COM port instead of a Windows printer, and directly send and receive ESC/POS commands and responses using the COM port.
3.Install one of OPOS/POS for.NET/JavaPOS and switch between control method of printer and cash drawer.

kunif
  • 4,060
  • 2
  • 10
  • 30