Click here to Skip to main content
13,042,421 members (137,346 online)
Rate this:
Please Sign up or sign in to vote.
Hi all

I face a problem to sending/receiving data from serial port.

I have a string "Hello World".

I use

//at sending part
array<byte>^ sbyte = Encoding::ASCII -> GetBytes("€‚ƒ‰Š");
this -> serialPort1 -> Write(sbyte, 0, sbyte -> Length);
//receiving part
String^ cipher = this -> serialPort1 -> ReadLine;
array<byte>^ rbyte = this -> serialPort1 -> Read(cipher, 0, cipher -> Length);

From above code, i cant receive any byte.

the main thing i would like to do is
1) Get Byte from a String which contain extended ASCII.
2) send in byte form
3) receive in byte form

I discovered if i straight send extended ASCII in string form, the receiver can't determine it and come out "?????".
Got any other way to make sure the extended ASCII can send and receive properly?

Thanks in advance who can help me...
Posted 18-May-13 21:35pm
Updated 18-May-13 21:38pm
Lim Chong Han 19-May-13 5:59am
Can someone help me? :(

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You are using Encoding::ASCII[^]. This will replace all non ASCII characters (highest bit set) by a question mark character.

You may send the characters as they are without performing any conversion. If your data use some kind of text encoding, sender and receiver must use the same encoding. Alternatively convert the text before sending to an encoding defined by you or provide the encoding separately so that the receiver can convert it if necessary.

The term 'Extended ASCII' is really misleading and should be avoided (see also in the Wikipedia[^]).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 19 May 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100