2009-10-02 67 views
2

與斑馬GK420d溝通我使用我正在開發一個POS應用斑馬GK420d標籤打印機。我試圖通過Zebra提供的OPOS驅動程序與打印機進行通信。但我陷入困境。這是一個簡單的形式在視覺基本2008年與一個按鈕。這是我正在運行的完整代碼。通過斑馬OPOS驅動器

公共類FrameStep1 繼承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 

末級

你可以看到,我已呼籲要求(),並設置DeviceEnabled =真。然而,當我調試它會發生什麼是隨着控制傳遞m_Printer.Open()它神奇地結束了在btnPrint_Click(),並不會進一步,除非我點擊我的窗體上的按鈕,然後在m_Printer.PrintNormal()它打破並拋出POSControlException,其中的文本顯示「嘗試訪問在方法或屬性設置操作可以使用之前必須聲明的專用設備」。

難道我似乎是在這裏做什麼錯事。

回答

1

你可以試試這個:

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打印機等待切紙機開始打印前。