title: Communicating with Zebra GK420d through Zebra OPOS driver
body: <p>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.</p>
  
  <p>Public Class FrameStep1 
              Inherits System.Windows.Forms.Form</p>
  
  <pre><code>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
  </code></pre>
  
  <p>End Class</p>
  
  <p>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."</p>
  
  <p>Do I seem to be doing anything wrong here.</p>