问题描述
嗨!我是创建POS系统的新手。
我想在打印开始时打开我的现金抽屉。我在互联网上找到了一些代码,但它们似乎没有用。它总是给我这个错误:对象引用没有设置为对象的实例。
这是我的代码:
Hi! I am new in creating POS systems.
I want to open my cash drawer when printing starts. I have found some codes in the internet but they do not seem to work. It always gives me this error: Object reference not set to an instance of an object.
This is my codes:
using Microsoft.PointOfService;
CashDrawer myCashDrawer = null;
PosExplorer explorer;
public void CashDrawerClass()
{
try
{
explorer = new PosExplorer();
DeviceInfo ObjDevicesInfo = explorer.GetDevice("C4141");
bool check = ObjDevicesInfo.IsDefault;
myCashDrawer = (CashDrawer)explorer.CreateInstance(ObjDevicesInfo);
}
catch (Exception ex)
{
MessageBox.Show("CashDrawerClass: " + ex.Message);
}
}
public void OpenCashDrawer()
{
try
{
myCashDrawer.Open();
myCashDrawer.Claim(1000);
myCashDrawer.DeviceEnabled = true;
myCashDrawer.OpenDrawer();
myCashDrawer.DeviceEnabled = false;
myCashDrawer.Release();
myCashDrawer.Close();
}
catch (NullReferenceException ex)
{
MessageBox.Show("OpenCashDrawer: " + ex.Message);
}
}
现金抽屉已连接到我的打印机。
The cash drawer is connected to my printer.
推荐答案
if (ObjDevicesInfo == null)
Report an error.
2.检查 myCashDrawer
被赋予一个值。
myCashDrawer.Open();
当你调用OpenCashDrawer()时,最明显的事情,除了看起来有点凌乱的设计/实现方面,我看不到任何类似的东西
when you call OpenCashDrawer(), the most obvious thing, apart from it looking a bit messy design/implementation-wise, is I dont see anything that looks like
myCashDrawer = new CashDrawer();
可能将参数传递给CashDrawer对象的实例化
possibly with arguments being passed into the instantiation of the CashDrawer Object
这篇关于打印开始时如何打开CashDrawer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!