0

I need to open Cash Drawer in my WPF application, this is the first time I deal with Cash Drawer, after some search I have knew that I'll use Microsoft Point of Services. So I have installed POSforDotNet V1.14 and start new project and added the reference, I have found this example :

CashDrawer myCashDrawer;
PosExplorer explorer;

public MainWindow()
{
    InitializeComponent();
    this.Loaded += MainWindow_Loaded;
}

void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
    explorer = new PosExplorer();
    DeviceInfo ObjDevicesInfo = explorer.GetDevice("CashDrawer");
    myCashDrawer = explorer.CreateInstance(ObjDevicesInfo);

}

private void Button_Click(object sender, RoutedEventArgs e)
{
    myCashDrawer.Open();
    myCashDrawer.Claim(1000);
    myCashDrawer.DeviceEnabled = true;
    myCashDrawer.OpenDrawer();
    myCashDrawer.DeviceEnabled = false;
    myCashDrawer.Release();
    myCashDrawer.Close();
}

You can download my test application HERE

I have tried but it dose not work :(

gave me error in myCashDrawer = explorer.CreateInstance(ObjDevicesInfo); line

Please can help me because I'm stuck with Microsoft Point of Services and I'm not fully understand it.

Tharif
  • 13,794
  • 9
  • 55
  • 77
Abdulsalam Elsharif
  • 4,773
  • 7
  • 32
  • 66
  • Can you define 'does not work'? – Patrick Hofman Apr 29 '14 at 12:08
  • @PatrickHofman, Thanks for your time ,It gave me error in myCashDrawer = explorer.CreateInstance(ObjDevicesInfo); line. you can download the test application – Abdulsalam Elsharif Apr 29 '14 at 12:11
  • 4
    You need to also post the error you received in your original question. I seem to remember when I used POS for .NET that there was a separate application that needed to be used to claim the device on the windows level. You might try researching that. – alan Apr 29 '14 at 12:12
  • Upvote on @alan specifically for "post the error". – Steve Apr 29 '14 at 12:49
  • 1
    Do you have a OPOS cashdraw named CashDrawer set up ? You can check in the registry under HKEY_LOCAL_MACHINE\SOFTWARE\OLEforRetail\ServiceOPOS\CashDrawer` there should be a sub key named `CashDrawer`. Also how is the cashdraw connected to the computer, direct connect or via a printer? – Re0sless May 01 '14 at 07:41
  • http://stackoverflow.com/questions/7736676/c-sharp-code-for-open-close-drawer-and-printing-the-receipt-at-the-same-time – Mohamed Abd Elaziz Aug 06 '15 at 00:24
  • http://stackoverflow.com/questions/7736676/c-sharp-code-for-open-close-drawer-and-printing-the-receipt-at-the-same-time – Mohamed Abd Elaziz Aug 06 '15 at 00:26
  • http://stackoverflow.com/questions/7736676/c-sharp-code-for-open-close-drawer-and-printing-the-receipt-at-the-same-time you need to try this. – Mohamed Abd Elaziz Aug 06 '15 at 00:57

3 Answers3

3

You need to typecast to CashDrawer. I updated your code now sure you will not get error.

myCashDrawer = (CashDrawer)explorer.CreateInstance(ObjDevicesInfo);
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Anant Shah
  • 31
  • 2
2

Besides the (CashDrawer) cast, I'd recommend to use

DeviceInfo ObjDevicesInfo = explorer.GetDevice("CashDrawer", "LOGICAL DEVICE NAME for your cash drawer");

If you had more than one installed and you just use one parameter, it'll throw an error (and MSPOS v1.14 installs a phony cash drawer for testing, so you've got at least your physical and that one).

Mario
  • 283
  • 2
  • 13
0
            System.IO.Ports.SerialPort port = null;
            port = new System.IO.Ports.SerialPort(Program.CashDrawerPort);
            port.PortName = Program.CashDrawerPort;
            port.BaudRate = 9600;
            port.Parity = System.IO.Ports.Parity.None;
            port.DataBits = 8;
            port.StopBits = System.IO.Ports.StopBits.One;
            port.RtsEnable = true;
            try
            {
                port.Open();
                if (port.IsOpen)
                {
                    port.Write("B");
                }
                else
                {
                }
                port.Close();
            }
            catch (Exception exceptionMessage)
            {
            }
  • 1
    Usually it's better to explain a solution instead of just posting some rows of anonymous code. You can read [How do I write a good answer](https://stackoverflow.com/help/how-to-answer), and also [Explaining entirely code-based answers](https://meta.stackexchange.com/questions/114762/explaining-entirely-%E2%80%8C%E2%80%8Bcode-based-answers) – Anh Pham Oct 20 '18 at 16:07