我目前正在处理一个需要发送信息以在 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
我注意到Documentation(另一个EPSON打印机型号的第10-11页)某个ASB Status
,其定义如下:
自动状态返回:这是 TM打印机的功能。这是一种状态 打印机状态更改时自动从打印机发送 (打开或关闭封面,缺纸,打印完成等)。
后面提到(第22页)ASB_RECEIPT_END
是一个与没有纸张的打印机链接的常量
我们如何使用前面提到的ASB status
来了解打印机是否处于“缺纸”状态?
如果ASB status
不是获取信息的方式,有人会指出我正确的方向吗?
请注意,我不介意使用C#或VB.NET代码
答案 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
http://www.asciitable.com(ASCII表可以更容易地找出命令)