Namespace UTSModule.Test.Command.ComPortCommand
    Public Class CloseAllComportExecutor
        Inherits TestCommandExecutor

        Private ReadOnly _portList As List(Of ComPort)

        Public Sub New(command As TestCommand, portList As List(Of ComPort))
            MyBase.New(command)

            _portList = portList
        End Sub

        Public Overrides Function Execute() As TestCommandReturn
            '从历史使用串口中查询,未查询到也视为成功
            For Each comPort As ComPort In _portList
                Try
                    comPort.Close()
                Catch ex As Exception
                    CommandReturn.ExecuteResultTipString = $"串口关闭失败：{ex.Message}"
                    CommandReturn.ExecuteResult = False

                    Return CommandReturn
                End Try
            Next

            CommandReturn.ExecuteResultTipString = $"串口全部关闭成功"
            CommandReturn.ExecuteResult = True
            Return CommandReturn
        End Function
    End Class
End Namespace