Serial Port Complete - Latest Microcontroller projects

(lily) #1
Using .NET’s SerialPort Class

The Write and Read methods can also write and read Chars and Char arrays.

 ‘ Write a Char.


Dim valueToWrite As Char

valueToWrite = CChar("A")
binaryWriter1.Write(valueToWrite)

' Read a Char.

Dim receivedData As Integer

receivedData = binaryReader1.Read
Console.WriteLine(ChrW(receivedData))

' Write an array of Chars.

Dim valueToWrite(1) As Char

valueToWrite(0) = CChar("O")
valueToWrite(1) = CChar("K")

binaryWriter1.Write(valueToWrite, 0, 2)

' Read Chars into an array.

Dim receivedData(1) As Char

binaryReader1.Read(receivedData, 0, 2)
Console.WriteLine(receivedData)
Free download pdf