-1

I have a few UserControl program which requires to read data from 1 serialport. A few program i have includes:

  • Airspeed, Sonar, Latitude, Longtitude & etc. Values displayed in textbox
  • Object Avoidance display
  • GPS Map

I have a button in the main form, and when it is click, it will open the serialport and the usercontrol should read data and display them, but i have no idea how to do it.

Does anybody know how i can my different usercontrol can read the data from 1 serialport? or probably some website links that i can read up. Thank you!

1 Answer 1

1

If you have one source (the serial port) and many consumers (your user controls). Then you have to add another layer of indirection. Write a class that is the owner of the serial port class and reads all the data from it into some kind of buffer (react on DataReceived event, put new data into List, Queue, etc.). This buffer will be made publicity from this class and additionally it has some event on is own (DataReceived?). All your consumers can now listen to this event and take a look into the buffer to find the desired data.

The main problem is to remove data out of the shared buffer, cause it depends on your consumers if they need the whole buffer or only some part of it. Just think about a concept how each consumer can inform the producer from which point it only works in the buffer and let the producer cut down the buffer if everyone moved beyond the beginning of the buffer. But be aware that you also have to re-inform your consumers that the indices have been changed now.

You could also avoid the problem of the growing shared buffer if every consumer creates its own local buffer by every receive of some data and in that case every consumer can cut down its own buffer as needed.

Which strategy makes more sense depends on the situation if the complexity of the first approach is needed due to make the memory footprint for the whole application smaller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.