Welcome to the new platform of Programmers Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use it's exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
Problem with System.Convert.ToChar
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?