2013-04-17 151 views
0

我想通过以太网打印在VB.NET中的热敏打印机上。在互联网上搜索,我发现这个程序,显然存储在内存打印,因为打印机什么都不做。然后,如果我从控制面板发布测试页面,它会打印我在+测试页面上打印的内容。你会错过例行公事吗?,非常感谢你能给我的帮助。我正尝试在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() 

回答

0

尝试增加VbCrLf到SendBytes:

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

或者使用nStream.WriteLine代替nStream.Write

+0

非常感谢您! – matus