UiPath Documentation
activities
latest
false
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。
UiPath logo, featuring letters U and I in white

用户界面自动化活动

上次更新日期 2026年4月7日

终端编码的自动化 API

UiPath.Terminal.Activities

用于自动化终端模拟会话的编码工作流 API。提供方法,以便通过 BlueZone、IBM PCOMM、Attachmate 或直接的 TCP/SSH 连接与 IBM 3270/5250、VT、HP、ANSI、Wyse 和其他旧版终端系统建立连接,然后以编程方式与终端屏幕进行交互。

服务访问器: terminal (类型ITerminalService所需包: project.json 依赖项中的"UiPath.Terminal.Activities": "*"

自动导入的命名空间

安装此包后,这些命名空间将自动在编码工作流中可用:

UiPath.Terminal
UiPath.Terminal.Data
UiPath.Terminal.Activities.API
UiPath.Terminal.Enums
UiPath.Terminal
UiPath.Terminal.Data
UiPath.Terminal.Activities.API
UiPath.Terminal.Enums

服务概述

terminal服务提供工厂方法,用于打开终端连接并返回TerminalConnection对象。连接对象是所有终端操作 1(屏幕读取、字段访问、按键发送和等待)的 API 界面。

这是一个基于连接的 API

  1. 调用服务方法( GetConnection / GetSshConnection )以打开并连接。
  2. 使用返回的TerminalConnection执行终端操作。
  3. 完成后处置连接(或使用using语句)。

在编码工作流模式下,所有TerminalConnection方法在失败时都会抛出TerminalConnectionException而不是返回错误代码。这意味着您无需检查返回值,只需处理异常即可。

连接方式

TerminalConnection GetConnection(string connectionString)

使用序列化的连接字符串打开终端连接。连接字符串对提供程序类型、主机、端口、协议和其他设置进行编码。使用终端会话XAML 活动的“连接设置”对话框生成有效字符串。

参数:

  • connectionString ( string ) — 序列化的连接字符串。示例:通过配置“终端会话”活动并复制ConnectionString属性值来获取。

返回: TerminalConnection — 已打开且已连接的终端会话。实现IDisposable ;在using语句中使用。

抛出: TerminalConnectionException如果无法在超时内建立连接。

TerminalConnection GetConnection(ConnectionData connectionData)

使用ConnectionData对象打开终端连接,允许在不使用序列化连接字符串的情况下进行编程配置。

参数:

  • connectionData ( ConnectionData ) — 指定提供程序、主机、端口、协议和模拟设置的配置对象。

返回: TerminalConnection — 已打开且已连接的终端会话。

抛出:如果无法建立连接,则抛出TerminalConnectionException

TerminalConnection GetSshConnection(ConnectionData connectionData, string sshUser, SecureString sshPassword)

打开具有显式凭据的 SSH 终端连接。connectionData必须指定ProviderType = UiPathNewConnectionProtocol = SSH

参数:

  • connectionData ( ConnectionData ) — 连接配置。必须有ProviderType = TerminalProviderType.UiPathNewConnectionProtocol = CommunicationType.SSH
  • sshUser ( string ) — SSH 用户名。
  • sshPassword ( SecureString ) — SSH 密码。使用SecureString变量(例如,来自“获取凭据”)以避免公开纯文本。

返回: TerminalConnection — 已打开且已连接的 SSH 终端会话。

抛出: TerminalConnectionException如果连接失败);或ArgumentException如果ProviderTypeConnectionProtocol无效)。

终端连接

TerminalConnection是所有服务方法返回的句柄。它提供所有终端交互操作并实现IDisposable

备注:

此类型会实现IDisposable 。始终在using语句内部使用或显式调用Dispose() / Shutdown() 。处置将断开会话并终止所有主机进程。

属性

属性类型描述
Connectedbooltrue 如果会话当前已连接到主机。
ConnectionStringstring用于建立此连接的序列化连接字符串。
DefaultCmdOptionsCommandOptions在未显式覆盖的情况下,应用于所有操作的默认超时和等待模式选项。

Events

事件描述
TerminalScreenChanged终端屏幕内容更改时引发。
TerminalFieldChanged字段值更改时引发。
TerminalCursorChanged光标位置更改时引发。
TerminalConnectionChanged连接状态更改(例如,连接/断开连接)时引发。
TerminalErrorRaised异步发生终端错误时将引发。

屏幕阅读方法

TerminalResultCode GetText(out string text, CommandOptions options = null)

阅读终端屏幕的全部可见文本内容。

参数:

  • text ( out string ) — 接收全屏文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。默认为DefaultCmdOptions

返回: TerminalResultCode.Success (或在编码工作流模式下,若失败则抛出TerminalConnectionException )。

TerminalResultCode GetTextAtPosition(TerminalField criteria, int? length, out string text, CommandOptions options = null)

criteria定义的位置开始读取屏幕上的文本。(可选)限制读取的字符数。

参数:

  • criteria ( TerminalField ) — 通过RowStart / ColStart定义开始位置。
  • lengthint? ,可选)— 要读取的字符数。null读取至行尾。
  • text ( out string ) — 接收从该位置读取的文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode GetScreenArea(TerminalField criteria, out string text, CommandOptions options = null)

criteria定义的屏幕矩形区域中读取文本。

参数:

  • criteria ( TerminalField ) - 使用RowStartColStartRowEndColEnd定义区域。
  • text ( out string ) — 接收来自区域的文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode GetColorAtPosition(int row, int column, out Color color, CommandOptions options = null)

获取指定位置的字符的前景色。

参数:

  • row ( int ) — 行(从 1 开始)。
  • column ( int ) — 列(从 1 开始)。
  • color ( out Color ) - 接收System.Drawing.Color值。
  • optionsCommandOptions ,可选)— 超时和等待模式。
ScreenData GetScreen(CommandOptions options = null)

返回原始屏幕数据对象,包括所有字段属性和字符数据。

参数:

  • optionsCommandOptions ,可选)— 超时和等待模式。

返回:带有屏幕内容和字段元数据的ScreenData ;如果未连接,则返回null

字段方法

TerminalResultCode GetField(TerminalField field, out string text, CommandOptions options = null)

读取由其条件(标签、索引或坐标)标识的字段的文本内容。

参数:

  • field ( TerminalField ) — 字段标识。设置LabeledByFollowedByIndex或坐标属性。
  • text ( out string ) - 接收字段文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode SetField(TerminalField criteria, string text, CommandOptions options = null)

将文本写入与条件匹配的字段。

参数:

  • criteria ( TerminalField ) — 字段标识。设置LabeledByFollowedByIndex或坐标属性。
  • text ( string ) — 要写入的文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。

光标方法

TerminalResultCode GetCursorPosition(out CursorPosition cursorPosition, CommandOptions options = null)

获取终端光标的当前行和列。

参数:

  • cursorPosition ( out CursorPosition ) — 接收光标位置( RowColumn )。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode MoveCursor(int row, int column, CommandOptions options = null)

将终端光标移动到指定的行和列。

参数:

  • row ( int ) — 目标行(从 1 开始)。
  • column ( int ) — 目标列(从 1 开始)。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode MoveCursor(CursorPosition cursor, CommandOptions options = null)

使用CursorPosition对象移动光标。

参数:

  • cursor ( CursorPosition ) — 目标位置。
  • optionsCommandOptions ,可选)— 超时和等待模式。

按键发送方法

TerminalResultCode SendKeys(string keys, CommandOptions options = null)

将文本字符串发送到终端的当前光标位置。

参数:

  • keys ( string ) — 要发送的文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode SendKeysSecure(SecureString keys, CommandOptions options = null)

SecureString发送到终端。字符串在内存中解密并发送,然后将非托管缓冲区清零。用于密码。

参数:

  • keys ( SecureString ) — 要发送的安全文本。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode SendControlKey(ControlKey key, CommandOptions options = null)

将控制键(Tab、F1–F24、传输/Enter、箭头键等)发送到终端。

参数:

  • key ( ControlKey ) — 要发送的控制键。请参阅ControlKey枚举。
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode SendControlKey(ControlKey key, int delayMS, CommandOptions options = null)

发送一个控制键,然后在返回之前等待指定的毫秒数。当主机需要在按键后进行处理时,此方法非常有用。

参数:

  • key ( ControlKey ) — 要发送的控制键。
  • delayMS ( int ) — 发送密钥后的休眠毫秒数。
  • optionsCommandOptions ,可选)— 超时和等待模式。

等待方法

TerminalResultCode WaitScreenReady(CommandOptions options = null)

等待,直到终端键盘解锁并且屏幕准备好进行输入。

参数:

  • optionsCommandOptions ,可选)— 超时和等待模式。设置Timeout以控制等待时间。
TerminalResultCode WaitText(string text, TerminalField criteria = null, bool matchCase = true, CommandOptions options = null)

等待指定文本出现在终端屏幕上(如果提供了criteria ,则出现在特定字段中)。

参数:

  • text ( string ) — 要等待的文本。
  • criteriaTerminalField ,可选)— 设置后,等待特定字段中的文本。如果为null ,则等待屏幕上任意位置的文本。
  • matchCasebool ,可选)— 区分大小写。默认值: true
  • optionsCommandOptions ,可选)— 超时和等待模式。
TerminalResultCode FindTextInScreen(string text, CursorPosition startPosition, bool ignoreCase, out CursorPosition position, CommandOptions options = null)

在屏幕中搜索以startPosition开头的文本字符串。

参数:

  • text ( string ) — 要搜索的文本。
  • startPosition ( CursorPosition ) — 开始搜索位置。
  • ignoreCase ( bool ) — 不区分大小写的搜索。
  • position ( out CursorPosition ) — 接收找到文本时的坐标。
  • optionsCommandOptions ,可选)— 超时和等待模式。

:如果找到,则返回TerminalResultCode.Success ;否则返回如果未找到,则抛出异常(或返回InvalidCoordinates )。

连接生命周期

TerminalResultCode Disconnect(CommandOptions options = null)

断开与主机的连接,同时使连接对象保持活动状态(不释放)。很少需要 — Dispose()处理清理。

void Shutdown()

Dispose()的别名。断开连接、关闭主机流程并释放资源。

void Dispose()

断开会话连接,终止所有主机代理进程 (x86/x64),并释放所有托管和非托管资源。

高级

TerminalResultCode OverrideScreenResolution(ScreenSize screenSize, CommandOptions options = null)

覆盖终端屏幕尺寸。在主机需要非标准屏幕尺寸时使用。

参数:

  • screenSize ( ScreenSize ) — 目标屏幕尺寸。
  • optionsCommandOptions ,可选)— 超时和等待模式。

选项和配置类

CommandOptions

控制各个终端操作的超时和屏幕等待行为。

属性类型默认描述
Timeoutint30000引发超时错误之前等待的毫秒数。当0或负数时,回退到服务默认值 30000 毫秒。
WaitTypeWaitModeREADY如何在执行操作之前等待屏幕。
// Example: 10-second timeout, wait for screen ready
var opts = new CommandOptions(WaitMode.READY, 10000);
// Example: 10-second timeout, wait for screen ready
var opts = new CommandOptions(WaitMode.READY, 10000);

ConnectionData

用于终端连接的程序化配置对象。与GetConnection(ConnectionData)GetSshConnection()一起使用。

属性类型默认描述
ProviderTypeTerminalProviderTypeUiPathNew终端模拟器提供商。将UiPathNew用于直接 TCP/SSH 连接。
ConnectionTypeConnectionTypeProfile如何建立连接: Address (主机/端口 — UiPathNew为必要项)、 Profile (提供程序配置文件)、 LowLevel (EHLLAPI)。
ConnectionProtocolCommunicationTypeTELNET协议: TELNETSSHHPVT
TerminalTypeTerminalTypeTerminal3270终端模拟类型。
Hoststring目标主机的名称或 IP 地址。
Portint23TCP 端口。默认值为 23 (Telnet); SSH 通常使用 22。
ShowTerminalbooltrue是否显示终端窗口(如果提供程序支持)。
EnableSSLboolfalse为连接启用 SSL/TLS。
Profilestring提供程序配置文件的路径(对于基于配置文件的提供程序:Attachmate、IBM、 BlueZone 等)。
InProcessModeboolfalse在进程内运行终端提供程序(仅限通用/EHLLAPI)。
AttachExistingboolfalse连接到已在运行的终端会话。true值仅适用于Attachmate提供程序
ProxyTypeProxyTypeNone代理类型(无、HTTP、SOCKS4、SOCKS5)。
ProxyHoststring代理服务器主机名。
ProxyPortint代理服务器端口。
ProxyUserstring代理身份验证用户名。
ProxyPasswordstring代理身份验证密码。
InternalEncodingstring字符编码覆盖(例如, "IBM037"表示 EBCDIC)。
EhllDllstringEHLLAPI DLL(通用提供程序)的路径。
EhllFunctionstring"hllapi"EHLLAPI 入口点函数名称。
EhllSessionstring"A"EHLLAPI 会话标识符。
EhllEnhancedbooltrue使用增强型 EHLLAPI 模式。
EhllEncodingstring用于 EHLLAPI 文本通信的字符编码(通用提供程序)。如果未设置或无法识别,则默认为提供程序配置的编码。
EhllBasicModeboolfalse当为true时,禁用屏幕检索上的字段解析。屏幕数据仅作为原始文本返回,没有任何字段元数据。为了在不需要字段级访问时使用(通用型提供程序),以提高性能。
LuNamestring对于 3270/5250:从主机请求的 SNA 逻辑单元 (LU) 名称。对于 VT/Wyse/Linux:终端应答字符串(使用^M表示回车符)。对非 SNA 或非 VT 连接没有影响。
TerminalModelint0终端型号标识符。使用活动TerminalType的枚举值: TerminalModes3270 (3270)、 TerminalModes5250 (5250,当使用0 IBM_5250_3477_FCTTVtTermId (VT)、 TerminalModesHP (HP)、 TerminalModesWyse (Wyse)、 TerminalModesLinux (Linux)。

TerminalField

标识用于读取/写入操作的字段或屏幕区域。

属性类型描述
RowStartint起始行(从 1 开始,如果未设置,则为 -1)。
ColStartint“开始列”(从 1 开始,如果未设置,则为 -1)。
RowEndint区域操作的结束行(-1 表示未设置)。
ColEndint区域操作的结束列(-1 表示未设置)。
LabeledBystring字段之前的标签文本。
FollowedBystring字段之后的标签文本。
Indexint从零开始的字段索引(-1 表示取消设置)。

CursorPosition

表示终端屏幕上的行/列位置。

属性类型描述
Rowint行(从 1 开始)。默认值: 1
Columnint列(从 1 开始)。默认值: 1

枚举参考

WaitModeNONEREADYCOMPLETE

  • NONE — 立即执行;立即执行。
  • READY — 在执行之前等待键盘解锁。
  • COMPLETE — 等待所有屏幕数据到达,然后再执行。

TerminalProviderTypeUiPathNewAttachmateIBMBlueZoneGenericAttachmateExtraReflectionUnixReflectionIBMRumbaTandemHLL

  • UiPathNew — 直接 TCP/SSH 连接,无需第三方模拟器。支持 Telnet、SSH 和 CVT。
  • TandemHLL - 通过 THLLAPI( THLLW3.DLL / THLLW6.DLL 、Attachmate Reflection 6530)主机会话。使用ConnectionType.LowLevel和与Generic相同的Ehll*字段。不支持颜色属性数据; GetColorAtPosition始终返回Color.LightGreen

CommunicationTypeTELNETSSHHPVT

ConnectionTypeAddressProfileLowLevel

  • Address — 通过主机/端口连接。使用ProviderType.UiPathNew时为必需。
  • Profile — 使用特定于提供程序的配置文件(通过Profile设置的路径)进行连接。
  • LowLevel — 通过 EHLLAPI(通用提供程序)或 THLLAPI(TandemHLL 提供程序)连接。

TerminalTypeTerminal3270Terminal5250TerminalVTTerminalHPTerminalANSITerminalT653XTerminalSCOANSITerminalWYSETerminalLinux

ControlKey (选定值): TransmitTabBackTabReturnEscapeBackSpaceHomeEndInsertDeletePageUp PageDownUpDownLeftRightF1F24Shift_F1Shift_F12Ctrl_F1Ctrl_F12Alt_F1Alt_F12PA1PA3ClearResetAttentionEraseEOFEraseInputCursorSelectFieldPlusFieldMinusFieldExitCtrl_ACtrl_ZTandem_Horizontal_TabTandem_Vertical_Tab

TerminalModes3270 (与TerminalType.Terminal3270一起使用): IBM_3270_3278_2 (0)、 IBM_3270_3278_3 (1)、 IBM_3270_3278_4 (2)、 IBM_3270_3278_5 (3)、 IBM_3270_3279_2 (4)、 IBM_3270_3279_3 ( 5), IBM_3270_3279_4 (6), IBM_3270_3279_5 (7)

TerminalModes5250 (与TerminalType.Terminal5250一起使用): IBM_5250_3179_2 (54)、 IBM_5250_3179_220 (60)、 IBM_5250_3180_2 (52)、 IBM_5250_3196_A1 (53)、 IBM_5250_3477_FG (61)、 IBM_5250_3477_FC ( 62)、 IBM_5250_5251_1 (55)、 IBM_5250_5251_11 (56)、 IBM_5250_5252 (57)、 IBM_5250_5291_1 (58)、 IBM_5250_5292_2 (59)、 IBM_5250_5555_C01 (64)、 IBM_5250_5555_B01 (65) ), IBM_5250_Printer (63)

TTVtTermId (与TerminalType.TerminalVT一起使用): VT100 (0)、 VT101 (1)、 VT102 (2)、 VT220 (3)、 VT240 (4)、 VT320 ( 5)、 VT340 (6)、 VT420 (7)、 VT100W (10)、 VT101W (11)、 VT102W (12)、 VT220w (13)、 VT240W (14) )、 VT320W (15)、 VT340W (16)、 VT420W (17)、 VT100M (20)、 VT101M (21)、 VT102M (22)、 VT220M (23)个, VT240M (24)、 VT320M (25)、 VT340M (26)、 VT420M (27)

TerminalModesHP (与TerminalType.TerminalHP一起使用): HP_2372A (0)、 HP_70092 (1)、 HP_70094 (2)

TerminalModesWyse (与TerminalType.TerminalWYSE一起使用): WYSE_50_24_80 (0)、 WYSE_50_24_132 (10)、 WYSE_60_24_80 (1)、 WYSE_60_24_132 (11)、 WYSE_60_42_80 (41)、 WYSE_60_42_132 ( 51)、 WYSE_60_43_80 (61)、 WYSE_60_43_132 (71)、 WYSE_350_24_80 (2)、 WYSE_350_24_132 (12)

TerminalModesLinux (与TerminalType.TerminalLinux一起使用): Linux_24_80 (0)、 Linux_24_132 (1)、 Linux_36_80 (2)、 Linux_36_132 (3)、 Linux_48_80 (4)、 Linux_48_132 (5)

常见模式

登录到 3270 主机并读取字段

[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        Host = "mainframe.corp.com",
        Port = 23,
        TerminalType = TerminalType.Terminal3270,
        ProviderType = TerminalProviderType.UiPathNew,
        ConnectionType = ConnectionType.Address,
        ConnectionProtocol = CommunicationType.TELNET
    };

    using var conn = terminal.GetConnection(connData);

    // Wait for login screen, then type credentials
    conn.WaitText("ENTER USERID", options: new CommandOptions(WaitMode.READY, 30000));
    conn.SetField(new TerminalField { LabeledBy = "USERID" }, "myuser");
    conn.SetField(new TerminalField { LabeledBy = "PASSWORD" }, "mypassword");
    conn.SendControlKey(ControlKey.Transmit);

    // Wait for main menu
    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));

    // Read data
    conn.GetText(out string screen);
    Log(screen);
}
[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        Host = "mainframe.corp.com",
        Port = 23,
        TerminalType = TerminalType.Terminal3270,
        ProviderType = TerminalProviderType.UiPathNew,
        ConnectionType = ConnectionType.Address,
        ConnectionProtocol = CommunicationType.TELNET
    };

    using var conn = terminal.GetConnection(connData);

    // Wait for login screen, then type credentials
    conn.WaitText("ENTER USERID", options: new CommandOptions(WaitMode.READY, 30000));
    conn.SetField(new TerminalField { LabeledBy = "USERID" }, "myuser");
    conn.SetField(new TerminalField { LabeledBy = "PASSWORD" }, "mypassword");
    conn.SendControlKey(ControlKey.Transmit);

    // Wait for main menu
    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));

    // Read data
    conn.GetText(out string screen);
    Log(screen);
}

使用安全凭据的 SSH 连接

[Workflow]
public void Execute()
{
    var controlKeyDelayMS = 1000;
    var connData = new ConnectionData
    {
        Host = "unix-server.corp.com",
        Port = 22,
        TerminalType = TerminalType.TerminalVT,
        ProviderType = TerminalProviderType.UiPathNew,
        ConnectionType = ConnectionType.Address,
        ConnectionProtocol = CommunicationType.SSH
    };

    // sshPwd is a SecureString variable, for example, from Get Credential activity
    using var conn = terminal.GetSshConnection(connData, sshUser: "deploy", sshPassword: sshPwd);

    conn.WaitText("$", options: new CommandOptions(WaitMode.NONE, 10000));
    conn.SendKeys("ls -la /var/log");
    conn.SendControlKey(ControlKey.Transmit, controlKeyDelayMS);

    conn.GetText(out string output);
    Log(output);
}
[Workflow]
public void Execute()
{
    var controlKeyDelayMS = 1000;
    var connData = new ConnectionData
    {
        Host = "unix-server.corp.com",
        Port = 22,
        TerminalType = TerminalType.TerminalVT,
        ProviderType = TerminalProviderType.UiPathNew,
        ConnectionType = ConnectionType.Address,
        ConnectionProtocol = CommunicationType.SSH
    };

    // sshPwd is a SecureString variable, for example, from Get Credential activity
    using var conn = terminal.GetSshConnection(connData, sshUser: "deploy", sshPassword: sshPwd);

    conn.WaitText("$", options: new CommandOptions(WaitMode.NONE, 10000));
    conn.SendKeys("ls -la /var/log");
    conn.SendControlKey(ControlKey.Transmit, controlKeyDelayMS);

    conn.GetText(out string output);
    Log(output);
}

在自动化由公开 EHLLAPI 接口的第三方模拟器管理的终端会话(例如,通过其 EHLLAPI DLL 访问的正在运行的 IBM PCOMM 或 BlueZone 会话)时使用。

[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.Generic,
        ConnectionType = ConnectionType.LowLevel,
        EhllDll = @"C:\Program Files\IBM\Personal Communications\PCSHLL32.DLL",
        EhllFunction = "hllapi",
        EhllSession = "A",
        EhllEnhanced = true
    };

    using var conn = terminal.GetConnection(connData);

    // Move cursor to the Option field and type a menu choice
    conn.MoveCursor(row: 4, column: 14);
    conn.SendKeys("2");
    conn.SendControlKey(ControlKey.Transmit);
    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 20000));

    // Read a region of the response screen (rows 5-20, full width)
    var region = new TerminalField { RowStart = 5, ColStart = 1, RowEnd = 20, ColEnd = 80 };
    conn.GetScreenArea(region, out string result);
    Log(result);
}
[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.Generic,
        ConnectionType = ConnectionType.LowLevel,
        EhllDll = @"C:\Program Files\IBM\Personal Communications\PCSHLL32.DLL",
        EhllFunction = "hllapi",
        EhllSession = "A",
        EhllEnhanced = true
    };

    using var conn = terminal.GetConnection(connData);

    // Move cursor to the Option field and type a menu choice
    conn.MoveCursor(row: 4, column: 14);
    conn.SendKeys("2");
    conn.SendControlKey(ControlKey.Transmit);
    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 20000));

    // Read a region of the response screen (rows 5-20, full width)
    var region = new TerminalField { RowStart = 5, ColStart = 1, RowEnd = 20, ColEnd = 80 };
    conn.GetScreenArea(region, out string result);
    Log(result);
}

等待处理并读取结果字段(IBM Personal Communications/已保存的配置文件)

当已在 IBM PCOMM 工作区文件 ( .ws ) 中预配置连接时使用。必须在机器人计算机上安装 PCOMM。

[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.IBM,
        ConnectionType = ConnectionType.Profile,
        Mode = ConnectionMode.Play,
        ShowTerminal = true,
        Profile = @"C:\PComm\Profiles\MainframeSession.ws"
    };

    using var conn = terminal.GetConnection(connData);

    // Submit a transaction
    conn.SetField(new TerminalField { LabeledBy = "TRAN CODE" }, "INQ01");
    conn.SetField(new TerminalField { LabeledBy = "ACCOUNT  " }, accountNumber);
    conn.SendControlKey(ControlKey.Transmit);

    // Wait for either success or error indicator
    var opts = new CommandOptions(WaitMode.READY, 30000);
    conn.WaitScreenReady(opts);

    // Check status field
    conn.GetField(new TerminalField { LabeledBy = "STATUS   " }, out string status);
    if (status.Trim() == "00")
    {
        conn.GetField(new TerminalField { LabeledBy = "BALANCE  " }, out string balance);
        Log($"Balance: {balance}");
    }
    else
    {
        conn.GetText(out string screen);
        throw new Exception($"Transaction failed. Status: {status}. Screen: {screen}");
    }
}
[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.IBM,
        ConnectionType = ConnectionType.Profile,
        Mode = ConnectionMode.Play,
        ShowTerminal = true,
        Profile = @"C:\PComm\Profiles\MainframeSession.ws"
    };

    using var conn = terminal.GetConnection(connData);

    // Submit a transaction
    conn.SetField(new TerminalField { LabeledBy = "TRAN CODE" }, "INQ01");
    conn.SetField(new TerminalField { LabeledBy = "ACCOUNT  " }, accountNumber);
    conn.SendControlKey(ControlKey.Transmit);

    // Wait for either success or error indicator
    var opts = new CommandOptions(WaitMode.READY, 30000);
    conn.WaitScreenReady(opts);

    // Check status field
    conn.GetField(new TerminalField { LabeledBy = "STATUS   " }, out string status);
    if (status.Trim() == "00")
    {
        conn.GetField(new TerminalField { LabeledBy = "BALANCE  " }, out string balance);
        Log($"Balance: {balance}");
    }
    else
    {
        conn.GetText(out string screen);
        throw new Exception($"Transaction failed. Status: {status}. Screen: {screen}");
    }
}

检测条件逻辑的字段颜色

[Workflow]
public void Execute()
{
    var conn = terminal.GetConnection(connectionString);
    try
    {
        conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 10000));

        // Check if the status indicator at row 24, col 1 is red (error)
        conn.GetColorAtPosition(24, 1, out Color statusColor);

        if (statusColor == Color.Red)
        {
            conn.GetText(out string errorScreen);
            Log($"Error screen detected: {errorScreen}");
        }
        else
        {
            conn.GetField(new TerminalField { Index = 0 }, out string firstField);
            Log($"First field: {firstField}");
        }
    }
    finally
    {
        conn.Dispose();
    }
}
[Workflow]
public void Execute()
{
    var conn = terminal.GetConnection(connectionString);
    try
    {
        conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 10000));

        // Check if the status indicator at row 24, col 1 is red (error)
        conn.GetColorAtPosition(24, 1, out Color statusColor);

        if (statusColor == Color.Red)
        {
            conn.GetText(out string errorScreen);
            Log($"Error screen detected: {errorScreen}");
        }
        else
        {
            conn.GetField(new TerminalField { Index = 0 }, out string firstField);
            Log($"First field: {firstField}");
        }
    }
    finally
    {
        conn.Dispose();
    }
}

通过 THLLAPI 连接到 Tandem/NonStop 主机

在自动化通过 Attachmate Reflection 6530 运行的 Tandem/NonStop 会话时使用。THLLAPI 的EhllFunction入口点为"thllapi" (不是"hllapi" )。此提供程序没有颜色属性数据。

[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.TandemHLL,
        ConnectionType = ConnectionType.LowLevel,
        EhllDll = @"C:\Program Files\Attachmate\Reflection\THLLW6.DLL",
        EhllFunction = "thllapi",
        EhllSession = "A"
    };

    using var conn = terminal.GetConnection(connData);

    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));

    // Type a command and submit with Horizontal Tab to move between fields
    conn.SetField(new TerminalField { LabeledBy = "LOGON:" }, "myuser");
    conn.SendControlKey(ControlKey.Tandem_Horizontal_Tab);
    conn.SetField(new TerminalField { LabeledBy = "PASSWORD:" }, "mypassword");
    conn.SendControlKey(ControlKey.Return);

    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));
    conn.GetText(out string screen);
    Log(screen);
}
[Workflow]
public void Execute()
{
    var connData = new ConnectionData
    {
        ProviderType = TerminalProviderType.TandemHLL,
        ConnectionType = ConnectionType.LowLevel,
        EhllDll = @"C:\Program Files\Attachmate\Reflection\THLLW6.DLL",
        EhllFunction = "thllapi",
        EhllSession = "A"
    };

    using var conn = terminal.GetConnection(connData);

    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));

    // Type a command and submit with Horizontal Tab to move between fields
    conn.SetField(new TerminalField { LabeledBy = "LOGON:" }, "myuser");
    conn.SendControlKey(ControlKey.Tandem_Horizontal_Tab);
    conn.SetField(new TerminalField { LabeledBy = "PASSWORD:" }, "mypassword");
    conn.SendControlKey(ControlKey.Return);

    conn.WaitScreenReady(new CommandOptions(WaitMode.READY, 15000));
    conn.GetText(out string screen);
    Log(screen);
}

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新