Problems with chr(&HC0) in vb.net

When I send chr(&HCO) out the serial port, I see 0x3F.  This does not happen when I send chr(&H7F) out the port on any other hex value less than 0x7F.  It appears to be an overflow issue.  Can you help?
gmcorbeSoftware DeveloperAsked:
Who is Participating?
 
Bob LearnedConnect With a Mentor Commented:
What code page are you using?  United States is typically 1252.

port.Encoding = System.Text.Encoding.GetEncoding(1252)
0
 
Bob LearnedCommented:
Try sending ChrW(&HC0), instead of Chr.  That would be the Unicode representation for the character, instead of the ANSI representation (&H7F and lower).
0
 
gmcorbeSoftware DeveloperAuthor Commented:
Hi,
Thanks for responding.  I already tried that.  I believe you are correct in that it's an encoding issue with the serial port in that if I send anything beyond the normal ASCII data set (0-0x3F or 0-127), it freaks and sends out the maximum 7-bit value of 0x3F.  I'm studying encoding for a serial port now.  THANKS.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
Bob LearnedCommented:
Oh, yeah, it uses AsciiEncoding by default (d'oh).

 port.Encoding = System.Text.Encoding.Default
0
 
gmcorbeSoftware DeveloperAuthor Commented:
We're getting closer.

If I use port.Encoding = System.Text.UnicodeEncoding, I see a 0xC0 0x00 out the serial port.
System.Text..UTF7, System.Text.UTF8 did not work either.

Thanks...
0
 
gmcorbeSoftware DeveloperAuthor Commented:
IT WORKED.  THANKS.  I originally used the encoding described in blog
http://blogs.msdn.com/bclteam/archive/2006/05/26/608377.aspx which indicated to use mySerialPort.Encoding = Encoding.GetEncoding(28591);  which is Western European (ISO) encoding.  This code page worked for the 0xC0 char but failed with other characters.  Your code page is working for all characters!!!!!!!!!!  NOTE that the URL blog is good reading anyway.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.