minute read
Controller
You are reading our Automation1 API documentation for the C programming language.
The Basics
The C API revolves around the Automation1Controller handle. All interaction with an Automation1 controller occurs through an instance of this handle. To start using the C API, you must connect to an Automation1 controller to get an instance of an Automation1Controller handle. Then the C functions that are prefixed with Automation1_ in Automation1.h will give you access to the different features on the Automation1 controller.
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.
IMPORTANT: Most Automation1 C functions require the controller to be running.
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:
- To connect to a local controller, call the Automation1_Connect() function.
- To connect to a remote PC-based controller or a remote drive-based controller, call the Automation1_ConnectWithHost() function.
- To connect to a drive-based controller that is plugged into your computer over USB, call the Automation1_ConnectWithUsb() function.
Each connection type gives you an Automation1Controller handle.
bool Automation1_Connect(Automation1Controller* controllerOut);
bool Automation1_ConnectWithHost(const char* host, Automation1Controller* controllerOut);
bool Automation1_ConnectWithUsb(Automation1Controller* controllerOut);
When you are done interacting with the controller, call the Automation1_Disconnect() function.
Most Automation1 C functions require the controller to be running. The documentation for each feature tells you if the controller must be running.
To see if the controller is running, use the Automation1_Controller_IsRunning() function. If the controller is not currently running, you can start it by using the Automation1_Controller_Start() function.
bool Automation1_Controller_IsRunning(Automation1Controller controller, bool* isRunningOut);
bool Automation1_Controller_Start(Automation1Controller controller);
To get information about the controller to which you are connected, use the functions that follow:
bool Automation1_Controller_Name(Automation1Controller controller, char* nameOut, int32_t nameLength);
bool Automation1_Controller_SerialNumber(Automation1Controller controller, char* serialNumberOut, int32_t serialNumberLength);
Example Code
// Declare the handle for the controller and the axis index of axis X.
Automation1Controller controller = NULL;
int32_t axisX = 0;
// Connect to the iSMC that is installed on this PC. You can specify an IP address to connect to a remote controller.
// Pass the address of the controller handle to populate it for future function calls.
if (!Automation1_Connect(&controller)) { /* handle error */ }
// Start the Automation1 controller to which you are connected. Do this to make sure the controller is running.
if (!Automation1_Controller_Start(controller)) { /* handle error */ }
// Because the controller is running, you can execute commands.
if (!Automation1_Command_Enable(controller, 1, &axisX, 1)) { /* handle error */ }
// Disconnect from the controller when you are done interacting with it.
// When you disconnect the controller, this process does not stop the controller. The controller continues to run.
// You must disconnect to free your memory.
if (!Automation1_Disconnect(controller)) { /* handle error */ }
// Set the controller handle to null because it is not valid after you disconnect from the controller.
controller = NULL;
Error Handling
All the C API functions return a bool result that lets you know if the function was successful. You must examine the bool result of each function call to make sure that no error occurred. If an error does occur, you can use the Automation1_GetLastError() and the Automation1_GetLastErrorMessage() functions to get more information about it.
int32_t Automation1_GetLastError();
void Automation1_GetLastErrorMessage(char* errorMessageOut, int32_t errorMessageMaxLength);
The Automation1_GetLastError() function gives you the error number of the last error that occurred on the C thread that is currently executing.
The Automation1_GetLastErrorMessage() function gives you the string error message of the last error that occurred on the C thread that is currently executing.
C API errors are stored separately for each C thread. Each C thread tracks errors separately in the C API. You cannot get the C API error for one thread from a different thread.
A successful function call does not clear the last error. New errors will overwrite the previous errors.
Errors have error types that help keep similar errors together. In other APIs, these error types become exceptions. But in the C API, there are separate functions that you can use to determine the specific type of an error that occurs.
IMPORTANT: Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific.
For Example
Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
See the Errors and Error Handling section in C API Guidelines for more information.
Example Code
Automation1Controller controller;
if (!Automation1_Connect(&controller))
{
int32_t lastError = Automation1_GetLastError();
char lastErrorMessage[2048];
Automation1_GetLastErrorMessage(lastErrorMessage, 2048);
// Print or log the error, clean up, change your process, etc.
}
Machine Controller Definition Files
Machine Controller Definition (MCD) files are files that 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 Machine Controller Definition (MCD) files from the C API.
bool Automation1_Controller_DownloadMcdToFile(Automation1Controller controller, const char* mdkFilePathToMcd, bool shouldIncludeFiles, bool shouldIncludeConfiguration);
bool Automation1_Controller_UploadMcdToController(Automation1Controller controller, const char* mdkFilePathToMcd, bool shouldIncludeFiles, bool shouldIncludeConfiguration, bool eraseController);
For more information, see the Machine Controller Definition Files page.
Thread Safety
The Automation1_Connect functions are thread safe. You can call them from two or more threads without interference.
The Automation1Controller handle is thread safe. But some of the functions that accept this handle are not thread safe. Read the thread safety documentation for each C API function.
The Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions are thread safe. C API errors are stored separately for each C thread. Each C thread tracks errors separately in the C API.
The Automation1_Disconnect() function is not thread safe. Use only one thread to call this function for a single Automation1Controller handle.
The Automation1_Controller_Start(), Automation1_Controller_Stop(), and Automation1_Controller_Reset() functions are not thread safe. Only one thread at a time can call these functions. If it is necessary for two or more threads to call these functions, you must use locks to limit the access.
The Automation1_Controller_DownloadMcdToFile() and Automation1_Controller_UploadMcdToController() functions are not thread safe. Only one thread at a time can call these functions. If it is necessary for two or more threads to call these functions, you must use locks to limit the access.
All the other Automation1_Controller_ functions are thread safe. You can call them from two or more threads without interference.
Full Reference
For more information about the functions that are available for Controller, refer to the list that follows.
Functions
Connects to an Automation1 controller. Use this function to connect to a controller when the controller is installed on the same computer and has access control disabled. Make sure to call the Automation1_Disconnect() function to prevent memory from leaking when you are done with the controller.
controllerOut
(Out): A handle that represents a connection to an Automation1 controller. Use this handle only if the function call was successful.
Returns: True if the connection was successful. False if the connection was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Connects to an Automation1 drive-based controller that is connected to the same Windows computer over USB. Use this function to connect to a controller when the drive-based controller is connected to the same Windows computer over USB. Make sure to call the Automation1_Disconnect() function to prevent memory from leaking when you are done with the controller.
controllerOut
(Out): A handle that represents a connection to an Automation1 controller. Use this handle only if the function call was successful.
Returns: True if the connection was successful. False if the connection was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Connects to an Automation1 controller that is running on the specified host. Use this function to connect to a controller when the controller is installed on a different computer and has access control disabled.
host
(In): The null-terminated host name or host IP address of the Automation1 controller to which you want to connect.
controllerOut
(Out): A handle that represents a connection to an Automation1 controller. Use this handle only if the function call was successful.
Returns: True if the connection was successful. False if the connection was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Connects to an Automation1 controller and uses the specified user name and password.
userName
(In): The null-terminated user name for a user that has access to the Automation1 controller.
password
(In): The null-terminated password for the specified user.
controllerOut
(Out): A handle that represents a connection to an Automation1 controller. Use this handle only if the function call was successful.
Returns: True if the connection was successful. False if the connection was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Connects to an Automation1 controller that is running on the specified host and uses the specified user name and password. Use this overload to log in to a controller when the controller is installed on a different computer and has access control enabled. Make sure to call the Automation1_Disconnect() function to prevent memory from leaking when you are done with the controller.
host
(In): The null-terminated host name or host IP address of the Automation1 controller to which you want to connect.
userName
(In): The null-terminated user name for a user that has access to the Automation1 controller.
password
(In): The null-terminated password for the specified user.
controllerOut
(Out): A handle that represents a connection to an Automation1 controller. Use this handle only if the function call was successful.
Returns: True if the connection was successful. False if the connection was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Disconnects from the Automation1 controller. This process does not change the running state of the Automation1 controller. If the controller has started and is running, it will stay running. After you call this function, you cannot continue to use this controller handle.
controller
(In): The controller from which to disconnect.
Returns: True if you successfully disconnected from the controller. False if you did not disconnect from the controller. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Starts the Automation1 controller if it is not currently running. When you connect to the Automation1 controller, this process does not change the running state of the controller. Thus, use this function to start the controller after you connect to it. If the controller is currently running, this function does not have an effect. You can examine the state of the Automation1 controller by calling the Automation1_Controller_IsRunning() function.
controller
(In): The controller to start.
Returns: True if the controller successfully started. False if the controller did not start. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Stops the Automation1 controller if it is currently running. If the controller is currently stopped, this function does not have an effect. You will stay connected to the Automation1 controller after you stop it from running. When you stop the Automation1 controller, this process does not change your connection.
controller
(In): The controller to stop.
Returns: True if the controller was successfully stopped. False if the controller was not stopped. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Resets the Automation1 controller by putting the Automation1 controller into a fresh state and performing any initialization. The Automation1 controller will not be available while the reset is in progress.
controller
(In): The controller to reset.
Returns: True if the controller successfully reset. False if the controller did not reset. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets information about whether or not the Automation1 controller has started and is currently running. For example, the controller might be running AeroScript programs or performing motion. If the controller is running, you can safely execute commands on the controller, run programs, and so on.
controller
(In): The controller to examine.
isRunningOut
(Out): Whether or not the controller is currently running. Use this only if the function call was successful.
Returns: True if the function got the state of the controller. False if the function did not get the state of the controller. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets the number of axes that are available on the connected Automation1 controller. Different Automation1 controllers will have a different supported axis count.
controller
(In): The connected controller to query.
Returns: The number of axes that are available on the connected Automation1 controller.
Gets the number of tasks that are available on the connected Automation1 controller. Different Automation1 controllers will have a different supported task count.
controller
(In): The connected controller to query.
Returns: The number of tasks that are available on the connected Automation1 controller.
Gets the corresponding axis index of the specified axis name on the connected Automation1 controller.
controller
(In): The connected controller to query.
axisName
(In): The null-terminated name of the axis that will have its index retrieved.
axisIndexOut
(Out): The index of the axis that corresponds to the specified axis name. Use this argument only if the function call was successful. This argument must have memory preallocated before you pass it into this function.
Returns: True if the function got the axis index that corresponds to the specified axis name. False if the function did not get the axis index that corresponds to the specified axis name. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets the task index that corresponds to the specified task name on the connected Automation1 controller.
controller
(In): The connected controller to query.
taskName
(In): The null-terminated name of the task that will have its index retrieved.
taskIndexOut
(Out): The index of the task that corresponds to the specified task name. Use this argument only if the function call was successful. This argument must have memory preallocated before you pass it into this function.
Returns: True if the function got the task index that corresponds to the specified task name. False if the function did not get the task index that corresponds to the specified task name. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets the name of the connected Automation1 controller.
controller
(In): The connected controller to query.
nameOut
(Out): A character array in which to store the controller name. This argument must have memory preallocated before you pass it into this function.
nameLength
(Out): The maximum number of elements to copy into the nameOut argument. This number must not be greater than the length of the nameOut
array.
Returns: True if the function got the name of the controller. False if the function did not get the name of the controller. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets the serial number of the connected Automation1 controller.
controller
(In): The connected controller to query.
serialNumberOut
(Out): A character array in which to store the serial number. This argument must have memory preallocated before you pass it into this function.
serialNumberLength
(Out): The maximum number of elements to copy into the serialNumberOut argument. This number must not be greater than the length of the serialNumberOut
array.
Returns: True if the function got the serial number of the controller. False if the function did not get the serial number of the controller. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Downloads a Machine Controller Definition (.mcd) file from the controller and saves it to the specified MDK file path. A downloaded machine controller definition file can contain controller configuration and controller files. To copy this controller's configuration and files, you can upload this file to any controller. When you use this function, a minimum of one of these parameters must be true - shouldIncludeFiles
and shouldIncludeConfiguration
.
controller
(In): The controller from which to get the Machine Controller Definition file.
mdkFilePathToMcd
(In): The MDK file path to which you save the downloaded Machine Controller Definition file.
shouldIncludeFiles
(In): Whether or not controller files are included in the download.
shouldIncludeConfiguration
(In): Whether or not controller configuration is included in the download.
Returns: True if the controller operation was successful. False if the controller operation was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Uploads the Machine Controller Definition (.mcd) file to the controller from the specified MDK file path. When you use this function, a minimum of one of the these parameters must be true - shouldIncludeFiles
and shouldIncludeConfiguration
. Before you call this function, make sure there is no important data on the controller that can be overwritten or erased. Before you upload a new Machine Controller Definition file that might overwrite the existing data, it is recommended that you download the current Machine Controller Definition file as a backup copy.
controller
(In): The controller to which you upload the Machine Controller Definition file.
mdkFilePathToMcd
(In): The MDK file path of the Machine Controller Definition file to upload.
shouldIncludeFiles
(In): Whether or not controller files are included in the upload.
shouldIncludeConfiguration
(In): Whether or not controller configuration is included in the upload.
eraseController
(In): Whether or not the controller is erased before you upload the new files. When set to true, this operation does a restoration of the controller.
Returns: True if the controller operation was successful. False if the controller operation was not successful. See the Automation1_GetLastError() and Automation1_GetLastErrorMessage() functions for more information. You can find information about these functions in the Errors and Error Handling section of C API Guidelines.
Gets the version of the Automation1 C API.
majorVersionOut
(Out): The major version of the API.
minorVersionOut
(Out): The minor version of the API.
patchVersionOut
(Out): The patch version of the API.
Gets the last Automation1 error number that occurred on the calling thread. Subsequent Automation1 C API function calls that are executing on the same thread might change this value. Make sure that the function call succeeded. If it did not succeed, call this function immediately.
Returns: A number that represents an Automation1 error.
Gets a human-readable error message that corresponds to the last Automation1 error that occurred on the calling thread. Subsequent Automation1 C API function calls that are executing on the same thread might change this value. Make sure that the function call succeeded. If it did not succeed, call this function immediately.
errorMessageOut
(Out): A character array in which to store the human-readable error message. This argument must have memory preallocated before you pass it into this function.
errorMessageMaxLength
(In): The maximum number of elements to copy into the errorMessageOut argument. This number must not be greater than the length of the errorMessageOut
array.
Examines the Automation1 error number that was passed in to see if it qualifies as a Controller error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a Controller error type. False if the error number does not qualify as a Controller error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerArgument error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if the error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerArgument error type. False if the error number does not qualify as a ControllerArgument error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerOperation error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if the error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerOperation error type. False if the error number does not qualify as a ControllerOperation error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerAxisAbort error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerAxisAbort error type. False if the error number does not qualify as a ControllerAxisAbort error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerAxisFault error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerAxisFault error type. False if the error number does not qualify as a ControllerAxisFault error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerCommunication error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerCommunication error type. False if the error number does not qualify as a ControllerCommunication error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerDisconnected error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerDisconnected error type. False if the error number does not qualify as a ControllerDisconnected error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerState error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerState error type. False if the error number does not qualify as a ControllerState error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerStopped error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerStopped error type. False if the error number does not qualify as a ControllerStopped error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerInternal error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerInternal error type. False if the error number does not qualify as a ControllerInternal error type.
Examines the Automation1 error number that was passed in to see if it qualifies as a ControllerUser error type. Automation1 error types are hierarchical. You must handle them in the correct order, which is most specific to least specific. For Example: Make sure that you examine the error number to see if an error is a ControllerCommunication error type before you examine it to see if the error is a Controller error type.
errorNumber
(In): The Automation1 error number to examine.
Returns: True if the error number qualifies as a ControllerUser error type. False if the error number does not qualify as a ControllerUser error type.