Namespace UTSModule.Test.Command.ComPortCommand
    Public Class ComWriteBytesExecutor
        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)
        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.WriteBytes(_sendText) Then
                CommandReturn.ExecuteResult = True
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送成功"
            Else
                CommandReturn.ExecuteResult = False
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
            End If

            Return CommandReturn
        End Function

    End Class
End Namespace