我试图打开一个带有C#的Posiflex现金抽屉。这是代码(由其他人提供):
using System;
using System.Collections.Generic;
using Microsoft.PointOfService;
namespace MyNamespace
{
public class CashDrawerClass
{
CashDrawer myCashDrawer;
PosExplorer explorer;
public CashDrawerClass()
{
explorer = new PosExplorer();
DeviceInfo ObjDevicesInfo = explorer.GetDevice("CashDrawer", "RR-Drawer");
myCashDrawer = explorer.CreateInstance(ObjDevicesInfo) as CashDrawer;
}
public void OpenCashDrawer()
{
myCashDrawer.Open();
myCashDrawer.Claim(1000);
myCashDrawer.DeviceEnabled = true;
myCashDrawer.OpenDrawer();
myCashDrawer.DeviceEnabled = false;
myCashDrawer.Release();
myCashDrawer.Close();
}
}
}一旦执行到达代码:
资源管理器=新的PosExplorer(),将引发以下异常:
System.NullReferenceException类型的未处理异常发生在mscorlib.dll中。
如果有帮助,下面是堆栈跟踪:
at Microsoft.PointOfService.Pos4NetTelemetry.IsCeipOptInEnabled()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Microsoft.PointOfService.Pos4NetTelemetry.get_Enabled()
at Microsoft.PointOfService.Pos4NetTelemetry.SetCurrentProcessBitness()
at Microsoft.PointOfService.PosExplorer.Initialize()
at Microsoft.PointOfService.PosExplorer..ctor()
at RunningRabbit.CashDrawerClass..ctor() in c:\C# Development\RunningRabbit\RunningRabbit\CashDrawerClass.cs:line 14
at RunningRabbit.MainPOS.btnOpenDrawer_Click(Object sender, EventArgs e) in c:\C# Development\RunningRabbit\RunningRabbit\MainPOS.cs:line 261
at System.Windows.Forms.Control.OnClick(EventArgs e)
at DevExpress.XtraEditors.BaseButton.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at DevExpress.Utils.Controls.ControlBase.WndProc(Message& m)
at DevExpress.XtraEditors.BaseControl.WndProc(Message& msg)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at RunningRabbit.Program.Main() in c:\C# Development\RunningRabbit\RunningRabbit\Program.cs:line 20
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()任何帮助都将不胜感激。
发布于 2016-10-14 14:15:41
在堆栈跟踪中可以看到:
初始化时的PosExplorer检查是否允许它在POS分期付款期间将遥测发送给微软用于.NET。代码试图读取此属性:
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\POSfor.Net\\Setup").GetValue("CeipOptIn", (object) 0);因此,如果没有安装.NET的POS,则此Subkey不在注册表中,然后抛出异常。
注意:
遥测只包含在1.14版本的POS为.NET。我建议使用1.12版本的,它具有相同的功能,无需遥测。
https://stackoverflow.com/questions/32375213
复制相似问题