SerialPort.Write 方法

定义

将数据写入串行端口输出缓冲区。

重载

Write(String)

将指定的字符串写入串行端口。

Write(Byte[], Int32, Int32)

使用缓冲区中的数据将指定数量的字节写入串行端口。

Write(Char[], Int32, Int32)

使用缓冲区中的数据将指定数量的字符写入串行端口。

Write(String)

Source:
SerialPort.cs
Source:
SerialPort.cs
Source:
SerialPort.cs

将指定的字符串写入串行端口。

public:
 void Write(System::String ^ text);
public void Write (string text);
member this.Write : string -> unit
Public Sub Write (text As String)

参数

text
String

输出字符串。

例外

指定的端口未打开。

textnull

该操作未在超时时间到期之前完成。

注解

如果要将字符串作为输出写入串行端口,请使用此方法。

如果输出缓冲区中有太多字节并且Handshake设置为 ,则 SerialPort 对象可能会在等待设备准备好接受更多数据时引发 TimeoutExceptionXOnXOff

默认情况下, SerialPort 使用 ASCIIEncoding 对字符进行编码。 ASCIIEncoding 将所有大于 127 的字符编码为 (字符) 63 或“?”。 若要支持该范围中的其他字符,请将 设置为 EncodingUTF8EncodingUTF32EncodingUnicodeEncoding

适用于

Write(Byte[], Int32, Int32)

Source:
SerialPort.cs
Source:
SerialPort.cs
Source:
SerialPort.cs

使用缓冲区中的数据将指定数量的字节写入串行端口。

public:
 void Write(cli::array <System::Byte> ^ buffer, int offset, int count);
public void Write (byte[] buffer, int offset, int count);
member this.Write : byte[] * int * int -> unit
Public Sub Write (buffer As Byte(), offset As Integer, count As Integer)

参数

buffer
Byte[]

包含要写入端口的数据的字节数组。

offset
Int32

buffer 参数中从零开始的字节偏移量,从此处开始将字节复制到端口。

count
Int32

要写入的字节数。

例外

传递的 buffernull

指定的端口未打开。

offsetcount 参数超出了所传递的 buffer 的有效区域。 offsetcount 小于零。

offset 加上 count 大于 buffer 的长度。

该操作未在超时时间到期之前完成。

注解

如果要写入字节缓冲区以创建到串行端口的输出,请使用此方法。

如果输出缓冲区中有太多字节并且Handshake设置为 ,则 SerialPort 对象可能会在等待设备准备好接受更多数据时引发 TimeoutExceptionXOnXOff

适用于

Write(Char[], Int32, Int32)

Source:
SerialPort.cs
Source:
SerialPort.cs
Source:
SerialPort.cs

使用缓冲区中的数据将指定数量的字符写入串行端口。

public:
 void Write(cli::array <char> ^ buffer, int offset, int count);
public void Write (char[] buffer, int offset, int count);
member this.Write : char[] * int * int -> unit
Public Sub Write (buffer As Char(), offset As Integer, count As Integer)

参数

buffer
Char[]

包含要写入端口的数据的字符数组。

offset
Int32

buffer 参数中从零开始的字节偏移量,从此处开始将字节复制到端口。

count
Int32

要写入的字符数。

例外

传递的 buffernull

指定的端口未打开。

offsetcount 参数超出了所传递的 buffer 的有效区域。 offsetcount 小于零。

offset 加上 count 大于 buffer 的长度。

该操作未在超时时间到期之前完成。

注解

如果要写入字符缓冲区以创建到串行端口的输出,请使用此方法。

如果输出缓冲区中有太多字节并且Handshake设置为 ,则 SerialPort 对象可能会在等待设备准备好接受更多数据时引发 TimeoutExceptionXOnXOff

默认情况下, SerialPort 使用 ASCIIEncoding 对字符进行编码。 ASCIIEncoding 将所有大于 127 的字符编码为 (字符) 63 或“?”。 若要支持该范围中的其他字符,请将 设置为 EncodingUTF8EncodingUTF32EncodingUnicodeEncoding

适用于