Click here to Skip to main content
15,948,338 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am having a problem with my program.
I had set my Serial communication to a 4800bps, 8 bits 1 stop bit non parity (already set this parameter in the C++/Cli program and in the external circuit). Well I am trying to send an array of bytes (25 bytes) to my external Circuit (wich is the receptor .This has been set for receiving 25 bytes to perform an specific action), well when I used the following serial port code part (C++/CLI) I obtained very different results in my circuit(receptor) from the results I had by testing the communication on the HyperTerminal (this results are the ones that I expected) from Windows.

private: System::Void button6_Click_1(System::Object^ sender, System::EventArgs^ e)
   array<Byte>^ TxBfr={0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0x00,0xFF,0x03};

This code DOES send the information (arry of bytes) but seems like its been modified, because my external circuit performs a different action to the one its supposed to do.

Do I have to do any convertion to my array? Might that be the problem?

Thanks for reading any feedback?

Updated 3-Oct-11 12:44pm
André Kraak 3-Oct-11 18:14pm    
Edited question:
Added pre tags
Formatted text/code
Sergey Alexandrovich Kryukov 3-Oct-11 18:27pm    
Insufficient information. There is nothing special about these parameters and data sent, so how anyone could find a problem?
You messed up something. Who knows what exactly?

1 solution

In the documentation of the Write[^] method is a remark about the encoding used by the function.
By default, SerialPort uses ASCIIEncoding to encode the characters. ASCIIEncoding encodes all characters greater then 127 as (char)63 or '?'. To support additional characters in that range, set Encoding to UTF8Encoding, UTF32Encoding, or UnicodeEncoding.

So the encoding is messing up your bytes, as stated any byte larger than 127 is replaced by char(63) '?'.

Try using a different encoding.
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