C# 从C中的COM端口读取#
可能重复:C# 从C中的COM端口读取#,c#,serial-port,C#,Serial Port,可能重复: 如何在C#中从COM端口读取数据?更具体地说,我需要读取可变长度的数据。如果可能,请提供一个例子。提前感谢您需要使用System.IO.Ports.SerialPort类或System.IO.Ports命名空间 这方面有一些例子和更多信息 以下是一个例子: // This is a new namespace in .NET 2.0 // that contains the SerialPort class using System.IO.Ports; priv
如何在C#中从COM端口读取数据?更具体地说,我需要读取可变长度的数据。如果可能,请提供一个例子。提前感谢您需要使用
System.IO.Ports.SerialPort
类或System.IO.Ports
命名空间
这方面有一些例子和更多信息
以下是一个例子:
// This is a new namespace in .NET 2.0
// that contains the SerialPort class using System.IO.Ports;
private static void SendSampleData()
{
// Instantiate the communications
// port with some basic settings
SerialPort port = new SerialPort(
"COM1", 9600, Parity.None, 8, StopBits.One);
// Open the port for communications
port.Open();
// Write a string
port.Write("Hello World");
// Write a set of bytes
port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);
// Close the port
port.Close(); }
您需要使用
System.IO.Ports.SerialPort
类或System.IO.Ports
命名空间
这方面有一些例子和更多信息
以下是一个例子:
// This is a new namespace in .NET 2.0
// that contains the SerialPort class using System.IO.Ports;
private static void SendSampleData()
{
// Instantiate the communications
// port with some basic settings
SerialPort port = new SerialPort(
"COM1", 9600, Parity.None, 8, StopBits.One);
// Open the port for communications
port.Open();
// Write a string
port.Write("Hello World");
// Write a set of bytes
port.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);
// Close the port
port.Close(); }
你能详细说明你想做什么吗?这些数据是如何发送给你的……你在这个网站上搜索过吗?这个问题已经提过很多次了。明白了。你能详细说明你想做什么吗?这些数据是如何发送给你的……你在这个网站上搜索过吗?这个问题已经提过很多次了。请参阅。这显示如何书写,而问题询问如何阅读。这显示如何书写,而问题询问如何阅读