How to make SendKeys act Synchronously in IBM Host Access Library

后端 未结 1 536
执念已碎
执念已碎 2020-11-30 15:17

I use the IBM Host Access Class Library for COM Automation as a way to communicate with an IBM AS400 (aka iSeries, IBM i, green screen, 5250) through a terminal emulator. I

相关标签:
1条回答
  • 2020-11-30 16:07

    The "Operator Information Area" class seems to provide a solution for this problem.

    My general case seems to be working correctly with this implementation:

     Friend Sub PutTextWithEnter(ByVal field As FieldDefinition, ByVal value As String)
        If IsNothing(field) Then Throw New ArgumentNullException("field")
        If IsNothing(value) Then Throw New ArgumentNullException("value")
        _Presentation.SendKeys(Mid(value.Trim, 1, field.Length).PadRight(field.Length) & "[enter]", field.Row, field.Column)
        WaitForEmulator(_Session.Handle)
    End Sub
    
    Private Sub WaitForEmulator(ByVal EmulatorHandle As Integer)
        Dim Oia As New AutOIATypeLibrary.AutOIA
        Oia.SetConnectionByHandle(EmulatorHandle)
        Oia.WaitForInputReady()
        Oia.WaitForAppAvailable()
    End Sub
    

    I give thanks to a user named "khieyzer" on this message board for pointing our this clean and general-purpose solution.

    Edit:

    After a few weeks debugging and working through timing and resource release issues, this method now reads like:

    Private Sub WaitForEmulator(ByRef NeededReset As Boolean)
        Dim Oia As New AutOIA
        Oia.SetConnectionByHandle(_Presentation.Handle)
    
        Dim inhibit As InhibitReason = Oia.InputInhibited
        If inhibit = InhibitReason.pcOtherInhibit Then
            _Presentation.SendKeys("[reset]")
            NeededReset = True
            WaitForEmulator(NeededReset)
            Marshal.ReleaseComObject(Oia)
            Exit Sub
        End If
    
        If Not Oia.WaitForInputReady(6000) Then
            If Oia.InputInhibited = InhibitReason.pcOtherInhibit Then
                _Presentation.SendKeys("[reset]")
                NeededReset = True
                WaitForEmulator(NeededReset)
                Marshal.ReleaseComObject(Oia)
                Exit Sub
            Else
                Marshal.ReleaseComObject(Oia)
                Throw New InvalidOperationException("The system has stopped responding.")
            End If
        End If
    
        Oia.WaitForInputReady()
        Oia.WaitForAppAvailable()
        Marshal.ReleaseComObject(Oia)
    End Sub
    
    0 讨论(0)
提交回复
热议问题