0

我目前正在试用 VB.NET PrinterSample_Step1, "Hello OPOS for .Net" 。我已经使用 EPSON 高级驱动程序安装了 TM-H6000IV 的驱动程序,并在 SetUpPOS for OPOS.NET 中进行了设置。当我运行示例程序时,它会返回异常:{"The printer is currently being initialized."}. 当我运行 CheckHealthTest 时,它会卡在这个屏幕上:https ://imgur.com/41Z26Ny ,它会返回这个错误:https ://imgur.com/avz0wyz 。这是示例程序中的代码:

Imports Microsoft.PointOfService


Public Class FrameStep1
    Inherits System.Windows.Forms.Form

    Private m_Printer As Microsoft.PointOfService.PosPrinter = Nothing


#Region " Windows Forms Designer generated code."

    Public Sub New()
        MyBase.New()

        ' The InitializeComponent() call is required for windows Forms designer support.
        InitializeComponent()

        ' TODO: Add counstructor code after the InitializeComponent() call.

    End Sub

    ' Rear treatment is carried out in the resource being used.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Design  variable.
    Private components As System.ComponentModel.IContainer

    ' This method is required for Windows Forms designer support.
    'Do not change the method contents inside the source code editor.   
    ' The Forms designer might not be able to load this method if it was changed manually.
    Friend WithEvents btnPrint As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.btnPrint = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnPrint
        '
        Me.btnPrint.Location = New System.Drawing.Point(84, 40)
        Me.btnPrint.Name = "btnPrint"
        Me.btnPrint.Size = New System.Drawing.Size(120, 32)
        Me.btnPrint.TabIndex = 0
        Me.btnPrint.Text = "Print"
        '
        'FrameStep1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(280, 125)
        Me.Controls.Add(Me.btnPrint)
        Me.MaximizeBox = False
        Me.Name = "FrameStep1"
        Me.Text = "Step1 Print ""Hello OPOS for .Net"""
        Me.ResumeLayout(False)

    End Sub

#End Region

    ''' <summary>
    '''  A method "Print" calls some another method.
    '''  They are method for printing.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub btnPrint_Click(ByVal sender As System.Object _
    , ByVal e As System.EventArgs) Handles btnPrint.Click

        '<<<step1>>> Start
        Try
            'As using the PrintNormal method, send strings to a printer, and print it
            '[vbCrLf] is the standard code for starting a new line.
            m_Printer.PrintNormal(PrinterStation.Receipt, "Hello OPOS for .Net" + vbCrLf)

        Catch ex As PosControlException

        End Try
        '<<<step2>>> End

    End Sub
    ''' <summary>
    ''' When the method "changeButtonStatus" was called,
    ''' all buttons other than a button "closing" become invalid.
    ''' </summary>
    Private Sub ChangeButtonStatus()

        'Disable control.
        btnPrint.Enabled = False
    End Sub
    ''' <summary>
    ''' The processing code required in order to enable to use of service is written here.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub FrameStep1_Load(ByVal sender As System.Object _
    , ByVal e As System.EventArgs) Handles MyBase.Load

        '<<<step1>>>--Start
        'Use a Logical Device Name which has been set on the SetupPOS.
        Dim strLogicalName As String
        Dim deviceInfo As DeviceInfo
        Dim posExplorer As PosExplorer

        strLogicalName = "PosPrinter2"

        'Create PosExplorer
        posExplorer = New PosExplorer

        m_Printer = Nothing

        Try

            deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, strLogicalName)
            m_Printer = posExplorer.CreateInstance(deviceInfo)

        Catch ex As Exception
            ChangeButtonStatus()
            Return
        End Try

        Try

            'Open the device
            m_Printer.Open()

            'Get the exclusive control right for the opened device.
            'Then the device is disable from other application.
            m_Printer.Claim(1000)

            'Enable the device.
            m_Printer.DeviceEnabled = True

        Catch ex As PosControlException

            ChangeButtonStatus()

        End Try
        '<<<step1>>>--End
    End Sub
    ''' <summary>
    ''' When the method "closing" is called,
    ''' the following code is run.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    Private Sub FrameStep1_Closing(ByVal sender As Object _
    , ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        '<<<step1>>>--Start
        If m_Printer Is Nothing Then
            Return
        End If

        Try
            'Cancel the device
            m_Printer.DeviceEnabled = False

            'Release the device exclusive control right.
            m_Printer.Release()


        Catch ex As Exception

        Finally
            'Finish using the device.
            m_Printer.Close()

        End Try
        '<<<step1>>>--End

    End Sub
End Class

异常将在以下几行中被捕获:

    Private Sub btnPrint_Click(ByVal sender As System.Object _
    , ByVal e As System.EventArgs) Handles btnPrint.Click

        '<<<step1>>> Start
        Try
            'As using the PrintNormal method, send strings to a printer, and print it
            '[vbCrLf] is the standard code for starting a new line.
            m_Printer.PrintNormal(PrinterStation.Receipt, "Hello OPOS for .Net" + vbCrLf)

        Catch ex As PosControlException

        End Try
        '<<<step2>>> End

    End Sub

我发现了这个问答:https ://okbizcs.okwave.jp/epson/questiondetail/?qid=8318452但它似乎与这个问题无关。

这是 CheckHealthTest 的完整例外:

================== Exception =====================
Microsoft.PointOfService.PosControlException
ErrorCode : Offline (108)
ErrorCodeExtended : 5010
Message : The printer is currently being initialized.
Target : System.String CheckHealth(Microsoft.PointOfService.HealthCheckLevel)
## StackTrace ##
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.CheckHealth(HealthCheckLevel level)
   at CheckHealthTest.MainForm.ExecuteCheckHealth(DeviceInfo objInfo)
   at CheckHealthTest.MainForm.btnCheckHealth_Click(Object sender, EventArgs e)
---------InnerException-----------
jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterStateException
Message : The printer is currently being initialized.
Target : Void ConfirmConditionForNotOfflineCommand(Int32)
## StackTrace ##
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmConditionForNotOfflineCommand(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.CheckError(Int32[] aiStationIndex, Boolean bAfterQueue)

这是程序的堆栈跟踪:

ErrorCode: Failure
ErrorCodeExtended: 0
Stack trace:    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at Microsoft.PointOfService.PosException.GetExceptionText(Exception e)
   at Microsoft.PointOfService.PosException.LogError()
   at Microsoft.PointOfService.PosControlException..ctor(String message, ErrorCode errorCode, Int32 errorCodeExtended)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.OutputData(Byte[] abyData, Boolean bAddSelect, Int64 lTimeout, Boolean bFlow)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.OutputData(Byte[] abyData, Boolean bFlow)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.GetPrinterStatus(Boolean bFullCheck, Int64 lTimeout)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.GetPrinterStatus(Boolean bFullCheck)
   at jp.co.epson.upos.H6000IV.pntr.init.H6000IV_Initialization.InitializeCommon()
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.Initialize()
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.Initialize(Int32 iResetCounter)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.InitializationThread.ThreadProcess()
   at jp.co.epson.uposcommon.core.v1_14_0001.util.EpsonCommonThread.Run()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   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()
[PosException]: Microsoft.PointOfService.PosControlException: The device is offline.
ErrorCode: Failure
ErrorCodeExtended: 0
Stack trace:    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at Microsoft.PointOfService.PosException.GetExceptionText(Exception e)
   at Microsoft.PointOfService.PosException.LogError()
   at Microsoft.PointOfService.PosControlException..ctor(String message, ErrorCode errorCode, Int32 errorCodeExtended)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.OutputData(Byte[] abyData, Boolean bAddSelect, Int64 lTimeout, Boolean bFlow)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.GetRealtimeStatus()
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.GetPrinterStatus(Boolean bFullCheck, Int64 lTimeout)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.GetPrinterStatus(Boolean bFullCheck)
   at jp.co.epson.upos.H6000IV.pntr.init.H6000IV_Initialization.InitializeCommon()
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.Initialize()
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.AbstractPrinterInitialization.Initialize(Int32 iResetCounter)
   at jp.co.epson.upos.core.v1_14_0001.pntr.init.InitializationThread.ThreadProcess()
   at jp.co.epson.uposcommon.core.v1_14_0001.util.EpsonCommonThread.Run()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   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()
[PosException]: Microsoft.PointOfService.PosControlException: The printer is currently being initialized. ---> jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterStateException: The printer is currently being initialized.
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmConditionForNotOfflineCommand(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmCondition(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.CheckError(Int32[] aiStationIndex, Boolean bAfterQueue)
   --- End of inner exception stack trace ---
ErrorCode: Failure
ErrorCodeExtended: 0
Stack trace:    at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
   at System.Environment.get_StackTrace()
   at Microsoft.PointOfService.PosException.GetExceptionText(Exception e)
   at Microsoft.PointOfService.PosException.LogError()
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.CreatePosControlException(Int32 iErrorCode, Int32 iErrorCodeExtended, String strMessage, Exception orgException)
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonUPOSExceptionCreator.CreatePosControlException(PrinterStateException orgException, Boolean bAfterQueue)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.CheckError(Int32[] aiStationIndex, Boolean bAfterQueue)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.OutputToPrinterImp(OutputDataStruct dataStruct, Boolean fromPrinterService)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.OutputToPrinter(OutputDataStruct dataStruct)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.OutputToPrinterForProcessID_EJ.OutputToPrinter(OutputDataStruct dataStruct)
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.SendOutputData(OutputDataStruct outputData, Int32 iTransmitType, Boolean bAsync, Boolean bFlow, Boolean bImmediate)
   at jp.co.epson.upos.H6000IV.pntr.H6000IVService.SendOutputData(OutputDataStruct outputData, Int32 iTransmitType, Boolean bAsync, Boolean bFlow, Boolean bImmediate)
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.SendOutputData(OutputDataStruct outputData, Boolean bAsync, Boolean bFlow, Boolean bImmediate)
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.ExecuteNormalPrint(Int32 iStationIndex, String strData, Boolean bTransaction, Boolean bFlow, Boolean bImmediate)
   at jp.co.epson.upos.core.v1_14_0001.pntr.CommonPrinterService.PrintNormal(PrinterStation station, String strData)
   at jp.co.epson.upos.H6000IV.pntr.H6000IVService.PrintNormal(PrinterStation station, String strData)
   at PrinterSample_Step1.FrameStep1.btnPrint_Click(Object sender, EventArgs e) in D:\Epson-OPOS-ADK\Samples\VB.NET\Printer\PrinterSample_Step1\FrameStep1.vb:line 78
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   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 System.Windows.Forms.Application.Run(Form mainForm)
   at PrinterSample_Step1.FrameStep1.Main()
Inner Exception: jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterStateException: The printer is currently being initialized.
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmConditionForNotOfflineCommand(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmCondition(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.CheckError(Int32[] aiStationIndex, Boolean bAfterQueue)
Stack trace:    at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmConditionForNotOfflineCommand(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.state.PrinterState_USBSerialCompatible.ConfirmCondition(Int32 iStation)
   at jp.co.epson.upos.core.v1_14_0001.pntr.io.CommonOutputToPrinterAndEJ.CheckError(Int32[] aiStationIndex, Boolean bAfterQueue)
Exception thrown: 'Microsoft.PointOfService.PosControlException' in Epson.opos.tm.service.v1_14_0001.dll
The program '[16316] PrinterSample_Step1.exe' has exited with code -1 (0xffffffff).
4

1 回答 1

0

可能打印机的收据卷轴没有正确装入或纸张/打印头盖板打开。

在该状态下,无法向打印机发送正常命令,因此无法进行打印。

由于设置了Claim方法和DeviceEnabled=true时的初始化,无法发送状态通知规范命令,可能已经确定打印机还在初始化过程中,无法通信。

如果收据卷或打印机盖状况良好,但仍然出现这些错误,那么您要么指定了要连接的 COM 端口名称,要么打印机和设备驱动程序未处于串行端口模式(供应商类)。它可以设置为并口模式(打印机类)。

这可能是那些已收到错误通知的结果。


针对评论描述:

如果您没有连接打印机,仅此而已。
示例程序假定连接了一台可以正常打印的实际打印机。

它不仅限于 EPSON 打印机,还包括任何打印机或其他设备。
除非模拟器/模拟器软件明确提供。

于 2021-07-08T02:32:22.983 回答