dotnet-api-docs icon indicating copy to clipboard operation
dotnet-api-docs copied to clipboard

SerialPort.Write with byte[] buffer does not encode characters

Open 5andr0 opened this issue 4 years ago • 2 comments

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

5andr0 avatar Jan 10 '22 17:01 5andr0

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:

area-System.IO

Milestone: -

ghost avatar Jan 10 '22 17:01 ghost

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:

opbld30 avatar Jan 10 '22 17:01 opbld30