wpf 打开钱箱
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23364208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open Cash Drawer
提问by Abdulsalam Elsharif
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 :
我需要在我的 WPF 应用程序中打开 Cash Drawer,这是我第一次处理 Cash Drawer,经过一番搜索我知道我将使用 Microsoft Point of Services。所以我安装了 POSforDotNet V1.14 并开始新项目并添加了参考,我找到了这个例子:
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
在 myCashDrawer = explorer.CreateInstance(ObjDevicesInfo) 中给了我错误;线
Please can help me because I'm stuck with Microsoft Point of Services and I'm not fully understand it.
请帮助我,因为我被微软服务点困住了,我不完全理解它。
回答by Anant Shah
You need to typecast to CashDrawer. I updated your code now sure you will not get error.
您需要将类型转换为CashDrawer. 我现在更新了您的代码,确保您不会出错。
myCashDrawer = (CashDrawer)explorer.CreateInstance(ObjDevicesInfo);
回答by Mario
Besides the (CashDrawer) cast, I'd recommend to use
除了 (CashDrawer) 演员表,我建议使用
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).
如果您安装了多个并且只使用一个参数,它会抛出一个错误(并且 MSPOS v1.14 安装了一个虚假的现金抽屉用于测试,所以您至少有您的物理和那个)。
回答by user3458630
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)
{
}

