Namespace UTSModule.Test.Command.ComPortCommand
    Public Class ComWriteTextExecutor
        Inherits TestCommandExecutor
        Private _comPort As ComPort
        Private ReadOnly _portName As String
        Private ReadOnly _sendText As String

        Public Sub New(command As TestCommand)
            MyBase.New(command)

            _portName = command.Parameter(0)
            _sendText = command.Parameter(1)
            If command.Parameter(2) = "1" Then _sendText = _sendText & vbCrLf
        End Sub

        Public Overrides Function Execute() As TestCommandReturn
            '从历史使用串口中查询
            If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
                CommandReturn.ExecuteResultTipString = $"无效的串口名"
                CommandReturn.ExecuteResult = False
                Return CommandReturn
            End If

            If _comPort.WriteText(_sendText) = False Then
                CommandReturn.ExecuteResult = False
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
            Else
                CommandReturn.ExecuteResult = True
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送成功"
            End If

            Return CommandReturn
        End Function

    End Class
End Namespace