Scientist42
Scientist42

Reputation: 77

Need advice about communication via serial port in C++/CLI

I am working on project where I have to communicate via serial port. I will be receiving quite "large" amount of data from UART via RS232 (approximately 6KB/10ms) and I have to collect it and decode it. Decoded data will be stored to files and some of them will be shown in GUI.

I will be using C++/CLI (in Visual Studio 2010 using .NET v4.0) because of managed data work and large amount of libraries.

And my main question is: What would you recommend me:

A) To not use threads and look for data each 5ms via timer...

B) To not use threads and look for data based on event of incoming data...

C) Use threads...

What would you recommend me? I have not much experience to tell what will be the best solution.

Thank you for your future responses...

Upvotes: 2

Views: 721

Answers (1)

stijn
stijn

Reputation: 35911

If you need a gui, you will need a seperate thread to get the data. There's no way to reliably get data each x mSec and process it in a ui thread.

Apart from that you seem somehwat confused about what a thread does: A and B can be combined with C. I'd recommend using a seperate thread polling the port for data or use an event to check when new data arrives. Timer might be inaccurate, and after all it's the port dictating at what rate the data comes in so it's better to listen to that instead of using a seperate timebase. Store the processed data on a queue (aka producer) and have yet another thread (aka consumer) get large chunks from the queue to flush them to files (you do not want to write a file every 5mSec, instead write a large amount of data in one go every 100mSec or so). The ui thread can then also preview from that queue and displays pieces of the data.

Upvotes: 3

Related Questions