串行端口模式 C#

Serial Port Mode C#

我正在尝试在 C# 上配置串行端口以将二进制文件发送到我的端口。通常,我会在 Windows 终端中写入:

    mode COM3 19200, n, 8, 1, p

然后,要发送我的文件,我会写:

    copy /b myFile.plt COM3

如何在 C# 上执行这些指令?

谢谢:)

试试这个

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.IO.Ports;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SerialPort port = new SerialPort("COM3", 19200, Parity.None, 8, StopBits.One);

            Byte[] data =  File.ReadAllBytes("myFile.plt");

            port.Write(data, 0, data.Count());

        }
    }
}
​