SerialPort.Write 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将数据写入串行端口输出缓冲区。
重载
| 名称 | 说明 |
|---|---|
| Write(String) |
将指定的字符串写入串行端口。 |
| Write(Byte[], Int32, Int32) |
使用缓冲区中的数据将指定的字节数写入串行端口。 |
| Write(Char[], Int32, Int32) |
使用缓冲区中的数据将指定的字符数写入串行端口。 |
Write(String)
- Source:
- SerialPort.cs
- 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
输出的字符串。
例外
指定的端口未打开。
text 是 null。
该操作在超时期限结束之前未完成。
注解
如果要将字符串作为输出写入串行端口,请使用此方法。
如果输出缓冲区中存在过多的字节,并且 Handshake 设置为 XOnXOff 该对象,则 SerialPort 当对象等待设备准备好接受更多数据时可能会引发 TimeoutException 该对象。
默认情况下, SerialPort 用于 ASCIIEncoding 对字符进行编码。 ASCIIEncoding 将所有大于 127 的字符编码为 (char)63 或 “?”。 若要支持该范围中的其他字符,请设置为EncodingUTF8Encoding或 UTF32EncodingUnicodeEncoding。
适用于
Write(Byte[], Int32, Int32)
- Source:
- SerialPort.cs
- 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
要写入的字节数。
例外
传递 buffer 的为 null.
指定的端口未打开。
offset或count参数位于所传递的有效区域buffer之外。 要么offsetcount小于零。
offset 加 count 号大于长度 buffer。
该操作在超时期限结束之前未完成。
注解
如果要写入字节缓冲区以创建到串行端口的输出,请使用此方法。
如果输出缓冲区中存在过多的字节,并且 Handshake 设置为 XOnXOff 该对象,则 SerialPort 当对象等待设备准备好接受更多数据时可能会引发 TimeoutException 该对象。
适用于
Write(Char[], Int32, Int32)
- Source:
- SerialPort.cs
- 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
要写入的字符数。
例外
传递 buffer 的为 null.
指定的端口未打开。
offset或count参数位于所传递的有效区域buffer之外。 要么offsetcount小于零。
offset 加 count 号大于长度 buffer。
该操作在超时期限结束之前未完成。
注解
如果要写入字符缓冲区以创建串行端口的输出,请使用此方法。
如果输出缓冲区中存在过多的字节,并且 Handshake 设置为 XOnXOff 该对象,则 SerialPort 当对象等待设备准备好接受更多数据时可能会引发 TimeoutException 该对象。
默认情况下, SerialPort 用于 ASCIIEncoding 对字符进行编码。 ASCIIEncoding 将所有大于 127 的字符编码为 (char)63 或 “?”。 若要支持该范围中的其他字符,请设置为EncodingUTF8Encoding或 UTF32EncodingUnicodeEncoding。