C#如何发送串口指令

来源:百度知道 编辑:UC知道 时间:2024/06/01 09:14:22
C#如何向串口发送指令

楼主自己要去多看看网上的资源

一般比较常用的是SerialPort类
SerialPort的Write方法被重载了很多次,
因此可以直接发送byte[],char[],string等类型数据
下面是最简单的例子,COM1口的参数是系统默认的,你可以在设备管理器中设置

SerialPort sp = new SerialPort()

sp.Open("COM1");

sp.Write("发往串口的数据");

sp.Close();

this.serialPort.write();

using System;
using System.IO.Ports;
using System.Threading;

public class PortChat
{
static bool _continue;
static SerialPort _serialPort;

public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.
_serialPort = new SerialPort();

// Allow the user to set the appropriate properties.
_serialPort.PortName = SetP