我试图通过以太网在VB.NET中的热敏打印机上打印

时间:2013-04-17 15:13:37

标签: vb.net printing ethernet

我正尝试在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()

1 个答案:

答案 0 :(得分:0)

尝试将VbCrLf添加到SendBytes:

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

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