Solved

C# Update multiple open Forms from data retrieved from Serial port

Posted on 2008-06-24
4
1,398 Views
Last Modified: 2010-08-05
I'm currently in design phase, so I don't currently have any code snippets, but here's a description of the program.  It is a timing view for a race team.

Receives text based serial stream from attached device.  The information I will be retrieving from the stream will be "Car number, Position, Lap Number, Lap Time, Total time".  From this I will be updating multiple forms.  One form will show current positions, last lap, and whether the Car moved up or down in position.  Another will show Car Number, Current Points (determined from loaded data and Position), Another will show current number of laps on tires for our car.  There could be up to 5 windows all showing different information that is derived from the stream data.

In addition to the real time updates, it will also need to save the data to write out to a file at the end.

I'm wondering what will be the best way of keeping all of this data and updating multiple forms when a SerialPort.DataReceived event is fired. One thought I've had is the DataReceived even processes the stream and get's the information, then passes a single string with just the info I need to each of the forms.  

As for storing it for writing a report afterwards, the only thing I could think of would be a multi dimensional array where each Lap would have 43 car numbers, and each car # for each lap would have Lap Time, Position, Total Time, and then at the end dump this information into CSV or however I choose to store it.

The possible problems I can see :

1) Speed - The Form updates need to be as close to real time as possible.
2) Buffering - Can't lose data from serial port, need to make sure every incoming value is pased
2) Size - Worst case would be 400 Laps with 43 Cars, each lap/car combo with the three values mentioned.

Am I on the right track?  Any advice would be greatly appreciated.  I've done some MDI applications, but nothing that all pulled from the same values and defintely nothing of this complexity, so I'm trying to plan it out as much as possible so I don't paint myself into a corner.

Thanks in advance.
0
Comment
Question by:Kragster
  • 2
  • 2
4 Comments
 
LVL 11

Accepted Solution

by:
William earned 250 total points
ID: 21861633
Sounds like a really cool project...  I now have project envy :)

I like your idea of :
One thought I've had is the DataReceived even processes the stream and get's the information, then passes a single string with just the info I need to each of the forms.  

The easiest way I can think of to 'do this' would be:
Create a Custom Class(Component) derived from the Serial Port:
In the recieved event
Parse your data for the various forms...
Create a cutom event for each form and have each form subscribe to their event...
Raise the event(s) as needed...
Inside the subscribed form populate the data with object/string required and refresh/invalidate that form
This would give the fastest results....
-------------------- Sounds simplier in my head :) ----------------

Storing the report afterword....
Why not use SQL2005 Express?
Or
Create a serializable class/struct to hold your data then you can save it to XML.

Hope this helps....
BillyDvd
0
 
LVL 2

Author Comment

by:Kragster
ID: 21864759
With the SerialPort stuff running in it's own thread(I think it does it automatically) is there potentially any problem with one of the form events getting called a second time before it finishes?

First time with multi-threading too.  This is going to be an interesting project for me :)
0
 
LVL 11

Expert Comment

by:William
ID: 21865825
What I have done in the past is place a loop in the event....
while( reading )
{
//do your work here ...  build your strings from the bufffer whatever....

//Place a short sleep here to ensure you get all the data as the data is slower then the proccessor (baud rate (9600+) or proccessor 1ghz+ ....
System.Threading.Thread.Sleep( 180);
}
after the loop is comnplete...
raise your events as required
this ensures that the events you need are the ones raised....
0
 
LVL 2

Author Comment

by:Kragster
ID: 21886023
Thanks for the help, think I've got a pretty good idea now.  I'm starting to work on the first module, to handle the serial input, this weekend in New Hampshire.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
eclipse package explorer vs project explorer view 2 33
comparing string in C# 3 34
Long URL in SMS 6 24
C# TextBox 11 15
This is an explanation of a simple data model to help parse a JSON feed
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now