Hi All,
I have an application which connects to a networked barcode printer over a socket connection. Everything seemed to work fine until the customer complained that if they turned the power to the printer off, the connection would not reestablish. So we made some modifications, but alas I still can not get anything to work well. This is my code below. It is a little hacked apart, but what seems to happen is that the first label I try to print after the printer has been shut down fails. But the second one works. It also takes a long time to fail the first time. Any ideas?
I have an application which connects to a networked barcode printer over a socket connection. Everything seemed to work fine until the customer complained that if they turned the power to the printer off, the connection would not reestablish. So we made some modifications, but alas I still can not get anything to work well. This is my code below. It is a little hacked apart, but what seems to happen is that the first label I try to print after the printer has been shut down fails. But the second one works. It also takes a long time to fail the first time. Any ideas?
VB.NET:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim input As String = TextBox1.Text
Dim printerconnection As New System.Net.Sockets.TcpClient()
Try
printerconnection.Connect("10.0.0.2", 9100)
Dim barcode As String
barcode = FormatBarcode(input)
Dim sendbytes As [Byte]() = Encoding.ASCII.GetBytes(barcode)
Dim printersend As NetworkStream = printerconnection.GetStream()
printersend.Write(sendbytes, 0, sendbytes.Length)
printerconnection.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error in Button")
End Try
End Sub
Last edited by a moderator: