minute read

Controller

You are reading our Automation1 API documentation for the .NET programming language.

The Basics

The .NET API revolves around the Controller class. All interaction with an Automation1 controller is through an instance of this class. To start using the .NET API, you must connect to an Automation1 controller to get an instance of the Controller class. Then the properties on this class will give you access to the various Automation1 controller features.

When you connect to a controller, this process does not automatically start it. You can connect to a non-running Automation1 controller without starting it. When you disconnect a controller, this process does not stop a controller that is running. The Controller.Runtime property represents features that you can access only if the controller is started and running. For more information, refer to the Controller Runtime section below.

You can connect to many Automation1 controllers at the same time in the same custom application. You can also connect to the same Automation1 controller multiple times at the same time.

How to Use

You can connect to multiple controllers at the same time or connect to the same controller multiple times. Call the Controller.Connect method to connect to a specific controller, either a locally installed PC-based controller, a remote PC-based controller, or a remote drive-based controller. Call the Controller.ConnectUsb method to connect to a drive-based controller that is plugged into your computer over USB.

When you are done interacting with the controller, call the Controller.Disconnect method.

Example Code

Copy
// Connect to the iSMC that is installed on this PC. You can optionally specify an IP address to connect to a remote controller.
Controller controller = Controller.Connect();
 
// Start the Automation1 controller that you are connected to, to make sure it is running.
controller.Start();
 
// With the controller running, you can access the Runtime property.
controller.Runtime.Commands.Motion.Enable("X");
 
// Disconnect from the controller when you are done interacting with it.
// When you disconnect the controller, this does not stop it. The controller will continue to run.
controller.Disconnect();

Controller Runtime

The Controller.Runtime property represents features that you can access only if the controller is started and running. If the controller is not running or is in the process of resetting, an exception will be thrown. The controller runtime is different from the Controller.Configuration property, which is how you configure the behavior of the controller the next time it starts or is reset. Controller.Configuration requires you to reset the controller while Controller.Runtime changes have an immediate effect.

Controller Information

You can use the Controller.Information property to get information about the Automation1 controller to which you are connected. Refer to the example that follows.

Copy
string host = controller.Information.Host;
string controllerName = controller.Information.Name;
string serialNumber = controller.Information.SerialNumber;
Version version = controller.Information.Version;

The Controller.Information property also has some events to which you can subscribe. These events let you know when the controller is started, stopped, or reset. You can also use them to get the state of the Automation1 controller if your custom application needs to change its behavior. Refer to the example that follows.

Copy
EventHandler<ControllerEventArgs> ControllerStarted;
EventHandler<ControllerStoppedEventArgs> ControllerStopped;
EventHandler<ControllerEventArgs> ControllerReset;

Machine Controller Definition Files

Machine Controller Definition (MCD) files define an Automation1 controller. These files can include all the parameters, configuration, and files that define your motion control system. MCD files make it easy for you to back up your controller configuration, test parameter changes, and replicate a machine.

You can download and upload MCD files from the .NET API. Refer to the example that follows.

Copy
void DownloadMcdToFile(string mdkFilePathToMcd, bool shouldIncludeControllerFiles, bool shouldIncludeConfiguration);
void UploadMcdToController(string mdkFilePathToMcd, bool shouldIncludeControllerFiles, bool shouldIncludeConfiguration, bool eraseController);

For more information, see the Machine Controller Definition Files page.

Thread Safety

The Controller.IsRunning property is thread safe. You can call this property from two or more threads without interference.

The Controller.Connect and Controller.Disconnect methods are thread safe. You can call them from two or more threads without interference.

The Controller.Start, Controller.Stop, and Controller.Reset methods are not thread safe. Only one thread at a time can call these methods. If two or more threads must call these methods, you must use locks to limit access.

For all other properties on the Controller class, see their respective reference pages for information about their thread safety.

Full Reference

For more information about the properties, methods, and events that are available for Controller, refer to the lists that follow.

Controller Properties

Controller Methods

Controller.Information Properties

Controller.Information Events

Controller.Runtime Properties