如何实现FIFO缓冲区?

时间:2014-06-25 21:10:28

标签: c#

我的数据来自串口,我想将它存储在FIFO缓冲区中,然后再通过TCP / IP发送到客户端。我该怎么办?

1 个答案:

答案 0 :(得分:0)

为什么需要FIFO?您可以从StreamSerialPort获得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);
}
相关问题