Difficulty parsing serial Communication data using System.IO.Ports.SerialPort Class

  • Thread starter Thread starter FarStarz9
  • Start date Start date
F

FarStarz9

Guest
I am communicating to a PLC via serial port using the System.IO.Ports.SerialPort class. The data I am receiving looks like this ? O??? ?????l? ??????????? +?
I believe this is because VB is having trouble parsing the data because the Character values of some of these values are outside the limit of ASCII.
Please give any suggestions you might have on how to read this data properly. I have attached the part of the code where I created the serial port object and where I am reading the read buffer.

' Set up the Communications Port
'Set up serial communication - COM1-port name, 19200 baud rate, no parity, 8 - data bit
' 1 - stop bit
serialPLCVar = New SerialPort("COM1", 19200, Parity.None, 8, 1)

'inform the system that data exist in input buffer when 1 bit exist
serialPLCVar.ReceivedBytesThreshold = 1

AddHandler serialPLCVar.DataReceived, AddressOf SerialPLCVar_DataRecieved
txtCurPortNum.Text = serialPLCVar.PortName


Private Sub SerialPLCVar_DataRecieved(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
Console.WriteLine("Start SerialPLCVar_DataRecieved")

Dim D As Integer
s1 &= serialPLCVar.ReadExisting()
's1 &= Chr(serialPLCVar.ReadExisting)
Console.WriteLine(System.DateTime.Now & "Return from PLC: " & s1.ToString)

Continue reading...
 
Back
Top