minute read
Tasks
You are reading our Automation1 API documentation for the .NET programming language.
In the .NET API, Tasks lets you interact with and manage Automation1 controller tasks.
The Basics
Each Automation1 controller has one or more tasks that execute AeroScript programs and AeroScript commands on the controller. Each task has a task name and a task index. Task indices start at 1. Task index 0 is reserved and cannot be used.
How to Use
In the .NET API, Tasks 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 do work with tasks. For more information about this property, see the Controller page.
To work with tasks in the .NET API, use the Controller.Runtime.Tasks property and index the task that you want to work with. A task can be specified by either task name or task index.
Refer to the example that follows.
controller.Runtime.Tasks[string taskName]
controller.Runtime.Tasks[int taskIndex]
You can get the status of a task to see if the task is running an AeroScript program or if there is an error on the task. Refer to the example that follows.
ControllerTaskStatus controllerTaskStatus = controller.Runtime.Tasks[string taskName].Status;
Each time that you access the Status property, you get a new status from the controller. For best results, access the Status property one time only to get the most current status. Then use the returned ControllerTaskStatus object until you need to get the most current status of the controller again. If you do not do this and try to access the Status property too many times, bugs known as race conditions can occur. These bugs occur when the status of the task changes between multiple accesses of the property.
Manage AeroScript Programs
You can use tasks in the .NET API to run AeroScript programs on controller tasks. This is one of two ways to command your Automation1 controller, with the other being Commands. Use the Program property on a task to manage AeroScript programs on the controller task. Refer to the example that follows.
controller.Runtime.Tasks[string taskName].Program.Run(string controllerFileName);
The Run method starts the execution of the AeroScript program, but it does not wait for the program to complete. The specified controller file can be either an AeroScript source file (.ascript) or a compiled AeroScript file (.a1exe). If the controller file is an AeroScript source file, then the file will be compiled before it is executed.
You can also specify a CompiledAeroScript object that you got from compiling AeroScript source with the Controller.Compiler property. See the Compiler page.
To determine if an AeroScript program is still running, get the task’s status. Then examine the TaskState property that returns the TaskState enum. The TaskState.ProgramRunning enum value will tell you if an AeroScript program is currently running on that task. The TaskState.ProgramComplete enum value will tell you if an AeroScript program completed successfully on that task. The TaskState.Error enum value will tell you if an AeroScript program failed with some type of error that you can examine with the Error property. Refer to the example that follows.
TaskState taskState = controller.Runtime.Tasks[string taskName].Status.TaskState;
ErrorInformation errorInformation = controller.Runtime.Tasks[string taskName].Error;
To stop an AeroScript program that is running, use the Stop method. Refer to the example that follows.
controller.Runtime.Tasks[string taskName].Program.Stop();
Handle AeroScript Application Messages
AeroScript programs that run on a controller task can use the AppMessage AeroScript functions to send information to a .NET custom application. Automation1 Studio also handles these AeroScript functions so you cannot use your custom application and Studio at the same time if you handle any AppMessage functions. To learn more, see the Application Message Functions page.
You can register for any of the AppMessage AeroScript functions with the AppMessage property. Each of the different AppMessage functions has its own property. When you register a handler for an AppMessage function, you must specify a delegate to a .NET method that will be invoked when the AppMessage AeroScript function is executed. Some AppMessage functions require a value to be returned to AeroScript, so your delegate will have to return a value too. You can register each AppMessage one time only. To change the registration of the AppMessage function, unregister the first handler. Then register the new second handler. Refer to the example that follows.
controller.Runtime.Tasks[string taskName].AppMessage.Box.Register(Func<AppMessageBoxArguments, int> handler);
controller.Runtime.Tasks[string taskName].AppMessage.Box.Unregister();
controller.Runtime.Tasks[string taskName].AppMessage.Display.Register(Action<AppMessageDisplayArguments> handler);
controller.Runtime.Tasks[string taskName].AppMessage.Display.Unregister();
Handle AeroScript Callbacks
AeroScript programs that run on a controller task can use the Callback() AeroScript function to send information to or to pass execution to a .NET custom application. When the Callback() function is executed from AeroScript, program execution on that task waits for any registered .NET callback handler to execute. The AeroScript program continues when the .NET callback handler completes. Each callback is identified by a unique identifier, which is a callback ID. This ID is used when you register for the callback and when you execute the Callback() AeroScript function. These handlers can be given data from AeroScript and return data back to AeroScript. To learn more, see the Callback Functions page.
Inputs into a .NET callback handler and outputs out of a .NET callback handler can be AeroScript integers, AeroScript reals, and AeroScript strings. AeroScript integers are 64-bit. They are represented in .NET by the long data type. AeroScript reals are double-precision floating-point numbers. They are represented in .NET by the double data type.
You can register for the Callback() AeroScript function with the Callback property. When you register a handler for the Callback() function, you must specify a delegate to a .NET method that will be invoked when the Callback() function is executed. The Callback() function requires values to be returned to AeroScript. Thus your delegate will have to return a value too. If you do not want to return any values, return empty arrays. You can register the Callback() function one time only. To change the registration of the Callback, unregister the first handler. Then register the new second handler. Refer to the example that follows.
controller.Runtime.Tasks[string taskName].Callback.Register(int callbackId, Func<ControllerTaskCallbackArguments, ControllerTaskCallbackReturn> handler);
controller.Runtime.Tasks[string taskName].Callback.Unregister(int callbackId);
Task Variables
In the .NET API, Task Variables lets you get and set task variables on a task on an Automation1 controller. You can use task variables to share information between iterations of a program running on the same task.
IMPORTANT: Task Variables are not under Tasks and are not accessible with the Controller.Runtime.Tasks property. Refer to Task Variables to learn how to use Task variables in the .NET API.
Thread Safety
All the methods and properties that operate under the Controller.Runtime.Tasks property are thread safe. You can call them from two or more threads without interference.
But because the .NET API is thread safe, that does not mean the controller can handle the operations. A single controller task can run only one AeroScript program at a time. You must synchronize or coordinate your process to prevent controller errors from occurring.
For Example
You can make a single .NET thread responsible for a single controller task.
Full Reference
For more information about the properties and methods that are available for Tasks, refer to the lists that follow.
Controller.Runtime.Tasks Properties
Gets the number of tasks on the Automation1 controller.
Gets the ControllerTask object for a specific task name.
Gets the numeric index of this task. You can use the numeric index to uniquely identify this task.
Gets the string name of this task. You can use the string name to uniquely identify this task.
Gets the current status for this task by returning a new ControllerTaskStatus object. That object represents a moment in time for this task.
Controller.Runtime.Tasks[].AppMessage Methods
Register for the app message box that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task. Returns the button that you clicked on the message box.
Unregisters for the app box message that an AeroScript program can raise on this task.
Register for the display app message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task.
Unregisters for the display app message that an AeroScript program can raise on this task.
Register for the display dismiss app message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task.
Unregisters for the display dismiss app message that an AeroScript program can raise on this task.
Register for the file open app message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task. Returns the file that you want to open.
Unregisters for the file open app message that an AeroScript program can raise on this task.
Register for the file save app message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task. Returns the file that you want to save.
Unregisters for the file save app message that an AeroScript program can raise on this task.
Register for the app input box message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task. Returns the text that you supplied as input to the message input box.
Unregisters for the app input box message that an AeroScript program can raise on this task.
Register for the app menu message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task. Returns the index of the option that you specified.
Unregisters for the app menu message that an AeroScript program can raise on this task.
Register for the app lamp message that an AeroScript program can raise on this task. You can register App messages one time only. To change the registration of an app message, you must unregister it. To do this, use the Unregister method.
handler: The code to execute when the app message is raised by an AeroScript program on this task.
Unregisters for the app lamp message that an AeroScript program can raise on this task.
Controller.Runtime.Tasks[].Callback Methods
Registers a callback that an AeroScript program can raise on this task. You can register to Callbacks one time only. To change the registration of a callback, you must unregister it. To do this, use the Unregister method.
callbackId: A number that uniquely identifies the callback per task.
handler: The code to execute when the callback is raised by an AeroScript program on this task.
Unregisters a callback.
Controller.Runtime.Tasks[].Debug Methods
Does one line of program execution on the AeroScript program that is currently paused on this task, stepping into all the function calls that occur. You can call this method only if an AeroScript program is loaded on this task and it is paused.
Does execution on the AeroScript program that is currently paused on this task, stepping out of the current function call. You can call this method only if an AeroScript program is loaded on this task and it is paused.
Does one line of program execution on the AeroScript program that is currently paused on this task, stepping over all the function calls that occur. You can call this method only if an AeroScript program is loaded on this task and it is paused.
Adds a breakpoint to an AeroScript source file at the line number that you specified. When AeroScript execution gets to the specified line number in the specified source file, the running program will pause. Breakpoints that you add to programs and static libraries are unique per task. Breakpoints that you add to dynamic libraries are the same across all tasks.
aeroScriptSourceFileName: The AeroScript source file to which you add a breakpoint.
lineNumber: The AeroScript source line number to which you add a breakpoint.
Removes all the breakpoints from an AeroScript source file.
aeroScriptSourceFileName: The AeroScript source file from which to remove all the breakpoints.
Returns the list of all the breakpoints that you added to an AeroScript source file.
aeroScriptSourceFileName: The AeroScript source file for which to get the breakpoints.
Returns: The list of AeroScript source line numbers that have breakpoints for the AeroScript source file on the specified task.
Removes a breakpoint from an AeroScript source file at the line number that you specified.
aeroScriptSourceFileName: The AeroScript source file from which to remove a breakpoint.
lineNumber: The AeroScript source line number from which to remove a breakpoint.
Controller.Runtime.Tasks[].Program Methods
Loads the specified controller file as an AeroScript program on this task. If the controller file is an AeroScript source file, it compiles before it executes. When the file is loading, this process does not also start the program. To begin program execution on this task, you must call the Start method. The AeroScript program must exist as a controller file on the Automation1 controller. See Controller.Files. You cannot load AeroScript libraries on a task. The controller file must be an AeroScript program. Thus it can be a source program file or a compiled program file.
controllerFileName: The controller file that is the AeroScript program you want to load on this task. The controller file can be a source program file or a compiled program file.
Loads a compiled AeroScript program on this task. When the program is loading, this process does not also start the program. To begin program execution on this task, you must call the Start method. To compile a program, see Controller.Compiler. You cannot load AeroScript libraries on a task. The CompiledAeroScript object must be a compiled AeroScript program.
compiledAeroScript: The compiled AeroScript program that you want to load on this task.
Pauses the AeroScript program that is currently running on this task and suspends program execution. This method waits indefinitely for the loaded program to pause. To continue program execution, call the Start method.
Pauses the AeroScript program that is currently running on this task and suspends program execution. This method waits for the quantity of time that you specified for the loaded program to pause. To continue program execution, call the Start method.
millisecondsTimeout: The number of milliseconds to wait before you pause the program on this task. If the program uses a quantity of time that is larger than this before it pauses, an exception is thrown.
Runs the specified controller file as an AeroScript program on this task. If the controller file is an AeroScript source file, it compiles before it executes. When a program runs, it automatically loads and begins to execute on this task. This method waits for the program to load and start. But it does not wait for the program to complete. The AeroScript program must exist as a controller file on the Automation1 controller. See Controller.Files. You cannot run AeroScript libraries on a task. The controller file must be an AeroScript program. Thus it can be a source program file or a compiled program file.
controllerFileName: The controller file that is the AeroScript program you want to run on this task. The controller file can be a source program file or a compiled program file.
Runs a compiled AeroScript program on this task. When a program runs, it automatically loads and begins to execute on this task. This method waits for the program to load and start. But it does not wait for the program to complete. To compile an AeroScript program source file, see Controller.Files. You cannot run AeroScript libraries on a task. The CompiledAeroScript object must be a compiled AeroScript program.
compiledAeroScript: The compiled AeroScript program that you want to run on this task.
Starts or continues the AeroScript program that is currently loaded on this task and begins program execution. This method waits for the loaded program to start. But it does not wait for the program to complete. To start or continue a program, you must load it onto this task. To load a program, call the Load method.
Stops the AeroScript program that is currently running on this task, terminating program execution. This method waits indefinitely for the loaded program to stop. This method also stops queue mode and buffered run mode. After a program is stopped, it is unloaded from the task.
Stops the AeroScript program that is currently running on this task, terminating program execution. This method will wait for the specified quantity of time for the loaded program to stop. This method will also stop queue mode and buffered run mode. After a program is stopped it is unloaded from the task.
millisecondsTimeout: The number of milliseconds to wait to stop the program on this task. If the program takes longer than this quantity of time to stop, an exception is thrown.
ControllerRuntime.Tasks[].Motion Methods
Enables retrace mode for the AeroScript program running on this task. When you enable retrace mode, the controller executes motion and motion-synchronized functions in reverse order through functions that were previously executed. The controller keeps a history of moves and synchronized commands that it can use for retrace.
Disables retrace mode for the AeroScript program running on this task. When you disable retrace mode, the controller executes forward through the retrace history until it moves to the program line where retrace was activated.
Enables the feedhold state on this task. When you enable the feedhold state, motion immediately decelerates, and program execution and immediate commands on this task stop.
Disables the feedhold state on this task. When you disable the feedhold state, motion on this task accelerates to the speed it was before feedhold was enabled. Program execution and immediate commands continue from where they were before the feedhold state was enabled.
Sets the MFO (manual feedrate override) percentage for this task, which scales the programmed feedrate for all coordinated motion and motion generated by the MoveRapid()
AeroScript function. The true feedrate of the move is calculated by multiplying the MFO percentage with the programmed feedrate. To get the current value of MFO for this task, use Status (ControllerRuntime.Status)
to retrieve TaskStatusItem.Mfo
.
mfoPercent
: The MFO percentage to set.
ControllerTaskStatus Properties
Gets the value of the task mode on the task.
Gets the state of execution for the task.
Gets the value for manual feedrate override (MFO) on the task.
Gets the name of the AeroScript source file for the program that is loaded or running on the task, or null if there is no program loaded or if there is no source file.
Gets the name of the compiled AeroScript file for the program that is loaded or running on the task, or null if there is no program loaded.
Gets the error on the task, if any. This will be null if there is no error.
Gets the warning on the task, if any. This will be null if there is no warning.