-
September 28th, 2007, 03:26 AM
#1
Sending ASCII via serial port.
I'm trying to send out information over the serial port to an embedded device. The idea is to convert large numbered inputs into a couple of bytes by splitting it then running char() on it.
Then converting it to a string .. therefore sending down 2 bytes as special charactors. The problem happens when sending a char that is valued over 128. For example þ or û anything thats ascii code is bigger than 128.
The string that is being sent over the serial port contains the right numbers i.e
ó| is produced as stored in string11/12 when 62332 however it will not be sent over the serial port.
The receiving code does accept these charactors as it has been tested with hyperterminal.
Code:
// Read in the number from the text box and convert to int
int text1 = System::Convert::ToInt32(this->textBox1->Text);
int text2 = text1 >> 8;
int text3 = text1 & 0x000000FF;
// Bit shift the number into two differet ints
wchar_t w_text11 = unsigned char(text2);
wchar_t w_text12 = unsigned char(text3);
// Convert the number to its ASCII equivilant
String ^s_text11 = System::Convert::ToString(w_text11);
String ^s_text12 = System::Convert::ToString(w_text12);
//Convert the ascii equivilant to a string
//Write strings to serial port
this->serialPort1->Write(s_text11);
this->serialPort1->Write(s_text12);
Anyone know how to send special chars over the serial port ASCII value >128 ?
Thanks.
Paul
-
September 28th, 2007, 04:24 AM
#2
Re: Sending ASCII via serial port.
Hey found the answer in some vb stuff..
The default encoding on the serial port is ASCII up to 127 char sete. the encoding on the serial port needed to be changed..
this->serialPort1->Encoding = System::Text::Encoding::GetEncoding(28591);
That did the job.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|