2023年8月31日 星期四

Printing to a network Thermal printer

         Public Sub SendViaTCP(ByVal whatIP As String, ByVal whatPort As Integer, ByVal whatToSend As String)

            Dim tcpSender As TcpClient = New TcpClient()

            tcpSender.SendBufferSize = 4096

            tcpSender.Connect(whatIP, whatPort)

            If tcpSender.Connected = False Then

                MessageBox.Show("Not connected")

                tcpSender.Close()

                Exit Sub

            End If


            Dim nStream As NetworkStream = tcpSender.GetStream()

            If nStream.CanWrite = True Then

                Dim SendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(whatToSend)

                nStream.Write(SendBytes, 0, SendBytes.Length)

                nStream.Flush()

            End If

            System.Threading.Thread.Sleep(500)


            nStream.Close()

            tcpSender.Close()

        End Sub


沒有留言:

張貼留言