How to Open Cashdrawer using POS for .NET v1.14 SDK ?

AADHITHYA A S V 6 Reputation points
2021-02-09T17:58:50.707+00:00

I'm creating an windows form (C#) to Open drawer and check if cashdrawer is open or close using POS for .NET v1.14 SDK.

Note : Cashdrawer is directly connected to system

Tried following code but no luck

using Microsoft.PointOfService;  
using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.IO.Ports;  
using System.Linq;  
using System.Text;  
using System.Threading.Tasks;  
using System.Windows.Forms;  
  
  
namespace Appletay  
{  
    public partial class Login : Form  
    {  
   
        public PosExplorer myExplorer;  
        public CashDrawer myCashDrawer;  
        public Login()  
        {  
            InitializeComponent();  
            myExplorer = new PosExplorer(this);  
            //myExplorer = new PosExplorer();  
            DeviceInfo device = myExplorer.GetDevice("CashDrawer");  
            myCashDrawer = (CashDrawer)myExplorer.CreateInstance(device);  
  
        }  
  
   
  
        private void i0_Click(object sender, EventArgs e)  
        {  
             myCashDrawer.Open();  
            myCashDrawer.Claim(1000);  
            myCashDrawer.DeviceEnabled = true;  
            myCashDrawer.OpenDrawer();  
            myCashDrawer.DeviceEnabled = false;  
            myCashDrawer.Release();  
            myCashDrawer.Close();  
        }  
  
      
             
         
    }  
}  

getting following error during debug.
65982-snippet.png

Is it looking for specific device connected to my machine and it got failed as it was unable to detect it?

Can someone help me out to short out this please.

Thanks in Advance

Developer technologies | Windows Forms
Windows for business | Windows for IoT
{count} votes

2 answers

Sort by: Most helpful
  1. Sean Liming 4,766 Reputation points Volunteer Moderator
    2021-02-18T16:55:15.747+00:00

    The trick is setting up the OPOS driver or PSO for .NET Service object first, before attempting to access via an application. To verify the OPOS driver is setup correctly, please run the TestApp.exe that is part of the POS for .NET SDK. The TestApp application is found here: C:\Program Files (x86)\Microsoft Point Of Service\SDK\Samples\Sample Application. If you see your cash drawer in the list, you can then attempt to open, claim, and open the cash drawer. If you do not see the cash drawer in the list, then you need to configure the OPOS driver using the manufacturer's utilities.

    Is the cash drawer connected via USB, serial, or parallel?

    69714-image.png

    BTW - You will want to use the latest version of POS for .NET 1.14.1: https://www.microsoft.com/en-us/download/details.aspx?id=55

    0 comments No comments

  2. Mark W 1 Reputation point
    2021-07-26T04:46:14.627+00:00

    Hi Sean,

    I have a question related to this (slightly old) post. And also, let me prefix all of this with, I'm completely new to POS development.

    Per your comment above, I don't see my USB connected CashDrawer in the list of nodes. When I get a list of CashDrawer devices (using PosExplorer's GetDevices) all I see is the MS simulator. Not sure where to go from here because my CashDrawers shows up in Device Manager and seems fine.

    As a side step, I created a MyCashDrawer service object class deriving from CashDrawerBase (adorning it with my physical cash drawer's HardwareId [from device manager]). I also adorned with ServiceObject providing all the proper values (see further down). Then in my button click I have:

    _myCashDrawer = new CashDrawerServiceObject();
    //
    _myCashDrawer.Open();
    _myCashDrawer.DeviceEnabled = true;
    _myCashDrawer.Claim(1000);
    _myCashDrawer.OpenDrawer();
    _myCashDrawer.Close();
    

    All is good except OpenDrawer does not 'open the drawer'. I understand why because it just calls the OpenDrawerImpl to which I can't just call OpenDrawer because it's recursive and will result in an overflow.

    What should be in the overidden OpenDrawerImpl to actually open the cash drawer?

    [HardwareId("USB\\VID_0451&PID_0909", "USB\\VID_0451&PID_0909")]
    [ServiceObject(DeviceType.CashDrawer, "MyCashDrawer", "My cash drawer", 2, 0)]
    public class CashDrawerServiceObject : CashDrawerBase
    {
        public CashDrawerServiceObject()
        {
            DevicePath = "USB\\VID_0451&PID_0909\\D2E1F03469A7B5C803469A7B5C8D2E1F";
        }
    
        public override string CheckHealth(HealthCheckLevel level)
        {
            VerifyState(true, true);
            //
            return "Ok";
        }
    
        public override DirectIOData DirectIO(int command, int data, object obj)
        {
            VerifyState(false, false);
            //
            return new DirectIOData(data, obj);
        }
    
        public override string CheckHealthText { get; }
    
        protected override void OpenDrawerImpl()
        {
            //what to do here?
        }
    }
    

    All I need to do is open the cash drawer at this time.

    Thanks in advance, Sean.

    -Mark

    PS - I tried buying your book but your site kept telling me "Confirm Email is required" and I had it filled out with an exact match of my email.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.