C++ Program communicating with Arduino Uno

Hi,

I want a C++ program that I wrote to communicate with my Arduino. The C++ program essentially asks a user how many tickets they want to print. I want this value to be sent to the Arduino to determine how many times the Arduino needs to actuate a relay. I have been searching around for some existing code but haven't found anything that stands out as what I am looking for. Any guidance or points in the right direction would be greatly appreciated.

Thanks

Hello,

I tried with C++ and all I can say is, it's much easier to do it in C#, so use it if you can, here is a small example (sorry I wrote it in french) how to communicate a value from PC to Arduino: Check the percentage of the computer's battery - #25 by guix - Français - Arduino Forum

Agreed, its far easier in C#, however it may be too late to transpose an entire app. Here is some info on how to do it on windows ( without C#, its method is far simpler ). This is for C++, however any language that can use the windows API has access to the same functions, and possibly easier ways.

I can't remember off hand their names, however there are some open source serial implementations which wrap this functionality into a nicer interface.

Here is an article that popped up first.

I haven't looked into the next link, it seemed interesting from the google caption though.
http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/overview/serial_ports.html

What platform does your program run on, I.e. Windows, Mac, other? How are you connecting to the arduino, i.e. USB, wifi, other?

If you are connecting via USB then you simply need to find and open the arduino's serial port. How you do that will depend on what environment your program is running on. You should have no problem googling for example code on how to do that.

Thanks for the replies and links.

My program will run on Windows and connect to the Arduino via USB. So I will google information about opening the Arduino's serial port.

I am not familiar with C#, I need to look in to it in the future. I am currently in the process of learning C++ and have mediocre C programming abilities. So it's not that I don't want to use C#, it is that I don't have any knowledge in that language and unfortunately I also I don't have the spare time to direct towards learning it at the moment.

Again, I appreciate the links and will meddle around with this information to see if I can get where I need to be. I will update with any progress.

Thanks!

I found that using C++ to do this, was rather problematical, it seems to be more straightforward to use Processing.

Why not use/learn the API for com port communication then you are pretty much free to use what ever language you want to provided it supports the standard Win32 API calls.

See here:

In Unix it's as easy as open("/dev/ttyUSB0"...)
I've heard Windows starting from NT implements many BSD-like api's so I would expect it to have a similar open call as well.
You could also use a class library that abstracts the OS layer to allow for portability between windows/mac/unix.