Tutorial 1-2: Creating and closing devices

A device is an object of the WMX3Api class that has opened a communication channel with the WMX3 engine. Each thread that will call WMX3 API functions must obtain a device by creating a WMX3Api object and calling the CreateDevice function from that object.

The following code demonstrates how to create a device:

using namespace wmx3Api;
WMX3Api wmxlib;
wmxlib.CreateDevice(_T("C:\\Program Files\\SoftServo\\WMX3"), DeviceType::DeviceTypeNormal);

All WMX3 library classes and constants are contained in the wmx3Api namespace.

The first argument of the CreateDevice function should be passed the full path of the directory that contains the WMX3 engine file, WMX3Engine.rtss. This is “C:\Program Files\SoftServo\WMX3” for the default installation directory.

The second argument of the CreateDevice function should be passed DeviceTypeNormal.

See CreateDevice for additional information regarding this function.

After a device has been created, WMX3 API functions may be called through the WMX3Api object that created the device.

All WMX3Api objects that have created a device must call CloseDevice before exiting the application. Failing to close all opened devices will cause the WMX3 engine process to remain running after exiting the application. If this occurs, the WMX3 engine must be manually closed with the StopEngine function, or force terminated from the RTX Task Manager (this is not recommended, as it can potentially cause instability).

A CloseDevice function is appended to the above code:

using namespace wmx3Api;
WMX3Api wmxlib;
wmxlib.CreateDevice(_T("C:\\Program Files\\SoftServo\\WMX3"), DeviceType::DeviceTypeNormal);

wmxlib.CloseDevice();

To summarize, an application using the WMX3 library should call CreateDevice at the start of the application and CloseDevice before exiting the application.