我的数据来自串口,我想将它存储在FIFO缓冲区中,然后再通过TCP / IP发送到客户端。我该怎么办?
答案 0 :(得分:0)
为什么需要FIFO?您可以从Stream
和SerialPort
获得TcpClient
。只需将一个复制到另一个:
IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse("128.128.128.128"), 8888);
using(TcpClient client = new TcpClient())
using(SerialPort sp = new SerialPort("COM1"))
{
client.Connect(endpoint);
sp.Open();
Stream clientStream = client.GetStream();
Stream serialStream = sp.BaseStream;
sp.BaseStream.CopyTo(clientStream);
}