minute read

Controller

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

The Basics

The Python API revolves around the Controller class. All interaction with an Automation1 controller occurs through an instance of this class. To start using the Python 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 currently 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. There are different ways to connect:

  • 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.connect_usb 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 from the controller instance.

Example Code

Copy
# Import the Automation1 Python API package. For convenience, import this package as “a1”.
import automation1 as a1

# Connect to the iSMC that is installed on this PC. If you want to connect to a remote controller
# on a different PC, specify an IP address.
controller = a1.Controller.connect()

# Start the controller to which you are connected to make sure that 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. When you make changes to this property, they have an immediate effect.

WARNING: If the controller is not running or is in the process of resetting, do not try to access the Controller.runtime property. If you do, an exception will be raised.

The Controller.configuration property lets you configure the behavior of the controller the next time that it starts or is reset. When you make changes to this property, you must reset the controller for them to have an effect.

Thread Safety

The threading library is the only multithreading library that is officially supported by the Automation1 Python API.

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

The Controller.connect method is thread safe. You can call it from two or more threads without interference.

The Controller.disconnect method is not thread safe. Call this method from one thread only.

The Controller.start, Controller.stop, and Controller.reset methods are not thread safe. Only one thread at a time can call these methods. If it is necessary for two or more threads to call these methods, you must use locks to limit the access.

For all the 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 and methods that are available for Controller, refer to the lists that follow.

Controller Properties

Controller Methods

Controller.runtime Properties