Chapter 9
The default text encoding for BinaryReader and BinaryWriter is UTF8. Con-
structors can specify a different encoding method for the streams:
Friend binaryReader2 As BinaryReader
Friend binaryWriter2 As BinaryWriter
Dim serialPortStream As Stream
Dim utf16 As New System.Text.UnicodeEncoding
' Get the port's Stream object.
serialPortStream = myComPort.BaseStream
' Use the Stream object to create BinaryReader and BinaryWriter objects.
binaryReader2 = New BinaryReader(serialPortStream, utf16)
binaryWriter2 = New BinaryWriter(serialPortStream, utf16)
internal BinaryReader binaryReader2;
internal BinaryWriter binaryWriter2;
System.Text.UnicodeEncoding utf16 = new System.Text.UnicodeEncoding();
Stream serialPortStream = null;
// Get the port's Stream object.
serialPortStream = myComPort.BaseStream;
// Use the Stream object to create BinaryReader and BinaryWriter objects.
binaryReader2 = new BinaryReader( serialPortStream,utf16 );
binaryWriter2 = new BinaryWriter( serialPortStream,utf16 );
The PeekChar method, which returns the next value in a stream without
removing the value from the stream, isn’t supported by SerialPort BinaryReader
objects.
!
!-
The StreamReader and StreamWriter classes support reading and writing text
using a specified Unicode encoding. The object’s Encoding property determines
the encoding method. The default encoding is UTF-8. Unlike BinaryReader
and BinaryWriter, StreamReader and StreamWriter don’t use length prefixes.