Serial Communication in C++

I’m having trouble finding resources on serial communication with c++ for the 3d dashboard program. I have finished coding the interface but I need the serial comm part… I heard that you might need to use MFC but I wasn’t sure. Is there another way without having to create an MFC-based app?

*Originally posted by Adam Shapiro *
**I’m having trouble finding resources on serial communication with c++ for the 3d dashboard program. I have finished coding the interface but I need the serial comm part… I heard that you might need to use MFC but I wasn’t sure. Is there another way without having to create an MFC-based app? **

http://www.robbayer.com - just go to the how-to link, and there is a tutorial on how to get a serial communication set up w/o using MFC.

Wow, I should have checked there first… thanks.

*Originally posted by Adam Shapiro *
**Wow, I should have checked there first… thanks. **

Yup, it helps if you download RoboCon (found on his site) also…it comes with some nifty functions and all.

A word of warning: ignore everything it says about mult-threading unless you know what you are doing. It’s messy and can lead to some insanely difficult bugs.

Instead, follow RoboCon’s example, as it is not multi-threaded and works just fine. Just make sure you are looking at the RoboCon source, and not ConSample as ConSample is MFC, but RoboCon is not.

–Rob

And MFC is confusing if you haven’t really done any Win32 Programming (to me it was anyways). Multi-threading doesn’t work all that well w/ Win32 anyhow.

I’ve done a bit of MFC and Win32 but I didn’t really want to add MFC to the app if I could avoid it. It is complex enough having to use Direct3D… I’ll try RoboCon to see how it works. Hopefully I can get this program working soon so I can upload the code to our team website (which I need to finish too…).

I’ve got a low overhead example of how to implement a software-based state machine that properly handles the dashboard data stream. If it’ll help, you can find it on this page:

http://www.cvhsrobotics.org/resources.htm

-Kevin

I’ve used my serial port to communicate with my Stamp- and PIC-controlled minions many times. The code in C++ is very easy. It’s treated as a file. Just open “COMX” as the file and set a few permissions (where X is the port number)… its all in the MSDN serial communication sample program.

hPort = CreateFile (“COM4”, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

Then you’ll want to look up the DCB structure to set all the cool baud rate, parity, and stop bit options. The COMMTIMEOUTS struct might help you out too. I’ve got a program that uses my serial port to send data (via my very own cobbled-together RS-232 radio transmitter) to one of my PIC robots. PM me and I’ll send you the code.