Question SerialPort : Encoding received data issue

Thony

New member
Joined
May 18, 2011
Messages
3
Location
Heerenveen, Netherlands, Netherlands
Programming Experience
10+
Hi,

I'm trying to receive a stringvalue sent by a barcodescanner via com1. When I sent ABCD I get ??c?? in my project. Because I tought this was due to to the encoding I tried also the other encoding options (system.text.encoding). Also these don't give ABCD. Strangely enough when I try it by Windows Hyper terminal this show ABCD (meaning the value is sent correctly).

I hope someone can advise me on this.

Br.
Thony

testcode used :
VB.NET:
Public Sub Main()
  Dim mySerialPort As New SerialPort("COM1")
  
  mySerialPort.BaudRate = 9600
  mySerialPort.Parity = Parity.None
  mySerialPort.StopBits = StopBits.One
  mySerialPort.DataBits = 8
  mySerialPort.Handshake = Handshake.None

  AddHandler mySerialPort.DataReceived, AddressOf DataReceivedHandler

  mySerialPort.Open()

  Console.WriteLine("Press any key to continue...")
  Console.WriteLine()
  Console.ReadKey()

  mySerialPort.Close()
End Sub

Private Sub DataReceivedHandler(ByVal sender As Object, ByVal e As SerialDataReceivedEventArgs)
  Dim sp As SerialPort = CType(sender, SerialPort)
  Dim indata As String = sp.ReadExisting()

  Console.WriteLine("Data Received:")
  Console.Write(indata)
End Sub
 
Back
Top