Zebra Browser打印到联网打印机~HQES收到空白响应

时间:2018-04-03 09:49:59

标签: printing zebra

我在Windows上的Web应用程序中使用浏览器打印到iMZ320打印机。当打印机通过USB连接时,整个应用程序流程正常,~HQES请求打印机状态返回信息,我可以发送命令和项目以便成功打印。

当我将打印机连接更改为网络连接时,我可以使用浏览器打印进行正常打印,但~HQES响应为空。我可以使用HTTP POST命令打印并通过Postman发送它,它工作正常。当我在Postman中发送~HQES命令时,我得到一个带有200(成功)响应的空响应,所以并不是它的浏览器打印代码以某种方式屏蔽了响应。当我使用Zebra Setup Utilities发送~HQES命令时,我得到了响应:

"







  PRINTER STATUS                           

  ERRORS:         0 00000000 00000000     

  WARNINGS:       0 00000000 00000000     

"

当打印机不在打印机或门打开时,我通过Zebra Setup Utilities发送命令时,我得到的预期错误响应与上面显示的OK响应的格式相同。

有人知道如何获取联网打印机的打印机状态信息吗?

1 个答案:

答案 0 :(得分:0)

在vb中非常简单的示例。

私有函数ZPLTest(Ip作为字符串)作为字符串

    Dim client As TcpClient = New TcpClient()
    ZPLTest = "0-Printer on line"
    'check if ip is active
    Try
        client.Connect(Ip, 9100)
    Catch se As SocketException
        ZPLTest = "1-Printer off or network down"
        Exit Function
    End Try

    'send command
    Dim stream As NetworkStream = client.GetStream()
    Dim buffer As Byte() = New Byte(client.ReceiveBufferSize - 1) {}
    Dim sw As StreamWriter = New StreamWriter(stream)
    sw.Write("~HQES")
    sw.Flush()

    'check if stream reader is ok
    Dim i As Integer = 0
    While stream.DataAvailable = False
        Thread.Sleep(10)
        i += 1

        If i = 30 Then
            ZPLTest = "1- Printer not send status"
            Exit Function
        End If
    End While


    'read status printer
    Dim sr As StreamReader = New StreamReader(stream)
    Dim length As Integer = 0
    Thread.Sleep(500)
    While (stream.DataAvailable)
        length += stream.Read(buffer, length, (buffer.Length - length))
    End While

    sr.Close()
    sw.Close()
    client.Close()

    Dim results As String = (Encoding.UTF8.GetString(buffer, 0, length))

    Dim Errore As String = results.Substring(36, 1)

    If Errore = "1" Then ZPLTest = "1-Generic error"

    Dim Media As Integer
    Try
        Media = CInt(results.Substring(54, 1))
        If Media = 1 Then ZPLTest = "1-Error label"
        If Media > 1 Then ZPLTest = "1-Error ribbon"
        If Media > 3 Then ZPLTest = "1-Head open"
    Catch

    End Try

End Function