Click here to Skip to main content
Rate this: bad
good
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 22:35pm
Edited 18-May-13 22:38pm
v3
Comments
Lim Chong Han at 19-May-13 5:59am
   
Can someone help me? :(

1 solution

Rate this: bad
good
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[^]).
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 299
1 Maciej Los 295
2 Sergey Alexandrovich Kryukov 205
3 Aajmot Sk 202
4 Sinisa Hajnal 166
0 OriginalGriff 7,760
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,785


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 19 May 2013
Copyright © CodeProject, 1999-2014
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