Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm currently working on my small wsn project using arduino. I use my node for sending sensor data to my PC and I catch it using Serial Port programmed with C#. All the data from my node is encrypted using aes128. So I have to read the serial as byte in my C# program. The code below is how I read my serial.
C#
int databytes = ComPort.BytesToRead;
byte[] byte_buffer = new byte[databytes];
ComPort.Read(byte_buffer, 0, databytes);

The problem is when the program hasn't done read all the byte from buffer, it runs next process. I need help to make my program read all the byte first before running next process. Any suggestion?

Thanks
Posted

1 solution

Just 'run next process' after you have succesfully received all the needed data (this implies you probably have to wait for several DataReceived events).
 
Share this answer
 
Comments
Member 12008308 30-Sep-15 9:04am    
How? The data I need is 86 bytes long. How can I set the length of the serial buffer to wait until the 86 bytes are fully filled with data?
CPallini 30-Sep-15 9:09am    
Usually you don't do that. Instead you append all availabe data of each DatarRceived event in a buffer, until reaching the target size.

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