UnderAutomation
Une question ?

[email protected]

Contactez-nous
UnderAutomation
⌘Q
This page is only available in English.

SSH Linux commands

Remote execute Linux command lines on the robot controller.

  • Remote execute Linux commands
  • Default credentials
  • Enable SSH access
  • Remote start a shell
  • Try it with the Windows example
  • API reference

SSH is a protocol that allows you to remotly execute Linux command lines robot controller.

This feature is made possible because an embedded Linux is running in the robot.

You can also use this library to remote manipulate files over SSH, see the SFTP documentation.

Remote execute Linux commands

SSH features are not enabled by default when connecting to the robot. You must enable it and specify the Linux user name and password. If these credentials are not specified, the user is "ur" and the password "easybot".

To do this set the Ssh.EnableSSh property in ConnectParameters class.

Please then refer to the API reference below which lists all the available file and folder handling features.

If you wish to manipulate files outside of any instance of the UR object, you can create an instance of class Ssh.SshClient which has the same functions.

The RunCommand method allows you to synchronously execute a command and wait for its response.

Default credentials

  • Default user on a real robot : root

  • Default user on the simulator : ur

  • Default password : easybot

Enable SSH access

You may need to enable access on the robot. In Polyscope, navigate to Settings > Security > Secure Shell and ensure that SSH access is enabled.

using UnderAutomation.UniversalRobots;
using UnderAutomation.UniversalRobots.Ssh.Tools;
class SshRunCommand
{
static void Main(string[] args)
{
// Create a new robot instance
var robot = new UR();
// Setup connection to th robot
var param = new ConnectParameters();
param.IP = "192.168.0.1";
// Enable SSH
param.Ssh.EnableSftp = true;
// If not specified, credentials are "ur" with password "easybot"
param.Ssh.Username = "John";
param.Ssh.Password = "!!PASS!!";
// Connect to the robot
robot.Connect(param);
// Create a execute the command
SshCommand command = robot.Ssh.RunCommand("echo Hello > /home/ur/Desktop/NewFile.txt");
// Get result
string result = command.Result; // console output
int exitStatus = command.ExitStatus; // exit status
}
}

Remote start a shell

The creation of a shell allows to maintain a session and to have a working directory, like in a terminal. The method CreateShellStream allows to create a shell. It takes as parameter a window size. An event DataReceived is raised when the console outputs text.

using UnderAutomation.UniversalRobots;
using UnderAutomation.UniversalRobots.Ssh.Tools;
using UnderAutomation.UniversalRobots.Ssh.Tools.Common;
class SshCreateShell
{
static void Main(string[] args)
{
// Create a new robot instance
var robot = new UR();
// Setup connection to th robot
var param = new ConnectParameters();
param.IP = "192.168.0.1";
// Enable SSH
param.Ssh.EnableSsh = true;
// If not specified, credentials are "ur" with password "easybot"
param.Ssh.Username = "John";
param.Ssh.Password = "!!PASS!!";
// Connect to the robot
robot.Connect(param);
// Create a shell and specify its size
ShellStream shell = robot.Ssh.CreateShellStream("My super app", 40, 100, 40, 100, 1000);
shell.DataReceived += Shell_DataReceived;
shell.WriteLine("ping 192.168.0.10");
}
private static void Shell_DataReceived(object sender, ShellDataEventArgs e)
{
// New shell line from the robot
string dataReceived = e.Line;
}
}

Try it with the Windows example

SSH

API reference

Class
SshClientinherits SshClientBase
C#Python

Provides a client connection to SSH server

MemberTypeDescription
SshClient()
Constructor
Connect(string, string, string, int)
Method
void
Connects to the robot
  • ip : Robot IP address
  • username : Robot linux username (default username is ur for simulator and root for real robot)
  • password : Associated user password (default is easybot)
  • port : SSH port
Class
ShellStreaminherits Stream
C#Python

Contains operation for working with SSH Shell.

MemberTypeDescription
CanRead
Property
read only
bool
Gets a value indicating whether the current stream supports reading.
CanSeek
Property
read only
bool
Gets a value indicating whether the current stream supports seeking.
CanWrite
Property
read only
bool
Gets a value indicating whether the current stream supports writing.
DataAvailable
Property
read only
bool
Gets a value that indicates whether data is available on the ShellStream to be read.
Length
Property
read only
long
Gets the length in bytes of the stream.
Position
Property
long
Gets or sets the position within the current stream.
DataReceived
Event
EventHandler<ShellDataEventArgs>
Occurs when data was received.
ErrorOccurred
Event
EventHandler<ExceptionEventArgs>
Occurs when an error occurred.
BeginExpect(AsyncCallback, object, params ExpectAction[])
Method
IAsyncResult
Begins the expect.
  • callback : The callback.
  • state : The state.
  • expectActions : The expect actions.
BeginExpect(AsyncCallback, params ExpectAction[])
Method
IAsyncResult
Begins the expect.
  • callback : The callback.
  • expectActions : The expect actions.
BeginExpect(TimeSpan, AsyncCallback, object, params ExpectAction[])
Method
IAsyncResult
Begins the expect.
  • timeout : The timeout.
  • callback : The callback.
  • state : The state.
  • expectActions : The expect actions.
BeginExpect(params ExpectAction[])
Method
IAsyncResult
Begins the expect.
  • expectActions : The expect actions.
Dispose(bool)
Method
void
Releases the unmanaged resources used by the Stream and optionally releases the managed resources.
  • disposing : true to release both managed and unmanaged resources; false to release only unmanaged resources.
EndExpect(IAsyncResult)
Method
string
Ends the execute.
  • asyncResult : The async result.
Expect(string)
Method
string
Expects the expression specified by text.
  • text : The text to expect.
Expect(string, TimeSpan)
Method
string
Expects the expression specified by text.
  • text : The text to expect.
  • timeout : Time to wait for input.
Expect(Regex)
Method
string
Expects the expression specified by regular expression.
  • regex : The regular expression to expect.
Expect(Regex, TimeSpan)
Method
string
Expects the expression specified by regular expression.
  • regex : The regular expression to expect.
  • timeout : Time to wait for input.
Expect(TimeSpan, params ExpectAction[])
Method
void
Expects the specified expression and performs action when one is found.
  • timeout : Time to wait for input.
  • expectActions : The expected expressions and actions to perform, if the specified time elapsed and expected condition have not met, that method will exit without executing any action.
Expect(params ExpectAction[])
Method
void
Expects the specified expression and performs action when one is found.
  • expectActions : The expected expressions and actions to perform.
Flush()
Method
void
Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
Read()
Method
string
Reads text available in the shell.
Read(byte[], int, int)
Method
int
Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
  • buffer : An array of bytes. When this method returns, the buffer contains the specified byte array with the values between offset and (offset + count - 1) replaced by the bytes read from the current source.
  • offset : The zero-based byte offset in buffer at which to begin storing the data read from the current stream.
  • count : The maximum number of bytes to be read from the current stream.
ReadLine()
Method
string
Reads the line from the shell. If line is not available it will block the execution and will wait for new line.
ReadLine(TimeSpan)
Method
string
Reads a line from the shell. If line is not available it will block the execution and will wait for new line.
  • timeout : Time to wait for input.
Seek(long, SeekOrigin)
Method
long
This method is not supported.
  • offset : A byte offset relative to the origin parameter.
  • origin : A value of type SeekOrigin indicating the reference point used to obtain the new position.
SetLength(long)
Method
void
This method is not supported.
  • value : The desired length of the current stream in bytes.
Write(byte[], int, int)
Method
void
Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
  • buffer : An array of bytes. This method copies count bytes from buffer to the current stream.
  • offset : The zero-based byte offset in buffer at which to begin copying bytes to the current stream.
  • count : The number of bytes to be written to the current stream.
Write(string)
Method
void
Writes the specified text to the shell.
  • text : The text to be written to the shell.
WriteLine(string)
Method
void
Writes the line to the shell.
  • line : The line to be written to the shell.
Class
SshCommand
C#Python

Represents SSH command that can be executed.

MemberTypeDescription
CommandText
Property
read only
string
Gets the command text.
CommandTimeout
Property
TimeSpan
Gets or sets the command timeout.
Error
Property
read only
string
Gets the command execution error.
ExitStatus
Property
read only
int
Gets the command exit status.
ExtendedOutputStream
Property
read only
Stream
Gets the extended output stream.
OutputStream
Property
read only
Stream
Gets the output stream.
Result
Property
read only
string
Gets the command execution result.
BeginExecute()
Method
IAsyncResult
Begins an asynchronous command execution.
BeginExecute(AsyncCallback)
Method
IAsyncResult
Begins an asynchronous command execution.
  • callback : An optional asynchronous callback, to be called when the command execution is complete.
BeginExecute(AsyncCallback, object)
Method
IAsyncResult
Begins an asynchronous command execution.
  • callback : An optional asynchronous callback, to be called when the command execution is complete.
  • state : A user-provided object that distinguishes this particular asynchronous read request from other requests.
BeginExecute(string, AsyncCallback, object)
Method
IAsyncResult
Begins an asynchronous command execution.
  • commandText : The command text.
  • callback : An optional asynchronous callback, to be called when the command execution is complete.
  • state : A user-provided object that distinguishes this particular asynchronous read request from other requests.
Dispose()
Method
void
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Dispose(bool)
Method
void
Releases unmanaged and - optionally - managed resources
  • disposing : true to release both managed and unmanaged resources; false to release only unmanaged resources.
EndExecute(IAsyncResult)
Method
string
Waits for the pending asynchronous command execution to complete.
  • asyncResult : The reference to the pending asynchronous request to finish.
Execute()
Method
string
Executes command specified by CommandText property.
Execute(string)
Method
string
Executes the specified command text.
  • commandText : The command text.
~SshCommand()
Method
void
Releases unmanaged resources and performs other cleanup operations before the SshCommand is reclaimed by garbage collection.

Each method also exists in an asynchronous version, with the same name followed by Async and an optional cancellation token.


Intégrez facilement les robots Universal Robots, Fanuc, Yaskawa, ABB ou Staubli dans vos applications .NET, Python, LabVIEW ou Matlab

UnderAutomation
Contactez-nousLegal

© All rights reserved.