VB6 and VB.NET Serial (COM1) data error

35 pts.
Tags:
.NET
COM1
RS232
Serial ports
VB 6.0
VB.NET
Hello, I'm new to .NET. I have an application that is running in VB6. It sends 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 the source code is the same. VB6 source code: MSComm1.CommPort = 1 MSComm1.Settings = "9600,O,8,1" MSComm1.PortOpen = True MSComm1.Output = Chr(&H2B) & _ Chr(&H4) & _ Chr(&H3) & _ Chr(&HE8) & _ Chr(&H0) & _ Chr(&H2) & _ Chr(&HF6) & _ Chr(&H71) MSComm1.PortOpen = False The analyzer gets the following string in hex: 2B 04 03 E8 00 02 F6 71 VB.NET source code: Dim Port As SerialPort = New SerialPort("COM1", 9600, Parity.Odd, 8, StopBits.One) Port.Open() 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) & _ System.Convert.ToChar(&H71)) Port.Close() The analyzer gets the following string in hex: 2B 04 03 0F 00 02 3F 71 Why is there a difference in the string? Please help me correct it... Thanks

Software/Hardware used:
VB.NET 2010

Answer Wiki

Thanks. We'll let you know when a new response is added.

I found something interesting.

when I convert a number using System.Convert.ToChar(X) and sends it through serial the X can only be hex:0 to hex:3F if I want to get the correct value from the other side. Any value greater than hex:3F will not be hex:3F.

for example if I send
hex:64 you will get hex:3F
send hex:E8 you will get hex:3F

It seems like it max out with a 6 bit register value,
Please help me correct this mess …

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • BCP
    From: http://msdn.microsoft.com/en-us/library/y2sxhat8.aspx By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater then 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.
    65 pointsBadges:
    report
  • Aattanayake
    Dear BCP, You are right on the money. I changed the encoding and all working like before. Thanks a million ....
    35 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following