SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 201 | Next

Jan Axelson

"Serial Port Complete: COM Ports, USB Virtual COM Ports, and Ports for Embedded Systems"

IO
 using System.IO;
Using .NET??™s SerialPort Class
177
6 5   6 5- 
The BinaryReader and BinaryWriter classes support reading and writing data in
a variety of formats, including bytes and other numeric types, Boolean data,
Chars, and length-prefixed strings.
An application uses the SerialPort object??™s BaseStream property to obtain a
Stream object and then uses the object to create BinaryReader and Binary-
Writer objects:
 Friend binaryReader1 As BinaryReader
Friend binaryWriter1 As BinaryWriter
Dim serialPortStream As Stream
' Get the port's Stream object.
serialPortStream = myComPort.BaseStream
' Use the Stream object to create BinaryReader and BinaryWriter objects.
binaryReader1 = New BinaryReader(serialPortStream)
binaryWriter1 = New BinaryWriter(serialPortStream)
 internal BinaryReader binaryReader1;
internal BinaryWriter binaryWriter1;
Stream serialPortStream = null;
// Get the port's Stream object.
serialPortStream = myComPort.BaseStream;
// Use the Stream object to create BinaryReader and BinaryWriter objects.
binaryReader1 = new BinaryReader( serialPortStream );
binaryWriter1 = new BinaryWriter( serialPortStream );
The Write method can write a byte to a port:
 Dim dataToWrite As Byte
dataToWrite = 65
binaryWriter1.Write(dataToWrite)
Chapter 9
178
 byte dataToWrite;
dataToWrite = 65;
binaryWriter1.


Pages:
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213