Link to home
Start Free TrialLog in
Avatar of gmcorbe
gmcorbeFlag for United States of America

asked on

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?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Try sending ChrW(&HC0), instead of Chr.  That would be the Unicode representation for the character, instead of the ANSI representation (&H7F and lower).
Avatar of gmcorbe

ASKER

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.
Oh, yeah, it uses AsciiEncoding by default (d'oh).

 port.Encoding = System.Text.Encoding.Default
Avatar of gmcorbe

ASKER

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...
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gmcorbe

ASKER

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.