Imports UTS_Core.UTSModule.Test.StatusMonitor

Namespace UTSModule.Test.Command.UtsComPortCommand
    Public Class UtsWriteTextExecutor
        Inherits TestCommandExecutor

        Private ReadOnly _receiverAddress As String
        Private ReadOnly _utsCommand As String
        Private ReadOnly _utsParamString As String

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

            _receiverAddress = TestCommand.Parameter(0)
            _utsCommand = TestCommand.Parameter(1)
            _utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))

            CommandReturn.LowerLimit = String.Empty
            CommandReturn.UpperLimit = String.Empty
            CommandReturn.RecordValue = String.Empty
            CommandReturn.ExecuteResultTipString = String.Empty
            CommandReturn.ExecuteResult = True
        End Sub


        Public Overrides Function Execute() As TestCommandReturn
            '组包
            Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)

            '调用测试串口发送接口
            If UtsComportTask.SendTestCommand(sendData, True) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
                '发送数据失败
                CommandReturn.RecordValue = String.Empty
                CommandReturn.ExecuteResult = False
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
                Return CommandReturn
            Else
                CommandReturn.RecordValue = String.Empty
                CommandReturn.ExecuteResult = True
                CommandReturn.ExecuteResultTipString = "执行串口通讯发送完成"
            End If

            Return CommandReturn
        End Function

    End Class
End Namespace