我正在尝试将一个字符串发送给卡片编码器以设置卡片。
如果我使用特定软件(如Putty)通过tcp / ip发送消息,则PMS(卡软件)的日志文件会注册该事务。
我正在尝试通过VB.Net发送字符串,但是TcpClient
没有回答,并且PMS的日志文件没有注册任何内容。
有什么建议吗?
这是我使用的代码:
Public Function invia_stringa_tcpip() As String
Dim rr As String
' var ind_tcpip porta_tcpip, stri stringa da inviare
ind_tcpip = "192.168.1.3"
porta_tcpip = 3015
stri = "CCA;EA1;GR101;CO201803021200;AM1;"
Dim telnetclient As New System.Net.Sockets.TcpClient()
telnetclient.Connect(ind_tcpip, porta_tcpip)
Dim byt_to_send() As Byte = System.Text.Encoding.ASCII.GetBytes(stri)
telnetclient.Client.Send(byt_to_send, 0, byt_to_send.Length, SocketFlags.None)
If telnetclient.Client.Available < 0 Then 'controlla se il client tcp risponde
Dim byt_to_receive(telnetclient.Available - 1) As Byte
telnetclient.Client.Receive(byt_to_receive, 0, byt_to_receive.Length, SocketFlags.None)
rr = System.Text.Encoding.ASCII.GetString(byt_to_receive)
Return rr
End If
End Function