Hi all,

Currently im doing a little coding to communicate between two PCs through RS232 ports.
i am thinking of using:
"writeFile" to send a string to the other PC,
"readFile" to read back the acknowledgement string from that PC and
"strcmp" to check if the read back acknowledgement string is as expected.

i believe i will need to do some "openserialport" first then followed by the above parts...

i have the idea on how it should run, but no idea how to start the coding process.

Can anyone please advice me with some examples/solutions?

Appreciate it. thank you.

6 Years
Discussion Span
Last Post by solycutema

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 simpler.


hi mike, thanks
yes, i do understand the flow and how it should flow
did found some examples on msdn...
hope to find some more as reference.

thanks anyway.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.