Problem with System.Convert.ToChar - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Problem with System.Convert.ToChar

aattanayakeaattanayake Posts: 2Member
I'm new to .NET. I have an application that is running in VB6. It sends some text through COM1 port to another device.

When I converted the VB6 code to .NET the string it sends out is different! I have tried so many things and don't know what to do. I used a serial data analyzer and found the two strings are different even the source code is the same. Seems like the problem is in the System.Convert.ToChar method. It handles only 8 bit values and anything bigger converts incorrectly.

VB.NET source code:
Dim Port As SerialPort = New SerialPort("COM1", 9600, Parity.Odd, 8, StopBits.One)
Port.Write(System.Convert.ToChar(&H2B) & _
System.Convert.ToChar(&H4) & _
System.Convert.ToChar(&H3) & _
System.Convert.ToChar(&HE8) & _
System.Convert.ToChar(&H0) & _
System.Convert.ToChar(&H2) & _
System.Convert.ToChar(&HF6) & _

The analyzer gets the following string in hex: 2B 04 03 0F 00 02 3F 71

Is there a work around this?



Sign In or Register to comment.