Chapter 9
A receiving computer using ASCIIEncoding will display “?” for each received
byte greater than 7Fh received:
??
Another option is to use UTF-16 and transmit and receive all characters as
16-bit code units:
Dim utf16 As New System.Text.UnicodeEncoding()
myComPort.Encoding = utf16
System.Text.UnicodeEncoding utf16 = new System.Text.UnicodeEncoding();
myComPort.Encoding = utf16;
To send the copyright symbol, a transmitting computer using UTF-16 encod-
ing sends the bytes A9h 00h, and the receiving computer stores the bytes as the
character 00A9h. The down side is that data takes twice as long to transmit and
a receiving computer that uses 8-bit characters will have to convert the received
data. Note that the UTF-16 encoding property is called UnicodeEncoding (not
UTF16Encoding).
/
'>
Stream objects can represent a source or destination for a series of bytes. The
source or destination can be a storage medium such as a file, memory, or a con-
nection to a device such as a COM port (including virtual COM ports) or
TCP/IP socket. The Stream class provides methods for reading and writing to
stream objects.
A generic Stream object can read and write bytes. Objects created using auxil-
iary stream classes support reading and writing bytes as well as other data types.
SerialPort objects can use the auxialiary BinaryReader and BinaryWriter classes
to read and write numeric data and text and the auxiliary StreamReader and
StreamWriter classes to read and write text. Closing a SerialPort object disposes
of the port’s Stream object.
The stream classes are in the System.IO namespace:
Imports System.IO
using System.IO;