SerialPort.Write with byte[] buffer does not encode characters
Summary
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater than 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.
This statement in the remarks section of the prototype Write (byte[] buffer, int offset, int count); is false and should be removed.
The byte[] buffer will not be encoded!
There has been some confusion: https://stackoverflow.com/questions/32864198/can-i-use-serialport-write-to-send-byte-array
Tagging subscribers to this area: @carlossanlop See info in area-owners.md if you want to be subscribed.
Issue Details
Summary
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater than 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.
This statement in the remarks section of the prototype Write (byte[] buffer, int offset, int count); is false and should be removed.
The byte[] buffer will not be encoded!
| Author: | 5andr0 |
|---|---|
| Assignees: | - |
| Labels: |
|
| Milestone: | - |
Docs Build status updates of commit d4d9188:
:white_check_mark: Validation status: passed
| File | Status | Preview URL | Details |
|---|---|---|---|
| xml/System.IO.Ports/SerialPort.xml | :white_check_mark:Succeeded | View |
For more details, please refer to the build report.
Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.
For any questions, please:
- Try searching the docs.microsoft.com contributor guides
- Post your question in the Docs support channel