XScript Manual · Chapter 14

DRIVER — Project Driver

DRIVER is the keyword for accessing a driver DLL object registered in the project from a script. Use the form DRIVER["DriverName"] to obtain the driver instance and call its methods.

The fixed MOTION interpolation object (multi-axis line/arc interpolation) from older versions has been removed. Equipment-specific interpolation, communication, and special control are now implemented as a project driver DLL and called via DRIVER["..."]. Therefore the methods DRIVER provides are not fixed — they depend on the methods defined by the connected driver DLL.

What Is a Project Driver

A project driver is a .NET DLL containing a class that inherits the XDriverBase abstract class. QMachineStudio loads the registered DLL, finds the class inheriting XDriverBase, creates an instance, and exposes it as DRIVER["name"]. The class members also appear in the script editor's autocomplete.

Base Class (XDriverBase)

Members that every project driver has in common. All other methods are defined by each driver DLL itself.

MemberTypeDescription
DriverNamestringDriver name (the registered name)
IsInitializedboolWhether initialization is complete
Initialize()boolInitializes the driver. Returns true on success
Close()voidShuts down the driver and releases resources

Registering a Driver

Open the Project Driver Editor node in the Solution Explorer and register the driver name and DLL with Add Driver. The name you set here becomes the DRIVER["name"] key in scripts.

Calling from a Script

// Get the registered driver "MyBoard"
if (DRIVER["MyBoard"].IsInitialized == false)
{
    if (DRIVER["MyBoard"].Initialize() == false)
    {
        return;
    }
}
 
// Call a method defined by the driver DLL (method name/signature depend on the driver implementation)
DRIVER["MyBoard"].DoSomething(100, true);
 
// Shut down
DRIVER["MyBoard"].Close();
  • The method names, arguments, and return types follow the driver DLL implementation. DoSomething above is an example; the real methods differ per driver.
  • Accessing a name that is not registered causes a runtime error because the driver cannot be found. Check that it is registered and that IsInitialized is true before use.

Hardware Board Backend

I/O, motor, communication, and vision boards can also be backed by project drivers. In that case standard objects such as MOTOR, Digital I/O, and Communication use the driver internally, so scripts usually control hardware through the standard objects and use DRIVER only to call driver-specific functions directly.