Click to See Complete Forum and Search --> : Recieving data from Serial Port


chrisaugier
February 22nd, 2010, 01:46 PM
Hi all,
I have been struggling for a while now with using events to receive a string from a serial port and using the data inside my main function.

To set a bit of context i am sending movements for a buggy to follow and when a movement is complete, the buggy returns a "D". When the program receives this, the next coordinate should be sent.

I'm sure there is a tidy way of doing this avoiding global variables and i would very much appreciate it if someone with more knowledge in this area could lend a hand.

Code available on request.

Thanks in advance, Chris Augier.

nelo
February 23rd, 2010, 04:46 AM
I'm sure there is a tidy way of doing this avoiding global variables and i would very much appreciate it if someone with more knowledge in this area could lend a hand.
I don't have a lot of experience of reading from a serial port. But the way you have phrased your question suggests that you have a more general problem. The structure of your program and communication of data through the system can be independent of the target data source. The fact that you are communicating with a serial port shouldn't affect how you deal with variables. Without knowing the exact problem you are facing I would recommend object oriented principles and events for communications (You are already using events by the look of it). Are you facing a specific problem or are you just looking for some pointers to improve what you already have?

vcdebugger
February 23rd, 2010, 05:37 AM
http://www.dreamincode.net/forums/index.php?showtopic=35775

this link talks abt comport read/write operation using C#...

eclipsed4utoo
February 23rd, 2010, 07:46 AM
here is a little simpler snippet on reading and writing to the serial port.

http://www.dreamincode.net/code/snippet2764.htm