|
自己写了一段上位机串口测试程序,wifi那边用串口助手,上位机这边发送数据,串口助手可以接收到;可是串口助手发送数据,上位机这边接受不到,求高手帮忙……
private void NetSeriesThread()
{
byte[] read = new byte[1024];
byte[] write = new byte[1024];
//创建服务器
TcpClient tcpc = new TcpClient();
//请求连接服务器
int iPort = System.Int32.Parse(TB_PORT.Text);
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse(TB_IP.Text), iPort);
tcpc.Connect(ipep);
//建立网络数据流
NetworkStream s = tcpc.GetStream();
while(true)
{
//发送信息
//write[0] = 0xfe;
//write[1] = 0x01;
//write[2] = 0x01;
//write[3] = 0x02;
//write[4] = 0x16;
//s.Write(write, 0, write.Length);
//获取流(接收信息)
int bytes = s.Read(read, 0, read.Length);
string strInf = Encoding.ASCII.GetString(read);
MessageBox.Show(strInf);
}
s.Close();
tcpc.Close();
} |
|