Open Cash Drawer

烂漫一生 提交于 2020-01-06 14:17:17

问题


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.


回答1:


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

myCashDrawer = (CashDrawer)explorer.CreateInstance(ObjDevicesInfo);



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




回答3:


            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)
            {
            }


来源:https://stackoverflow.com/questions/23364208/open-cash-drawer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!