串行端口模式C#

本文关键字:模式 串行端口 | 更新日期: 2023-09-27 18:22:25

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

    mode COM3 19200, n, 8, 1, p

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

    copy /b myFile.plt COM3

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

感谢:)

串行端口模式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());
        }
    }
}
​