0

我正在尝试通过以太网在 VB.NET 中的热敏打印机上进行打印。在互联网上搜索,我发现了这个程序,它显然存储在内存打印中,因为打印机什么都不做。然后,如果我从控制面板发出测试页,它会打印我在上面打印的内容 + 测试页。你在日常生活中错过了什么吗?,非常感谢你能给我的帮助。

Dim cImpresion As String = Chr(27) & Chr(77) & Chr(64)
Dim tcpSender As TcpClient = New TcpClient()

tcpSender.SendBufferSize = 4096
tcpSender.Connect(whatIP, whatPort)
If tcpSender.Connected = False Then
  tcpSender.Close()
  Exit Sub
End If

Dim nStream As NetworkStream = tcpSender.GetStream()
If nStream.CanWrite = True Then
  Dim SendBytes As Byte
  SendBytes = System.Text.Encoding.ASCII.GetBytes("the text I want to print")
  nStream.Write(SendBytes, 0, SendBytes.Length)
  nStream.Flush()
End If

nStream.Close()
tcpSender.Close()
4

1 回答 1

0

尝试将 VbCrLf 添加到 SendBytes:

SendBytes = System.Text.Encoding.ASCII.GetBytes("the text I want to print")
SendBytes = SendBytes + vbCrLf

或使用 nStream.WriteLine 而不是 nStream.Write

于 2013-04-17T16:43:26.543 回答