.net 获取蓝牙配对Epson打印机的状态 问题
我目前正在开发一个应用程序,该应用程序需要发送信息,以便在爱普生TM-U295打印机上打印。所述打印机已启用蓝牙功能,并与计算机配对。我目前能够发送一个字符串到它和打印所需的信息。但是,如果打印机中没有纸张,字符串仍会在稀薄的空气中发送和打印 要打印的当前代码 请注意,.net 获取蓝牙配对Epson打印机的状态 问题,.net,vb.net,printing,bluetooth,epson,.net,Vb.net,Printing,Bluetooth,Epson,我目前正在开发一个应用程序,该应用程序需要发送信息,以便在爱普生TM-U295打印机上打印。所述打印机已启用蓝牙功能,并与计算机配对。我目前能够发送一个字符串到它和打印所需的信息。但是,如果打印机中没有纸张,字符串仍会在稀薄的空气中发送和打印 要打印的当前代码 请注意,Socket是一种StreamSocket,使用方法ConnectAsync()可连接到配对打印机 'Print Public Async Function Write(ByVal StrToSend As String) As
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
“发送打印命令”
专用异步子BtnPrint\u单击(发送方作为对象,e作为路由EventArgs)
如果状态打印机出纸,则
等待写入(txtexttosend.Text+vbLf)
如果结束
端接头
研发
我注意到(另一款爱普生打印机型号的第10-11页)中存在某种ASB状态
,其定义如下:
自动返回状态:这是TM打印机的一项功能。这是一种状态
打印机状态更改时自动从打印机发送
(打开或关闭封面,用纸,打印完成等)
后面提到(第22页),ASB\u RECEIPT\u END
是一个常数,与没有纸张的打印机相连
问题
我们如何使用前面提到的ASB状态
来了解打印机是否处于“缺纸”状态
如果ASB状态不是获取信息的途径,有人能告诉我正确的方向吗
注意,我不介意C#或VB.NET代码需要做什么
- 了解并使用ESC/POS命令
- 激活ASB(
命令)GS a
- 激活组分隔符命令
这会将GS
ASB的
和文本的Write
分开,避免打印类似以下内容: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表格更容易理解命令)请注意,由于对这种交互非常陌生,(我习惯于简单的表单到表单或表单到SQL Server交互),我发现很难通过文档找到我理解的信息。我偶然发现的其他帖子答案似乎与解决这个问题无关