I guess you could start from a tutorial example (from msdn or somewhere else), just copy/paste the code and start tweaking it, that's the easiest way. Then I guess you will need two programs, one that sends (or at least initializes the communication) and one that receives. Or what you can do to start is to make an "echo" program that simply outputs back whatever it receives. Then use a terminal application to type in strings to be sent to through RS232 (like Term, TERMINAL, Termite, etc.) and see if you get the echo back. Then, start tweaking to parse the commands and stuff.
It might be easier to use std::string and related functions instead of strcmp() for string parsing and comparison. If you want to be real fancy you can use boost::tokenizer or boost::spirit/lambda/phoenix, but these require quite good understanding of C++ to use (template meta-programming).
Basically a RS232 communication usually goes something like this:
- Open Port... check that it worked..
- Configure... [optional]
- while ( some_flag_that_means_the_program_is_still_running ) {
- while( readFile(...) == PORT_EMPTY ) { //PORT_EMPTY is made-up.
- sleep( some_small_time_interval );
- };
- Process received value (usually a string);
- if ( received_command == PROGRAM_TERMINATE )
- some_flag_that_means_the_program_is_still_running = false;
- };
- Close Port (closeFile())
Basically that is how the Win32 API is setup to work. But I'm sure there are libraries that make serial port communication a bit …