Sending ASCII via serial port.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Sending ASCII via serial port.

  1. #1
    Join Date
    Aug 2007
    Posts
    8

    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

  2. #2
    Join Date
    Aug 2007
    Posts
    8

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center