UnderAutomation
有问题吗?

[email protected]

联系我们
UnderAutomation
⌘Q
本页面仅提供英文版本。

SSH Linux commands

Run Linux commands on the controller of a UR cobot with SSH, one by one or in a shell that keeps its session.

  • Prerequisites
  • Run a command
  • Open a shell
  • Try it in the demo application
  • Reference

The controller of a Universal Robots cobot runs Linux. With SSH (Secure Shell), the SDK runs Linux commands on it, one by one or in a shell that keeps its session. This page shows both. To transfer files, see SFTP.

Prerequisites

  • Secure Shell is enabled on the robot. On PolyScope, open Settings, Security, Secure Shell.
  • The Linux user and its password: root on a robot, ur on URSim, easybot by default. The SDK uses ur and easybot when you set nothing.

A command runs with the rights of this user. A wrong command can stop the controller: test it on URSim first.

Run a command

SSH is disabled by default: set Ssh.EnableSsh in ConnectParameters. RunCommand runs a command and waits for its end. The returned SshCommand holds its output and its exit status.

static void Main(string[] args)
{
var robot = new UR();
var parameters = new ConnectParameters("192.168.0.1");
// SSH is disabled by default
parameters.Ssh.EnableSsh = true;
// "ur" and "easybot" by default
parameters.Ssh.Username = "root";
parameters.Ssh.Password = "easybot";
robot.Connect(parameters);
// Run a command and wait for its end
SshCommand command = robot.Ssh.RunCommand("df -h /programs");
string output = command.Result; // standard output
int exitStatus = command.ExitStatus;
}
}
Click to see the full code

SshClient also works without UR: new SshClient(), then Connect(ip, username, password).

Open a shell

A shell keeps its session and its working directory, like a terminal. CreateShellStream opens one, with a terminal name, a size and a buffer size. DataReceived is raised when the shell writes text.

robot.Connect(parameters);
// A shell keeps its session and its working directory, like a terminal.
// Terminal name, columns, rows, width, height, buffer size
ShellStream shell = robot.Ssh.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
// Raised for each text written by the shell
shell.DataReceived += (sender, e) => Console.Write(e.Line);
shell.WriteLine("cd /programs");
shell.WriteLine("ls -l");
}
}
Click to see the full code

Try it in the demo application

Everything on this page can be tried without writing code, in the Linux commands (SSH) page of the demo application.

Linux commands (SSH) page of the Universal Robots SDK demo application

The demo application is open source. The C# source of this page is SshControl.cs.

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.


轻松将 Universal Robots、Fanuc、Yaskawa、ABB 或 Staubli 机器人集成到您的 .NET、Python、LabVIEW 或 Matlab 应用程序中

UnderAutomation
联系我们Legal

© All rights reserved.