Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Communication between existing C++ code and Visual Micro (Read 1615 times)
Lakshith Ranasinghe
Newbies
*
Offline


Posts: 1
Joined: May 21st, 2021
Communication between existing C++ code and Visual Micro
May 24th, 2021 at 8:45am
Print Post  
Hi all,

I recently purchased Visual Micro for the purposes of integrating a stepper motor controlled by an Arduino to an existing Visual Studio project.
 
I have had a look at the documentation provided and the examples I have found are largely related to adding cpp files to an Arduino project rather than the other way around. Naturally I would assume the other way is possible?
 
I am hoping someone would be able to advice as to how best to proceed. The existing C++ code calculates the distance needed and I have already created the necessary code on the Arduino to control the stepper motor (which accepts the distance required to move).
 
What I am having trouble with is figuring out how to link up the 2 sets of code. Should I be using a serial port library from C++ which will then transfer the data to the Arduino via serial communication.

Or else is it possible to transfer that info to the Arduino simply by adding the .ino file to the project. How would I then call the Arduino sketch from the C++ code I have?

I require 2 way communication with the Arduino as I want to send a signal for the stepper motor to move, and I also want to receive a signal back when a particular switch is triggered too.
  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2170
Joined: Feb 13th, 2019
Re: Communication between existing C++ code and Visual Micro
Reply #1 - May 24th, 2021 at 9:15am
Print Post  
Adding CPP Files to an Arduino Project is the normal route, as Arduino projects are just C++ with the special features of the INO build system.   

You can move the code out of the INO into other CPP/H files and include and call them in your INO, so all of the other code is simply standard C++.
   
See our links below about adding code, and shared projects and libraries may also be of use in the future if the same stepper code module is needed in multiple projects.
YouTube: Adding C++ / C / INO Code to Arduino Project
Docs: Understanding Project Structure
Docs: About INO and CPP Files
Docs: Adding and Deleting Source Files

If you need your C++ project on the PC to communicate with your Arduino Board, they will need to do this via Serial/WiFi etc.. depending on the board in use, as the application on-chip and the application on-board are on separate machines at runtime.

Then your desktop C++ would need to access the Serial Port on the PC (using standard C++ Serial tools), to communicate with the Arduino Serial code on the board (using Arduino Serial.read() etc).

Both Desktop and Arduino Projects can share the C++ Stepper Calculation project to access its methods if needed.

The Serial Debugger can also be used to test the Arduino Code from the PC as shown in the below video about calibrating a Linear Actuator from the IDE:
Calibrating Linear Actuator with Serial Debugger
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint