Open Cash Drawer

2019-09-17 13:41发布

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.

3条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-17 14:26
            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)
            {
            }
查看更多
3楼-- · 2019-09-17 14:30

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).

查看更多
祖国的老花朵
4楼-- · 2019-09-17 14:32

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

myCashDrawer = (CashDrawer)explorer.CreateInstance(ObjDevicesInfo);
查看更多
登录 后发表回答