创建 LU2 会话后,可以通过Microsoft.HostIntegration.SNA.Session.ScreenData
和Microsoft.HostIntegration.SNA.Session.SessionDisplay
对象检索来自 3270 控制台的信息和消息。
通过 LU2 连接接收信息
如有必要,请使用
Microsoft.HostIntegration.SNA.Session.ScreenData
获取整个屏幕作为屏幕转储。在大多数情况下,不需要检索屏幕上的所有信息。 相反,可以将
Microsoft.HostIntegration.SNA.Session.SessionDisplay
对象用于大多数应用程序。调用
Microsoft.HostIntegration.SNA.Session.ScreenCursor
获取光标的位置。你可以选择通过调用
Microsoft.HostIntegration.SNA.Session.SessionDisplay.GetField%2A
或Microsoft.HostIntegration.SNA.Session.SessionDisplay.GetFields%2A
方法,或者Microsoft.HostIntegration.SNA.Session.SessionDisplay.CurrentField%2A
属性来获取屏幕上不同字段中所包含的位置和信息。Microsoft.HostIntegration.SNA.Session.SessionDisplay.GetField%2A
和Microsoft.HostIntegration.SNA.Session.SessionDisplay.GetFields%2A
两者都包含多个重载,允许你根据你提供的信息从屏幕检索字段信息。 相比之下,Microsoft.HostIntegration.SNA.Session.SessionDisplay.CurrentField%2A
仅表示光标当前位于的字段。最后,可以使用对各种
SessionDisplay.Wait
方法的调用来接收字段更新信息。
示例:
以下代码来自 Host Integration Server SDK 中的 3270 应用程序。 样例使用 SessionDisplay.CurrentField.Data
访问屏幕数据。
private void PerformTX_Click(object sender, EventArgs e)
{
try
{
// Disable every button and text box.
DisableEverything();
m_Handler.SendKey("@E");
TraceScreen();
// Wait for screen to calm down.
m_Handler.WaitForSession(SessionDisplayWaitType.NotBusy, 5000);
TraceScreen();
// See if the Balance Field is filled out.
m_Handler.Cursor.Row = m_row;
m_Handler.Cursor.Column = m_column;
TraceScreen();
// Tab to the Account Number field.
m_Handler.SendKey("@T");
TraceScreen();
// Move to the Next Field (Empty Stuff after 123456).
m_Handler.MoveNextField();
TraceScreen();
// Move to the Next Field (Title, Account Balance).
m_Handler.MoveNextField();
TraceScreen();
// Move to the Next Field (Account Balance).
m_Handler.MoveNextField();
TraceScreen();
// Extract Data from this field.
string accountBalance = m_Handler.CurrentField.Data;
// Trim the string.
accountBalance = accountBalance.Trim();
// Only things to do now are clear screen or disconnect.
EnableClearScreen();
// If we failed (not Abended) then this field will be blank.
if (accountBalance.Length == 0)
throw new Exception("Failed to get Account Balance");
else
MessageBox.Show(accountBalance, "Account Balance");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}