通过 Zebra OPOS 驱动程序与 Zebra GK420d 通信

发布于 2024-08-06 15:43:35 字数 2016 浏览 11 评论 0原文

我正在使用 Zebra GK420d 标签打印机来开发 POS 应用程序。我正在尝试通过 Zebra 提供的 OPOS 驱动程序与打印机进行通信。但我遇到了麻烦。这是 Visual Basic 2008 中的一个简单窗体,上面有一个按钮。这是我正在运行的完整代码。

公共类框架Step1 继承System.Windows.Forms.Form

Private m_Printer As Microsoft.PointOfService.PosPrinter = Nothing

Private Sub ChangeButtonStatus()

    'Disable control.
    btnPrint.Enabled = False
End Sub

Private Sub FrameStep1_Load(ByVal sender As System.Object _
, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim strLogicalName As String
    Dim deviceInfo As DeviceInfo
    Dim posExplorer As PosExplorer

    strLogicalName = "zebra"
    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

        m_Printer.Open()
        m_Printer.Claim(1000)
        m_Printer.DeviceEnabled = True

    Catch ex As PosControlException

        ChangeButtonStatus()

    End Try
End Sub


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

    Try

        m_Printer.PrintNormal(PrinterStation.Receipt, "Hello OPOS for .Net" + vbCrLf)

    Catch ex As PosControlException

    End Try
End Sub

Private Sub FrameStep1_Closing(ByVal sender As Object _
, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

    If m_Printer Is Nothing Then
        Return
    End If

    Try
        m_Printer.DeviceEnabled = False
        m_Printer.Release()
    Catch ex As Exception

    Finally
        m_Printer.Close()

    End Try
End Sub

End Class

您可以看到我已经调用了claim()并设置了DeviceEnabled=true。但是,当我调试它时,发生的情况是,当控件传递到 m_Printer.Open() 时,它会神奇地以 btnPrint_Click() 结束,并且不会再进一步​​,除非我单击表单上的按钮,然后单击 m_Printer.PrintNormal() 它中断并抛出 POSControlException,其中的文本显示“尝试访问独占设备,在使用方法或属性设置操作之前必须声明该设备”。

我在这里似乎做错了什么吗?

I am using a Zebra GK420d label printer for a POS application that i am developing. I am trying to communicate with the printer through its OPOS drivers provided by Zebra. But i get into trouble. It is a simple form in visual basic 2008 with a button on it. Here is the complete code that i am running.

Public Class FrameStep1
Inherits System.Windows.Forms.Form

Private m_Printer As Microsoft.PointOfService.PosPrinter = Nothing

Private Sub ChangeButtonStatus()

    'Disable control.
    btnPrint.Enabled = False
End Sub

Private Sub FrameStep1_Load(ByVal sender As System.Object _
, ByVal e As System.EventArgs) Handles MyBase.Load

    Dim strLogicalName As String
    Dim deviceInfo As DeviceInfo
    Dim posExplorer As PosExplorer

    strLogicalName = "zebra"
    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

        m_Printer.Open()
        m_Printer.Claim(1000)
        m_Printer.DeviceEnabled = True

    Catch ex As PosControlException

        ChangeButtonStatus()

    End Try
End Sub


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

    Try

        m_Printer.PrintNormal(PrinterStation.Receipt, "Hello OPOS for .Net" + vbCrLf)

    Catch ex As PosControlException

    End Try
End Sub

Private Sub FrameStep1_Closing(ByVal sender As Object _
, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

    If m_Printer Is Nothing Then
        Return
    End If

    Try
        m_Printer.DeviceEnabled = False
        m_Printer.Release()
    Catch ex As Exception

    Finally
        m_Printer.Close()

    End Try
End Sub

End Class

You can see that i have called claim() and set DeviceEnabled=true. However, when i debug it what happens is as the control passes over m_Printer.Open() it magically ends up in btnPrint_Click() and does not go any further unless i click the button on my form and then at m_Printer.PrintNormal() it breaks and throws POSControlException and the text therein reads "An attempt was made to access an exclusive-use device that must be claimed before the method or property set action can be used."

Do I seem to be doing anything wrong here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2024-08-13 15:43:35

您可以尝试以下操作:

if (m_Printer.State == ControlState.Closed)
  { m_Printer.Open();     }           

if (!m_Printer.Claimed)
                   { m_Printer.Claim(0);}

if (!m_Printer.DeviceEnabled)
                   { m_Printer.DeviceEnabled = true;}

Printer.PrintNormal(PrinterStation.Receipt, text);

Printer.CutPaper(100);

另请记住,某些 ZEBRA 打印机在开始打印之前会等待切纸机。

You could try this:

if (m_Printer.State == ControlState.Closed)
  { m_Printer.Open();     }           

if (!m_Printer.Claimed)
                   { m_Printer.Claim(0);}

if (!m_Printer.DeviceEnabled)
                   { m_Printer.DeviceEnabled = true;}

Printer.PrintNormal(PrinterStation.Receipt, text);

Printer.CutPaper(100);

Also remember that some ZEBRA printers wait for the paper cutter before starting to print.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文