Files overview
Access the files of a CS8 or CS9 controller: FTP server of a real controller, or .controller file of a controller emulated by Staubli Robotics Suite. Connection, paths, /usr/usrapp and errors.
This page explains how the Staubli SDK accesses the files of a CS8 or CS9 controller, real or emulated by Staubli Robotics Suite: the connection, the paths and the errors. The file client controller.File uploads, downloads, lists and manages the files, and sends complete VAL 3 applications.
Real or emulated controller
The same methods work on both, with the same paths. Only the address changes.
Real controller
The file client uses the FTP server of the controller. Give its IP address, and the user and the password of the FTP server.
static void Main(){var parameters = new ConnectionParameters("192.168.0.254");// The file client is disabled by defaultparameters.File.Enable = true;// User and password of the FTP server of the controllerparameters.File.User = "default";parameters.File.Password = "default";var controller = new StaubliController();controller.Connect(parameters);// False with a real controller: the files go through FTPConsole.WriteLine(controller.File.IsSimulated);controller.Disconnect();}
Emulated controller
The emulator of Staubli Robotics Suite (SRS) has no FTP server. It keeps the files of the emulated controller in the folder of its .controller file, with the same tree as a real controller (usr, log). Give the path of the .controller file as address:
- Local path (
C:\...\MyCell\Controller1\Controller1.controller): the emulator runs on this PC. The SOAP client connects to127.0.0.1. - UNC path (
\\SRS-PC\share\...\Controller1\Controller1.controller): the emulator runs on another PC. The SOAP client connects to this PC, and the files go through the Windows share.
A path that is not a .controller file is refused. The SOAP port of the emulated controller is read from its configuration: see Test with the Staubli Robotics Suite emulator.
static void Main(){// Controller emulated by Staubli Robotics Suite on this PC: give its .controller file.// The SOAP client connects to 127.0.0.1, the file client uses the folder of the .controller file.var parameters = new ConnectionParameters(@"C:\SRS\MyCell\Controller1\Controller1.controller");// Emulator on another PC: give a UNC path. The SOAP client connects to this PC.// var parameters = new ConnectionParameters(@"\\SRS-PC\SRS\MyCell\Controller1\Controller1.controller");parameters.File.Enable = true;var controller = new StaubliController();controller.Connect(parameters);// True: the files are read and written in the folder of the .controller fileConsole.WriteLine(controller.File.IsSimulated);Console.WriteLine(controller.File.ControllerFolder);controller.Disconnect();}
IsSimulated tells which mode is used. With an emulated controller, ControllerFile gives the full path of the .controller file and ControllerFolder the folder of the files, and the user and the password are not used.
Connection parameters
| Parameter | Default | Meaning |
|---|---|---|
File.Enable | false | Connect the file client |
File.User | "default" | User of the FTP server of the controller |
File.Password | "default" | Password of this user |
File.Port | 21 | Port of the FTP server (FileConnectParameters.DEFAULT_PORT) |
File.TimeoutMs | 30000 | Timeout of the FTP connection and of the transfers, in ms |
Set Soap.Enable to false to use the file client alone. The SOAP parameters are on the page Connect to your robot.
Paths on the controller
The paths are the paths of the controller, with / as separator: /usr/usrapp/myApp/myApp.pjx. A path that does not start with / is relative to the root of the controller. With an emulated controller, the root is the folder of the .controller file: a path cannot go outside of it.
| Folder | Content |
|---|---|
/usr/usrapp | The VAL 3 applications, one sub-folder per application (FileClientBase.USER_APP_FOLDER) |
/usr/usrapp/myApp | The files of the application myApp: myApp.pjx, its programs and its data |
The project path Disk://myApp/myApp.pjx of the SOAP methods (LoadProject, StartApplication) is the file /usr/usrapp/myApp/myApp.pjx.
Standalone file client
FileClient connects without StaubliController. Its address is an IP or the path of a .controller file, as above.
static void Main(){var files = new FileClient();// Real controller: IP, FTP user and password (port 21 by default)files.Connect("192.168.0.254", "default", "default");// Or the .controller file of a controller emulated by Staubli Robotics Suite (the user and the password are not used)// files.Connect(@"C:\SRS\MyCell\Controller1\Controller1.controller", null, null);foreach (FileItem item in files.GetListing("/usr/usrapp"))Console.WriteLine(item.Name);files.Disconnect();}}
Errors
parameters.File.Enable = true;var controller = new StaubliController();try{controller.Connect(parameters);byte[] content = controller.File.DownloadBytesFromController("/usr/usrapp/myApp/myApp.pjx");}catch (FileException ex){// Connection refused, file not found, or operation refused by the controllerConsole.WriteLine(ex.Message);// FTP reply of the controller, 0 and null when there is noneConsole.WriteLine($"{ex.RemotePath} {ex.ReplyCode} {ex.ReplyMessage}");}catch (DirectoryNotFoundException ex){// The address is a folder that does not existConsole.WriteLine(ex.Message);}controller.Disconnect();}
| Exception | When |
|---|---|
FileException | The FTP connection failed, the file does not exist, or the controller refused the operation |
ArgumentException | The address is a path but not a .controller file, or a path goes outside of its folder |
FileNotFoundException | The .controller file does not exist |
InvalidOperationException | A method is called before the connection, or after Disconnect |
When the FTP connection fails, the message of FileException also reminds that an emulated controller needs the path of its .controller file. ReplyCode and ReplyMessage give the reply of the FTP server of the controller, when there is one. The errors of the local files of your PC (for example a local file that does not exist) are not converted.
Reference
Methods of FileClientBase :// Creates a folder on the controller, with its parent folders when they do not exist. Nothing is done when the folder exists.void CreateDirectory(string path);// Deletes a folder of the controller and all its contentvoid DeleteDirectory(string path);// Deletes a file of the controllervoid DeleteFile(string path);// Checks if a folder exists on the controllerbool DirectoryExists(string path);// Disconnects the clientvoid Disconnect();// Downloads a file of the controller and returns its contentbyte[] DownloadBytesFromController(string remotePath, OnProgressDelegate progress = null);// Downloads a file of the controller to a local file. The local file is replaced when it exists, and its folder is created when it does not exist.void DownloadFileFromController(string localPath, string remotePath, OnProgressDelegate progress = null);// Downloads a file of the controller and writes its content to a streamvoid DownloadStreamFromController(Stream stream, string remotePath, OnProgressDelegate progress = null);// Checks if a file exists on the controllerbool FileExists(string path);// Gets information about a file or a folder of the controllerFileItem GetFileInfo(string path);// Lists the files and folders of a folder of the controllerFileItem[] GetListing(string path);// Renames or moves a file or a folder of the controllervoid Rename(string path, string newPath);// Uploads a complete VAL 3 application to the controller. The local folder of the application, named as the application and with its project file inside (for example C:\MyApps\myApp\myApp.pjx), is copied with its sub-folders to "/usr/usrapp/myApp" (FileClientBase.USER_APP_FOLDER). When the application already exists on the controller, its folder is deleted first: the files that are not in the local folder are removed. Stop and unload the application before (robot.Soap.StopAndUnloadAll()), then load it after (robot.Soap.LoadProject("Disk://myApp/myApp.pjx")).string UploadApplicationToController(string localAppFolder, OnProgressDelegate progress = null);// Uploads data as a file to the controller. The file of the controller is replaced when it exists.void UploadBytesToController(byte[] data, string remotePath, bool createRemoteDir = false, OnProgressDelegate progress = null);// Uploads a local file to the controller. The file of the controller is replaced when it exists.void UploadFileToController(string localPath, string remotePath, bool createRemoteDir = false, OnProgressDelegate progress = null);// Uploads the content of a stream as a file to the controller, from the current position of the stream to its end. The file of the controller is replaced when it exists.void UploadStreamToController(Stream stream, string remotePath, bool createRemoteDir = false, OnProgressDelegate progress = null);
Every method also exists in an asynchronous version, with the same name followed by Async and an optional CancellationToken.
Upload, download, listing and management of the files of the controller. With a real controller, the files are accessed through the FTP server of the controller. With a controller emulated by Staubli Robotics Suite, there is no FTP server: give the path of its .controller file as address. The files are accessed in the folder of this file, which has the same tree. The paths are the same in both cases (for example "/usr/usrapp/myApp/myApp.pjx"). A path that does not start with "/" is relative to the root of the controller. The VAL 3 applications are in the folder "/usr/usrapp" of the controller (USER_APP_FOLDER): one sub-folder per application, named as the application, that contains the project file (myApp.pjx) and the other files of the application.
| Member | Type | Description |
|---|---|---|
ControllerFile Property read only | string | Full path of the .controller file of the controller emulated by Staubli Robotics Suite. Null with a real controller. |
ControllerFolder Property read only | string | Full path of the folder of the .controller file: root of the files of the emulated controller. Null with a real controller. |
Enabled Property read only | bool | True when the client is connected |
Ip Property read only | string | IP or host name of the controller. Null with an emulated controller. |
IsSimulated Property read only | bool | True when the files are accessed in the folder of the .controller file of a controller emulated by Staubli Robotics Suite, false when they are accessed through FTP |
Port Property read only | int | Port of the FTP server of the controller. 0 with an emulated controller. |
USER_APP_FOLDER Field | string | Folder of the VAL 3 applications on the controller. Each application is in a sub-folder named as the application (for example "/usr/usrapp/myApp/myApp.pjx"). The project path "Disk://myApp/myApp.pjx" of robot.Soap.LoadProject(...) is this file. |
CreateDirectory(string) Method | void | Creates a folder on the controller, with its parent folders when they do not exist. Nothing is done when the folder exists.
|
DeleteDirectory(string) Method | void | Deletes a folder of the controller and all its content
|
DeleteFile(string) Method | void | Deletes a file of the controller
|
DirectoryExists(string) Method | bool | Checks if a folder exists on the controller
|
Disconnect() Method | void | Disconnects the client |
DownloadBytesFromController(string, OnProgressDelegate) Method | byte[] | Downloads a file of the controller and returns its content
|
DownloadFileFromController(string, string, OnProgressDelegate) Method | void | Downloads a file of the controller to a local file. The local file is replaced when it exists, and its folder is created when it does not exist.
|
DownloadStreamFromController(Stream, string, OnProgressDelegate) Method | void | Downloads a file of the controller and writes its content to a stream
|
FileExists(string) Method | bool | Checks if a file exists on the controller
|
GetFileInfo(string) Method | FileItem | Gets information about a file or a folder of the controller
|
GetListing(string) Method | FileItem[] | Lists the files and folders of a folder of the controller
|
Rename(string, string) Method | void | Renames or moves a file or a folder of the controller
|
UploadApplicationToController(string, OnProgressDelegate) Method | string | Uploads a complete VAL 3 application to the controller. The local folder of the application, named as the application and with its project file inside (for example C:\MyApps\myApp\myApp.pjx), is copied with its sub-folders to "/usr/usrapp/myApp" ( USER_APP_FOLDER). When the application already exists on the controller, its folder is deleted first: the files that are not in the local folder are removed. Stop and unload the application before (robot.Soap.StopAndUnloadAll()), then load it after (robot.Soap.LoadProject("Disk://myApp/myApp.pjx")).
|
UploadBytesToController(byte[], string, bool, OnProgressDelegate) Method | void | Uploads data as a file to the controller. The file of the controller is replaced when it exists.
|
UploadFileToController(string, string, bool, OnProgressDelegate) Method | void | Uploads a local file to the controller. The file of the controller is replaced when it exists.
|
UploadStreamToController(Stream, string, bool, OnProgressDelegate) Method | void | Uploads the content of a stream as a file to the controller, from the current position of the stream to its end. The file of the controller is replaced when it exists.
|
Each method also exists in an asynchronous version, with the same name followed by Async and an optional cancellation token.
Connection parameters of the file client (robot.File). With a real controller, the files are accessed through the FTP server of the controller, with the user and the password of these parameters. With a controller emulated by Staubli Robotics Suite, give the path of its .controller file as address: the files are accessed in the folder of this file.
| Member | Type | Description |
|---|---|---|
FileConnectParameters() Constructor | ||
Enable Property | bool | Should use this service (default: false) |
DEFAULT_PORT Field | int | Default port of the FTP server |
DEFAULT_TIMEOUT_MS Field | int | Default timeout of the FTP connection and of the transfers, in milliseconds |
Base class for the connection parameters of the file client
| Member | Type | Description |
|---|---|---|
FileConnectParametersBase() Constructor | ||
Password Property | string | Password of the user (default: default). Not used with a controller emulated by Staubli Robotics Suite. |
Port Property | int | Port of the FTP server of the controller (default: 21) |
TimeoutMs Property | int | Timeout of the FTP connection and of the transfers, in milliseconds (default: 30000) |
User Property | string | User of the FTP server of the controller (default: default). Not used with a controller emulated by Staubli Robotics Suite. |
Exception thrown when an operation on the files of the controller fails: the controller refused it, the file does not exist, or the communication failed. The message gives the reason and, when it is known, what to do.
| Member | Type | Description |
|---|---|---|
RemotePath Property read only | string | Path of the file or folder on the controller concerned by the operation. Null when the operation has no path. |
ReplyCode Property read only | int | FTP reply code returned by the controller (for example 550). 0 when the controller did not reply, and with an emulated controller. |
ReplyMessage Property read only | string | Reply text returned by the controller. Null when the controller did not reply, and with an emulated controller. |