Book for learning C++ and Serial ports

I am learning C++ with the goal of running applications that communicate with my Arduino projects via the serial port.

I have seen a few code examples that show how to use a serial port, but they all seem to use different libraries, and none explain the code. I'd like a book, or a tutorial that goes in depth covering that topic.

I'm using Windows 10 environment. If you don't know of a book, perhaps library suggestions will get me headed in the right direction.

My first project will be to transmit a little bit of data out the serial port to my Arduino. No response is required. Latter I will want two way communications, but for now transmit is all I need.

I do not need any "Window" of any kind on the computer, just dump some data.

Take a look at the examples in the IDE - I'm sure there are serial ones there.

TheMemberFormerlyKnownAsAWOL:
Take a look at the examples in the IDE - I'm sure there are serial ones there.

If you are referring to the Arduino IDE, you must have misunderstood the question. I need an application that runs on Windows, not on the Arduino.

I am using Codeblocks which does not come with examples.

amdkt7:
I am using Codeblocks which does not come with examples.

I must've misunderstood the question - I thought you were trying to learn C++.

Sorry.

TheMemberFormerlyKnownAsAWOL:
I must've misunderstood the questio. - I thought you were trying to learn C++.

Sorry.

I really don't understand.. My IDE is Code:Blocks and I am trying to learn C++ in the Windows environment. Are you expressing some sarcasm?

I don't know - what is "Code:Blocks"? And why doesn't it have examples?

It is an IDE for many different programming languages. It is the one that my current book "C++ All in One for Dummies" recommends, so that is what I am using. I have no idea why it does not include examples... perhaps the number of topics is too broad?

Well, maybe you could install the Arduino IDE?

AWOL, I do use the Arduino IDE for writing code that runs on the Arduino. I need code that runs on the PC. I know how to write code for the Arduino.

I'd be asking your question on a hobby Windows or Code:Blocks forum.

CodeBlocks does have example to create a simple windows form when you create a new project.

Keep in mind that, C++ itself is cross-platform, but interacting with Windows' resources requires Windows API. I don't know any book but there are abundance resources on the web (mostly from Microsoft itself) that have example code to request use of system resources.

Arduino_new, thanks. It's pretty confusing to me at this point, understanding which direction to start in. I understand that I need to interact with the Windows API.

Maybe I am trying to jump too far. Maybe I just need to continue learning C++ through my current book, but I just learned how to get the time in Unix format, which is just what I want to send to my Arduino project.

It probably is pretty simple, but finding an example that does what I want is getting me nothing but confused so far.

I am spending about eight hours a day studying C++ (while work is slow), so I am working hard to achieve my goal. I just need pointers.

It took MR FormerAWOL quite a few posts to make his point that I was perhaps on the wrong forum. So, I guess I will go ask elsewhere.

I've never done it, but my impression is that writing C++ on Windows and interacting with the API is something of a slog. I think that's why people use Python for that (never used it either).

amdkt7:
It probably is pretty simple, but finding an example that does what I want is getting me nothing but confused so far.

You just need to get to the specific: this is how you can get current time on windows machine. (from GetSystemTime function (sysinfoapi.h) - Win32 apps | Microsoft Learn)

#include <iostream>
#include <windows.h>
using namespace std;

int main()
{
    LPSYSTEMTIME time = new _SYSTEMTIME();
    GetSystemTime(time);
    cout << "year " << time->wYear << endl;
    cout << "hour " << time->wHour << " minute " << time->wMinute << " second " << time->wSecond << endl;
    delete time;
    return 0;
}

gfvalvo:
I've never done it, but my impression is that writing C++ on Windows and interacting with the API is something of a slog.

That it does, Windows people tend to wrap everything under their own typename which is very anoying.

I have code that gets the time, in the format that I need:

#include <iostream>
#include <time.h>
#include <stdlib.h>

using namespace std;

int main()
{
    time_t now;
    int unix = (time(&now));
    cout << unix << endl;

    return 0;
}

it's sending it out the serial port that is the goal today.

amdkt7:
it's sending it out the serial port that is the goal today.

Check this out if you want to learn it yourself: Serial Communication in Windows | CodeGuru

Here is the library that looks good: SerialPort/src at master · manashmandal/SerialPort · GitHub

now that's the kind of help I was looking for! I'll dig into it tomorrow, hopefully. The codeguro article looks like just the ticket.

Thanks

Why C++? For code running on a computer to communicate with an Arduino, I would choose python - easier to write, and very well suited to this sort of task....

Though it sounds like this is partly an exercise in learning C++

DrAzzy:
Why C++? For code running on a computer to communicate with an Arduino, I would choose python - easier to write, and very well suited to this sort of task....

Though it sounds like this is partly an exercise in learning C++

I started trying to learn Python, but when I was not learning how to do what I wanted to do, ie talk to hardware I got into Arduino instead. I have a lot of time invested in C++, especially since I do so much Arduino programming. It might be a good idea to go back to Visual C++ (I studied that for a while too), once I have a better grounding in C++.

Python would probably be easier, I'm sure. Just that I think C++ is my better long term language.

There is here: Jan Axelson's Lakeview Research
Her book is one of THE references for USB, but the serial book was last published in 2007, and I’m not sure how much windows apis have changed since then.

In the most basic form, you open “COMn:” and read/write it like any other file. But you may need additional setup to ensure asynchronous behavior.