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 189 | Next

Jan Axelson

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


! 
The .NET Framework supports many methods for reading and writing to
COM ports. An application that sends a text command and waits for a response
will likely use a different method than an application that is sending a large file
of object code.
The SerialPort class provides methods for reading and writing to ports. Applications
can also use a SerialPort object??™s BaseStream property to obtain BinaryReader,
BinaryWriter, StreamReader, and StreamWriter objects and use their
methods to access a port. Table 9-1 and Table 9-2 summarize methods for reading
and writing to SerialPort objects.
A basic data type for COM-port data is the byte array. An application can transfer
any kind of data in byte arrays. The COM-port software makes no assumptions
about the meaning of the data or how the receiving computer will use the
data. An application can encode data before placing it in a byte array and writing
the array to the port. The receiving computer can decode the received data
as needed.
Chapter 9
164
For applications that transfer text, numeric data other than bytes, and logical
values, the SerialPort class includes methods that handle the encoding and
decoding of these data types. For example, an application that wants to send the
text ???CMD1??? followed by a LF character could store the character codes in a
byte array and write the array to a port:
 Dim dataToSend(4) As Byte
dataToSend(0) = Asc("C")
dataToSend(1) = Asc("M")
dataToSend(2) = Asc("D")
dataToSend(3) = Asc("1")
dataToSend(4) = 10
myComPort.


Pages:
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201