Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

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

I have a string "Hello World".

I use

C++
//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
Updated 18-May-13 21:38pm
v3
Comments
Lim Chong Han 19-May-13 5:59am    
Can someone help me? :(

1 solution

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[^]).
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900