/WMX3/
How do I use software motion control?
In the previous WMX3 basic development tutorial, we explained how to create a project using C#, which should have given you some familiarity with the WMX3 software. C++ is also a primary programming language for WMX3, and its operation steps are largely the same as C#. The following tutorial will guide you through creating a WMX3 project using C++.
Q1 Introduction
Project Creation Overview
Developing a WMX3 application first requires creating a project, and C++ is one of the main programming languages for WMX3.
The folder containing the libraries required for C++ development is C:\Program Files\SoftServo\WMX3\Lib. WMX3Api.lib is a necessary library, while the others are optional. IMDll.dll should be copied to the same folder as the executable program.
The following example demonstrates the specific steps for creating a project, using a C++ program to enable axis connectivity. This method is applicable to WMX3_V3.3 and later versions.
Operating environment
System environment: RTX 3.7
Software version: WMX3_V3.4u1_64bit
Visual Studio 2012
Programming language: C++
Q2 Steps
1. Create a Win32 console application using Microsoft Visual Studio, selecting the default configuration in the project wizard.
Figure 1 Creating a console application
2. Open the Configuration Manager. When using the 64-bit version of the WMX3 library (i.e., RTX64), the solution platform must be switched to X64.
Figure 2 Configuration Manager
Figure 3 Switching Platforms
3. Open the project properties page. Navigate to "Configuration Properties\C/C++\General", click the arrow next to "Additional Include Directories", and select "Edit...".
In the pop-up dialog box, include the header file directory under the WMX3 installation directory. (Default: "C:\ProgramFiles\SoftServo\WMX3\Include")
Figure 4 Configuration Properties\C/C++\General
Figure 5 includes an additional directory.
4. Navigate to "Configuration Properties\Linker\General". Click the arrow next to "Additional Library Directories" and select "Edit...".
In the pop-up dialog box, include the lib directory under the WMX3 installation directory. (Default: "C:\ProgramFiles\SoftServo\WMX3\Lib").
Figure 6 Configuration Properties\Linker\General
Figure 7 Additional Library Directory
5. Navigate to "Configuration Properties\Linker\Input", click the arrow next to "Additional Dependencies", and then select "Edit...".
In the pop-up dialog box, add the following DLL file:
AdvancedMotionApi.lib
ApiBufferApi.lib
CompensationApi.lib
CoreMotionApi.lib
CyclicBufferApi.lib
EventApi.lib
IMDll.lib
IOApi.lib
LogApi.lib
UserMemoryApi.lib
WMX3Api.lib
Note: ①IMDLL.lib and WMX3Api.lib are required libraries, while other libraries are optional.
② When using Visual Studio 2015 or later, you also need to add legacy_stdio_
Add definitions.lib and legacy_stdio_wide_specifiers.lib to the list.
Figure 8 Configuration Properties\Linker\Input
Figure 9 Additional Dependencies
6. Navigate to "Configuration Properties\Generate Events\Post-Generate Events". Click the arrow next to "Command Line", select "Edit...", and enter the following statement:
copy/y"C:\ProgramFiles\SoftServo\WMX3\lib\IMDll.dll""$(OutDir)"
Figure 10 Configuration Properties\Generate Events\Post-Generate Events
Figure 11 Command Line
7. Close the project properties page, open the program writing page, and add the header file, for example:
#include"AdvancedMotionApi.h"
#include"ApiBufferApi.h"
#include"CompensationApi.h"
#include"CoreMotionApi.h"
#include"CyclicBufferApi.h"
#include"EventApi.h"
#include"IOApi.h"
#include"LogApi.h"
#include"UserMemoryApi.h"
#include"WMX3Api.h"
8. Add the following example code, which specifically creates a device, enables communication, enables axis 0, disables axis 0 after 5 seconds, disconnects communication, and shuts down the device.
int_tmain(intargc,_TCHAR*argv[])
{
using namespace wmx3Api;
using namespace std;
WMX3ApiWmx3Lib;
CoreMotionStatusCmStatus;
CoreMotionWmx3Lib_cm(&Wmx3Lib);
Wmx3Lib.CreateDevice("C:\\ProgramFiles\\SoftServo\\WMX3\\",DeviceType::DeviceTypeNormal,
INFINITE);
Wmx3Lib.SetDeviceName("MotorControl");
Wmx3Lib.StartCommunication(INFINITE);
Wmx3Lib_cm.axisControl->SetServoOn(0,1);
while(true)
{
Wmx3Lib_cm.GetStatus(&CmStatus);
if(CmStatus.axesStatus[0].servoOn)
{
break
}
Sleep(5000);
}
Wmx3Lib_cm.axisControl->SetServoOn(0,0);
while(true)
{
Wmx3Lib_cm.GetStatus(&CmStatus);
if(!CmStatus.axesStatus[0].servoOn)
{
break
}
Sleep(1000);
}
Wmx3Lib.StopCommunication(INFINITE);
Wmx3Lib.CloseDevice();
Sleep(3000);
return 0;
}
9. Open the WMX3Console tool, run the program, and monitor the communication and axis status.
When the axis number turns green and CommunicationState turns On, it means communication is enabled; when ServoOn/Off axis 0 turns green, it means axis 0 is enabled.
Figure 12 WMX3 Console Interface
Additional notes
For 64-bit systems, when the compilation platform is 32-bit, the following three points should be noted, while other operating steps remain unchanged.
① Skip step 2; no need to switch solution platforms.
② In step 4, change the WMX3 header file directory to "C:\Program Files\SoftServo\WMX3\Lib\x86"
③ Step 7 should be changed to inputting the following statement:
copy/y"C:\ProgramFiles\SoftServo\WMX3\lib\x86\IMDll.dll""$(TargetDir)"
Disclaimer: This article is a reprint. If it involves copyright issues, please contact us promptly for deletion (QQ: 2737591964). We apologize for any inconvenience.