Knowledge Base Ask Cody Resources



 
I am using the Distinct VIT VT220 Component to connect to a host via a third-party library (e.g. a Serial Port library) and it seems escape sequences are not processed correctly. How can I correct this?
The problem is that the data from the serial port should be passed to the
VT220 component without any changes, i.e. in binary format. When you read
from the port using ReadExisting, .Net tries to parse the incoming data and
thus the escape sequences are lost.

Use the Read method instead to read into a Byte[] (not Char[] !) array, or
ReadByte to read binary data from the port. Do not use any text-reading
methods on the serial port since that would corrupt the data.

You can then convert the read data into a String using Chr() function (this
way the escape sequences won't be lost) and supply the resulting string to
the component. Here's how the DataReceived event may be handled in this scenario:

Private Sub SerialPort1_DataReceived(ByVal sender As System.Object, ByVal e
As System.IO.Ports.SerialDataReceivedEventArgs) Handles
SerialPort1.DataReceived
Dim a() As Byte = {}
Dim dataSize As Integer
Dim s As String
Dim i As Integer


dataSize = SerialPort1.BytesToRead

Array.Resize(a, dataSize)

SerialPort1.Read(a, 0, dataSize)

s = ""
For i = 0 To a.Length - 1
s = s + Chr(a(i))
Next

AxVT2201.WriteData = s

End Sub






12/22/2024   Legal notices | PRIVACY Policy |