获取蓝牙配对Epson打印机的状态

时间:2015-06-10 20:12:53

标签: .net vb.net printing bluetooth epson

问题

我目前正在处理一个需要发送信息以在 EPSON TM-U295 打印机上打印的应用程序。所述打印机启用了蓝牙并与计算机配对。我目前能够发送一个字符串并打印所需的信息。但是,如果打印机中没有纸张,则仍会发送字符串并在空气中打印。

要打印的当前代码

请注意Socket是使用StreamSocket方法的ConnectAsync(),它允许您连接到配对的打印机。

'Print
Public Async Function Write(ByVal StrToSend As String) As Task
    Dim Bytestosend As Byte() = System.Text.Encoding.UTF8.GetBytes(StrToSend)
    Await Socket.OutputStream.WriteAsync(Bytestosend.AsBuffer())
    Await Socket.OutputStream.FlushAsync()
End Function

'Send the command to print
Private Async Sub BtnPrint_Click(sender As Object, e As RoutedEventArgs)
    Await Write(txtTextTosend.Text + vbLf)
End Sub

想要的代码

我希望能够验证纸张是否出现类似于以下情况:

'Send the command to print
Private Async Sub BtnPrint_Click(sender As Object, e As RoutedEventArgs)
    if Status <> PRINTER_PAPER_OUT then
        Await Write(txtTextTosend.Text + vbLf)
    End if
End Sub

R&amp; D

我注意到Documentation(另一个EPSON打印机型号的第10-11页)某个ASB Status,其定义如下:

自动状态返回:这是 TM打印机的功能。这是一种状态 打印机状态更改时自动从打印机发送 (打开或关闭封面,缺纸,打印完成等)。

后面提到(第22页)ASB_RECEIPT_END是一个与没有纸张的打印机链接的常量

More documentation

问题

我们如何使用前面提到的ASB status来了解打印机是否处于“缺纸”状态?

如果ASB status不是获取信息的方式,有人会指出我正确的方向吗?

请注意,我不介意使用C#或VB.NET代码

1 个答案:

答案 0 :(得分:0)

需要做什么

  • 了解并使用ESC / POS命令

  • 激活ASB(GS命令)

  • 激活组分隔符命令Write

    这会将ASB的{​​{1}}和文本的Write分开,以避免打印类似:aTEXTTOPRINT

  • 读取从打印机发回的状态

  • 验证状态是否缺纸

守则

  • 首先需要一个READ函数来读取字节并将其转换为字符串

    Dim bytes(2000) As Byte ' 2000 bytes is random I wasnt sure how many were needed 
    
    Dim result = Await Socket.InputStream.ReadAsync(bytes.AsBuffer, bytes.Length, InputStreamOptions.Partial)
    Dim lgtOfRead = result.Length
    Dim readstr As String = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length)
    Dim retstr As String = readstr.Take(lgtOfRead).ToArray()
    Return retstr
    
  • 其次需要发送上面提到的命令才能工作

    'Send the command to print
    Private Async Sub BtnPrint_Click(sender As Object, e As RoutedEventArgs)
        Dim cmd As Byte() = {29, 97} 'Send the command to enable ASB
        Await _Btcomm.Write(cmd)
    
        cmd = {29} 'Separate the information
        Await _Btcomm.Write(cmd)
    
        Dim strResult As String = Await _Btcomm.Read()
    
        'Verify if the status has a "`" character linked to paper out state
        If Not strResult.Contains("`") Then
            Await _Btcomm.Write(txtTextTosend.Text + vbLf)
        Else
            Dim md As MessageDialog = New MessageDialog("The printer has no paper", "No Paper")
            Await md.ShowAsync()
        End If
    End Sub
    

文档

Some commands

Some more commands

MOAR Commands

http://www.asciitable.com(ASCII表可以更容易地找出命令)