minute read
Status
You are reading our Automation1 API documentation for the .NET programming language.
The Basics
In the .NET API, Status lets you get information about what the Automation1 controller is doing at this current moment in time. The pieces of information that you can get are known as status items. They are categorized into axis, task, and system categories. See The Three Categories: Axis, Task, and System.
All status items return double-precision floating-point numbers. Some status items represent enumerations or masks. Use status to get axis positions, axis-homed states, axis faults, I/O values, task states, task errors, and more.
The .NET API gives you a way to retrieve multiple status items from an Automation1 controller during runtime. Retrieved status represents a moment in time. Status is different from Data Collection because status is not real-time, and it is not time-series data. Status also has variable latency when you retrieve it. You can get status at any time. But you can collect only one set of data at a time. See the Data Collection page.
When you get status, this process has some quantity of fixed overhead. Thus it is better for you to get status less often and get more status items in each call.
For Example
Instead of getting status for each axis through 32 separate method calls, get all status for all 32 axes in one call.
How to Use
In the .NET API, Status is part of the Controller.Runtime property. For all the APIs that operate under this property, the Automation1 controller must be running before you can get status. For more information about this property, see the Controller page.
To get status by using the .NET API, you must:
- Configure the status items that you want to get.
- Specify the axes or tasks from which to get the status items.
First, create a new StatusItemConfiguration object. This class represents a configuration of status items to retrieve from an Automation1 controller. The StatusItemConfiguration class is one of the few classes in the .NET API that you must construct.
StatusItemConfiguration statusItemConfiguration = new StatusItemConfiguration();
After you make a configuration object, you can add the status items that you want to retrieve. All status items are categorized into axis, task, and system categories:
- Axis status items require you to specify the axis from which to get the status item. You can specify an axis by its axis name or axis index.
- Task status items require you to specify the task from which to get the status item. You can specify a task by its task name or task index.
- The Automation1 controller is the only system. The System property does not require you to specify a system from which to get the status items.
Add the status items that you want to retrieve to the configuration. To do this, use the Axis, Task, System, and IndustrialEthernet properties with the Add method.
statusItemConfiguration.Axis.Add(AxisStatusItem axisStatusItem, string axisName);
statusItemConfiguration.Task.Add(TaskStatusItem taskStatusItem, string taskName);
statusItemConfiguration.System.Add(SystemStatusItem systemStatusItem);
statusItemConfiguration.IndustrialEthernet.Add(string industrialEthernetMappingName);
After you add all the status items that you want to retrieve to the configuration, you can get their values by using the Controller.Runtime.Status.GetStatusItems method. Call this method and pass in the StatusItemConfiguration object that you constructed to retrieve the values of those status items.
StatusItemResults statusItemResults = controller.Runtime.Status.GetStatusItems(StatusItemConfiguration statusItemConfiguration);
The StatusItemResults object that is returned represents the status at the moment in time that it was retrieved from an Automation1 controller, based on the specified StatusItemConfiguration object.
To get the value for each status item or Industrial Ethernet mapping, use the Axis, Task,and System or IndustrialEthernet properties. You can index these properties by doing one of the options that follow:
- Specify the status item and the corresponding axis or task, if applicable.
- Specify an Industrial Ethernet mapping.
double axisValue = statusItemResults.Axis[AxisStatusItem axisStatusItem, string axisName].Value;
double taskValue = statusItemResults.Task[TaskStatusItem taskStatusItem, string taskName].Value;
double systemValue = statusItemResults.System[SystemStatusItem systemStatusItem].Value;
double industrialEthernetValue = statusItemResults.IndustrialEthernet[string industrialEthernetMappingName].Value;
The double-precision floating-point number that is returned by the Value property is the value of the status item at the point in time when the StatusItemConfiguration object was retrieved.
Example Code
// Configure the status items that you want to get.
StatusItemConfiguration statusItemConfiguration = new StatusItemConfiguration();
statusItemConfiguration.Axis.Add(AxisStatusItem.PositionCommand, "X");
statusItemConfiguration.Task.Add(TaskStatusItem.TaskState, "Task 1");
statusItemConfiguration.System.Add(SystemStatusItem.Timer);
// Get the status from the controller.
StatusItemResults results = controller.Runtime.Status.GetStatusItems(statusItemConfiguration);
// Get the values out of the results object.
Console.WriteLine("X Position Command: {0}", results.Axis[AxisStatusItem.PositionCommand, "X"].Value);
Console.WriteLine("Task 1 Task State: {0}", results.Task[TaskStatusItem.TaskState, "Task 1"].Value);
Console.WriteLine("Timer: {0}", results.System[SystemStatusItem.Timer].Value);
How to Get an Axis Position
You can get an axis position. You can also get its homed state, enabled state, and faults. Refer to the example that follows:
// DriveStatus is a series of bits that can be masked. You will use it to get the axis "enabled" bit.
// AxisStatus is a series of bits that can be masked. You will use it to get the axis "homed" bit.
StatusItemConfiguration statusItemConfiguration = new StatusItemConfiguration();
statusItemConfiguration.Axis.Add(AxisStatusItem.ProgramPosition, "X");
statusItemConfiguration.Axis.Add(AxisStatusItem.DriveStatus, "X");
statusItemConfiguration.Axis.Add(AxisStatusItem.AxisStatus, "X");
statusItemConfiguration.Axis.Add(AxisStatusItem.AxisFault, "X");
StatusItemResults result = controller.Runtime.Status.GetStatusItems(statusItemConfiguration);
double programPosition = result.Axis[AxisStatusItem.ProgramPosition, "X"].Value;
Console.WriteLine($"Position: {programPosition}");
// DriveStatus is a series of status bits that you can mask to get various information about the state of the drive.
// It is acquired as a double. But you need to interpret it as a series of maskable bits. To do this, you must cast it to the
// correct enum type. Then apply the "Enabled" mask from the enum and check to see if the result equals the mask to determine
// if the drive axis is enabled.
DriveStatus driveStatus = (DriveStatus)result.Axis[AxisStatusItem.DriveStatus, "X"].Value;
bool isEnabled = (driveStatus & DriveStatus.Enabled) == DriveStatus.Enabled;
Console.WriteLine($"Enabled: {isEnabled}");
// AxisStatus is similar to DriveStatus because you can mask it to get information about the state of the axis.
// It is also acquired as a double. But you need to interpret it as a series of maskable bits. To do this, you must repeat
// the process outlined for DriveStatus and AxisStatus.
AxisStatus axisStatus = (AxisStatus)result.Axis[AxisStatusItem.AxisStatus, "X"].Value;
bool isHomed = (axisStatus & AxisStatus.Homed) == AxisStatus.Homed;
Console.WriteLine($"Homed: {isHomed}");
// Finally, AxisFault is also a status item that you can mask to get information about the faults on the axis.
// It is also acquired as a double. But you need to interpret it as a series of maskable bits. To do this, you must repeat
// the process outlined for DriveStatus and AxisStatus.
AxisFault axisFaults = (AxisFault)result.Axis[AxisStatusItem.AxisFault, "X"].Value;
Console.WriteLine($"Faults: {axisFaults}");
Automatic Status
Instead of using the Controller.Runtime.Status.GetStatusItems method to poll for status manually, you can make the .NET API poll for status automatically by using the Controller.Runtime.Status.Automatic.NewStatusRetrieved event. Automatic status will continuously and automatically retrieve status from the Automation1 controller. When you subscribe to this event, it will be raised periodically with the latest status information from the controller.
By default, automatic status gets common status items for all the axes and tasks every 100 milliseconds. But you can customize the status items that are retrieved by using the SetConfiguration method and the Period property. Automatic status will automatically pause.
To pause and resume automatic status, use the Pause and Resume methods. Automatic status will automatically pause and resume if you reset or stop the controller.
Example Code for Automatic Status
// Subscribe to the automatic status event that will be raised periodically.
controller.Runtime.Status.Automatic.NewStatusRetrieved += (sender, args) =>
{
Console.WriteLine("X Position Command: {0}", args.Results.Axis[AxisStatusItem.PositionCommand, "X"].Value);
};
Retrieve Industrial Ethernet Mappings
You can use Status to retrieve the values of Industrial Ethernet mappings. To do this, use the StatusItemConfiguration.IndustrialEthernet property.
StatusItemConfiguration configuration = new StatusItemConfiguration()
configuration.IndustrialEthernet.Add(“myMapping”); // Configured to retrieve the value of $myMapping.
configuration.IndustrialEthernet.Add(“myMappingArray”, 2); // Configured to retrieve the value of $myMappingArray[2].
After you use the Status.GetStatusItems() method to retrieve status, you can use the StatusItemResults.IndustrialEthernet property to access the values that you retrieved for your configured Industrial Ethernet mappings.
StatusItemResults results = controller.Runtime.Status.GetStatusItems(configuration);
double firstResult = results.IndustrialEthernet[“myMapping”].Value;
double secondResult = results.IndustrialEthernet[“myMappingArray”, 2].Value;
Thread Safety
The StatusItemConfiguration class is not thread safe. Only one thread at a time can access an instance of this class. If two or more threads must access or modify an instance of this class, you must use locks to limit the access.
All methods and properties on the Controller.Runtime.Status property are thread safe. You can call these methods and properties from two or more threads without interference.
All methods and properties on the Controller.Runtime.Status.Automatic property are thread safe. You can call these methods and properties from two or more threads without interference.
The StatusItemResults class is thread safe. You can access an instance of this class and its properties from two or more threads without interference.
Full Reference
For more information about the methods, properties, events, and constructors that are available for Status, refer to the lists that follow.
Controller.Runtime.Status Methods
Converts the data within a StatusItemResults object to use different units. How the data in a StatusItemResults object is converted depends on the Automation1 controller's configured parameters. See the ControllerDistanceUnit enum for information about how each unit type depends on configured parameters. For information about how to change configured parameters on the Automation1 controller, see the Controller.Configuration property in Configuration.
unitsToConvertTo
: The units to convert to.
resultstoConvert
: The results to convert.
Returns: A new StatusItemResults object, which contains data that has been converted to use a different set of units.
Returns the retrieved results for requested status items from the Automation1 controller. The retrieved status represents a moment in time. Retrieving status is not real-time and there is variable latency when you call this method. Construct a StatusItemConfiguration object and add status items to it to retrieve them from the Automation1 controller.
statusItemConfiguration
: What status items to retrieve from the Automation1 controller.
Returns: A StatusItemResults object that contains the results for the retrieved status items.
Controller.Runtime.Status.Automatic Properties
Gets or sets whether automatic status retrieval is paused. If automatic status retrieval is paused, the Controller.Runtime.Status.Automatic.NewStatusRetrieved event will not be raised.
Gets or sets the period (milliseconds) in which status should be retrieved from the Automation1 controller. This determines how often the Controller.Runtime.Status.Automatic.NewStatusRetrieved event is raised. The default value is 100 milliseconds.
Controller.Runtime.Status.Automatic Events
Raised when an exception occurs while trying to retrieve status from the Automation1 controller. See the ExceptionOccurredEventArgs.Exception property to see the exception that occurred. If this event is raised, status retrieval has been paused. To continue retrieving status, call the Controller.Runtime.Status.Automatic.Resume method.
Raised when new status is retrieved from the Automation1 controller. This event will not be raised while the controller is stopped or resetting, even if automatic status is not paused. It will continue to be raised when the controller is running again. By default, this event will retrieve common status items for each axis and task (see the Controller.Runtime.Status.Automatic.GetDefaultConfiguration method). But you can change the status item configuration by calling the Controller.Runtime.Status.Automatic.SetConfiguration method. To prevent this event from being raised, call the Controller.Runtime.Status.Automatic.Pause method.
Controller.Runtime.Status.Automatic Methods
Gets the status item configuration that is being used to retrieve status from the Automation1 controller. To change the status item configuration, see the Controller.Runtime.Status.Automatic.SetConfiguration method.
Returns: What status items are being retrieved from the Automation1 controller.
Gets the default status item configuration, which is used if you do not change the configuration through the Controller.Runtime.Status.Automatic.SetConfiguration method. This default status item configuration will retrieve common status items for each axis and task.
The default status item configuration configures the following axis status items
for each axis:
- AxisStatusItem.PositionCommand
- AxisStatusItem.PositionFeedback
- AxisStatusItem.PositionError
- AxisStatusItem.AuxiliaryFeedback
- AxisStatusItem.CurrentCommand
- AxisStatusItem.CurrentFeedback
- AxisStatusItem.CurrentError
- AxisStatusItem.ProgramPositionCommand
- AxisStatusItem.ProgramPositionFeedback
- AxisStatusItem.VelocityCommand
- AxisStatusItem.VelocityFeedback
- AxisStatusItem.VelocityError
- AxisStatusItem.AccelerationCommand
- AxisStatusItem.AccelerationFeedback
- AxisStatusItem.AccelerationError
- AxisStatusItem.DriveStatus
- AxisStatusItem.AxisStatus
- AxisStatusItem.AxisFault
The default status item configuration configures the following task status items
for each task:
- TaskStatusItem.ProgramLineNumber
- TaskStatusItem.MotionLineNumber
- TaskStatusItem.TaskStatus0
- TaskStatusItem.TaskStatus1
- TaskStatusItem.TaskStatus2
- TaskStatusItem.TaskMode
- TaskStatusItem.TaskState
- TaskStatusItem.TaskError
- TaskStatusItem.TaskWarning
- TaskStatusItem.ExecutionMode
- TaskStatusItem.Mfo
Returns: The default status item configuration.
Pauses retrieving status from the Automation1 controller until the Controller.Runtime.Status.Automatic.Resume method is called. If you pause status retrieval, this prevents the Controller.Runtime.Status.Automatic.NewStatusRetrieved event from being raised.
Resumes retrieving status from the Automation1 controller.
Sets the status item configuration that will be used to retrieve status from the Automation1 controller. If you change the configuration, this will change the results that are retrieved when the Controller.Runtime.Status.Automatic.NewStatusRetrieved event is raised.
statusItemConfiguration
: What status items to retrieve from the Automation1 controller.
StatusItemConfiguration Constructors
Constructs a new, empty StatusItemConfiguration object. Add status items to retrieve by using the System, Axis, and Task properties.
StatusItemConfiguration Properties
Gets the total number of all status items added to this configuration to be retrieved from an Automation1 controller.
StatusItemConfiguration Methods
Adds all the configured status items from another StatusItemConfiguration object to this configuration. This will update the Axis, Task, and System configurations.
otherStatusItemConfiguration
: The other StatusItemConfiguration object to add status items from.
Removes all of the status items from this configuration so they will not be retrieved from the Automation1 controller.
Adds an axis-based status item to be retrieved on a specific axis on the Automation1 controller.
axisStatusItem
: The axis-based status item to retrieve.
axisName
: The axis to retrieve the status item on.
Adds an axis-based status item to be retrieved on a specific axis on the Automation1 controller, with an optional argument for the status item. If you are not sure about the status item argument, do not use this overload.
axisStatusItem
: The axis-based status item to retrieve.
axisName
: The axis to retrieve the status item on.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Adds all of the configured axis-based status items from another AxisStatusItemConfigurationCollection object to this configuration.
otherAxisStatusItemConfiguration
: The other AxisStatusItemConfigurationCollection object to add status items from.
Removes all of the axis-based status items from this configuration so they will not be retrieved from the Automation1 controller.
Removes an axis-based status item from this configuration so it will not be retrieved from the Automation1 controller.
axisStatusItem
: The axis-based status item to remove.
axisName
: The axis that the status item was to be retrieved on.
Returns: True if the status item was found and removed. False if the status item was never added.
Removes an axis-based status item from this configuration so it will not be retrieved from the Automation1 controller.
axisStatusItem
: The axis-based status item to remove.
axisName
: The axis that the status item was to be retrieved on.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Returns: True if the status item was found and removed. False if the status item was never added.
Adds a task-based status item to be retrieved on a specific task on the Automation1 controller.
taskStatusItem
: The task-based status item to retrieve.
taskName
: The task to retrieve the status item on.
Adds a task-based status item to be retrieved on a specific task on the Automation1 controller, with an optional argument for the status item. If you are not sure about the status item argument, do not use this overload.
taskStatusItem
: The task-based status item to retrieve.
taskName
: The task to retrieve the status item on.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Adds all the configured task-based status items from another TaskStatusItemConfigurationCollection object to this configuration.
otherTaskStatusItemConfiguration
: The other TaskStatusItemConfigurationCollection object to add status items from.
Removes all the task-based status items from this configuration so they will not be retrieved from the Automation1 controller.
Removes a task-based status item from this configuration so it will not be retrieved from the Automation1 controller.
taskStatusItem
: The task-based status item to remove.
taskName
: The task that the status item was to be retrieved on.
Returns: True if the status item was found and removed. False if the status item was never added.
Removes a task-based status item from this configuration so it will not be retrieved from the Automation1 controller.
taskStatusItem
: The task-based status item to remove.
taskName
: The task that the status item was to be retrieved on.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Returns: True if the status item was found and removed. False if the status item was never added.
Adds a system-based status item to be retrieved from the Automation1 controller.
systemStatusItem
: The system-based status item to retrieve.
Adds a system-based status item to be retrieved from the Automation1 controller, with an optional argument for the status item. If you are not sure about the status item argument, do not use this overload.
systemStatusItem
: The system-based status item to retrieve.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Adds all of the configured system-based status items from another SystemStatusItemConfigurationCollection object to this configuration.
otherStatusItemSystemConfiguration
: The other SystemStatusItemConfigurationCollection object to add status items from.
Removes all the system-based status items from this configuration so they will not be retrieved from the Automation1 controller.
Removes a system-based status item from this configuration so it will not be retrieved from the Automation1 controller.
systemStatusItem
: The system-based status item to remove.
Returns: True if the status item was found and removed. False if the status item was never added.
Removes a system-based status item from this configuration so it will not be retrieved from the Automation1 controller.
systemStatusItem
: The system-based status item to remove.
argument: The argument for the status item. If you are not sure about this status item argument, do not use this overload.
Returns: True if the status item was found and removed. False if the status item was never added.
Adds an Industrial Ethernet mapping that you can retrieve from the Automation1 controller.
industrialEthernetMappingName
: The name of the Industrial Ethernet mapping to retrieve.
Adds an index of an Industrial Ethernet mapping array that you can retrieve from the Automation1 controller.
industrialEthernetMappingArrayName
: The name of the Industrial Ethernet mapping array to retrieve.
industrialEthernetMappingArrayIndex: The index in the Industrial Ethernet mapping array to retrieve.
Adds all of the configured Industrial Ethernet mappings from another IndustrialEthernetStatusItemConfigurationCollection
to this configuration.
otherIndustrialEthernetStatusItemConfiguration
: The other IndustrialEthernetStatusItemConfigurationCollection
to add status items from.
Removes all of the Industrial Ethernet mappings from this configuration so they will not be retrieved from the Automation1 controller.
Removes an Industrial Ethernet mapping from this configuration so it will not be retrieved from the Automation1 controller.
industrialEthernetMappingName
: The name of the Industrial Ethernet mapping to remove.
Returns: True if the Industrial Ethernet mapping was found and removed. False if the Industrial Ethernet mapping was never added.
Removes an index of an Industrial Ethernet mapping array from this configuration so it will not be retrieved from the Automation1 controller.
industrialEthernetMappingArrayName
: The name of the Industrial Ethernet mapping array to remove.
industrialEthernetMappingArrayIndex: The index of the Industrial Ethernet mapping array to remove.
Returns: True if the index of the Industrial Ethernet mapping array was found and removed. False if the index of the Industrial Ethernet mapping array was never added.