Imports System.Text
Imports System.Threading
Imports _485_BurningTool.CommunicationFlow
Imports _485_BurningTool.DataProcessing
Imports _485_BurningTool.RuningLog
Imports Newtonsoft.Json

Public Class SerialPort_BLV_Bootloader
    Inherits BLV_Bootloader

    '<Description("搜索命令")>
    'SearchCommand
    '<Description("跳转命令")>
    'skipCommand
    '<Description("设置参数")>
    'SetUpParameters
    '<Description("写入Flash数据")>
    'WriteFlashData
    '<Description("读取Flash数据")>
    'ReadingFlashData
    '<Description("擦除Flash数据")>
    'EraseFlashData
    '<Description("写入EEPROM数据")>
    'WriteEEPROMData
    '<Description("读取EEPROM数据")>
    'ReadingEEPROMData
    '<Description("擦除EEPROM数据")>
    'EraseEEPROMData
    '<Description("校验命令")>
    'CheckCommand
    '搜索命令

    Sub New()
        m_config = New BLV_Bootloaderconfig()
        'm_Receiver = Me
        ' m_Transmitter = Transmitter.CreateTransmitter(g_CommunicationType)
        m_flowdic = New Dictionary(Of String, List(Of (Integer, Cmdconfig)))
        UpdateUIqueue = New Queue(Of (Control, RuningLogConfig， Integer))
    End Sub

    'Public BindReceivedataFunction


    Public Overrides Function PacketDataSearchCommand(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC0
        Dim Timeout() As Byte = DataProcessing.IntToByteHB(CUShort(args(0)))
        Dim dvTimeout() As Byte = DataProcessing.IntToByteHB(CUShort(args(1)))
        result.Add(cmd)
        result.AddRange(Timeout)
        result.AddRange(dvTimeout)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataSkipCommand(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC1
        Dim addr As Byte = CByte(args(0))
        result.Add(cmd)
        result.Add(addr)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataSetUpParameters(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC2
        Dim Baudint As Integer = args(0)
        Dim intBaud As UShort = Baudint / 100
        Dim Baud() As Byte = DataProcessing.IntToByteHB(intBaud)
        Dim Timeout() As Byte = DataProcessing.IntToByteHB(CUShort(args(1)))
        result.Add(cmd)
        result.AddRange(Baud)
        result.AddRange(Timeout)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataWriteFlashData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC3
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim Data() As Byte = HexStringToByteArray(args(1))
        Dim len() As Byte = DataProcessing.IntToByteHB(CUShort(Data.Length))
        result.Add(cmd)
        result.AddRange(waddr)
        result.AddRange(len)
        result.AddRange(Data)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataReadingFlashData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC4
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim len() As Byte = DataProcessing.IntToByteLB(CUShort(args(1)))
        result.Add(cmd)
        result.AddRange(waddr)
        result.AddRange(len)
        Return result.ToArray


    End Function

    Public Overrides Function PacketDataEraseFlashData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC5
        Dim all As Byte = CInt(args(0))
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(1)))
        Dim len() As Byte = DataProcessing.IntToByteLB(CUShort(args(2)))
        result.Add(cmd)
        result.Add(all)
        result.AddRange(waddr)
        result.AddRange(len)
        Return result.ToArray

    End Function

    Public Overrides Function PacketDataWriteEEPROMData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC6
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim Data() As Byte = DataProcessing.GetBytesFromStr(args(1))
        Dim len() As Byte = DataProcessing.IntToByteLB(CUShort(Data.Length))
        result.Add(cmd)
        result.AddRange(waddr)
        result.AddRange(Data)
        result.AddRange(len)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataReadingEEPROMData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC7
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim len() As Byte = DataProcessing.IntToByteLB(CUShort(args(1)))
        result.Add(cmd)
        result.AddRange(waddr)
        result.AddRange(len)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataEraseEEPROMData(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC8
        Dim waddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim len() As Byte = DataProcessing.IntToByteLB(CUShort(args(1)))
        result.Add(cmd)
        result.AddRange(waddr)
        result.AddRange(len)
        Return result.ToArray
    End Function

    Public Overrides Function PacketDataCheckCommand(ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        Dim cmd As Byte = &HC9
        Dim startaddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(0)))
        Dim stopaddr() As Byte = DataProcessing.IntToByteHxxB(CInt(args(1)))
        Dim len() As Byte = DataProcessing.IntToByteHB(CUShort(args(2)))

        'Dim crclen As Integer = CInt(args(3))
        'Dim li As List(Of Integer) = DataProcessing.GetBytesFromStr(args(4))
        Dim li As List(Of Integer) = JsonConvert.DeserializeObject(Of List(Of Integer))(args(3))
        result.Add(cmd)
        result.AddRange(startaddr)
        result.AddRange(stopaddr)
        result.AddRange(len)
        For Each index As Integer In li
            'result.Add(CByte(args(I + 3)))
            result.AddRange(DataProcessing.IntToByteHB(index))
        Next
        Return result.ToArray
    End Function

    Public Overrides Function AssembleCommandData(command As Integer, ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        'm_config.GetType()
        Dim data As Byte()
        m_config.SetReceiverType(m_config.SingleSwitch, False, GetSN(),)

        Select Case command
            Case CmdType.CheckCommand
                data = PacketDataCheckCommand(args)
            Case CmdType.skipCommand
                data = PacketDataSkipCommand(args)
            Case CmdType.SetUpParameters
                data = PacketDataSetUpParameters(args)
            Case CmdType.WriteFlashData
                data = PacketDataWriteFlashData(args)
            Case CmdType.ReadingFlashData
                data = PacketDataReadingFlashData(args)
            Case CmdType.EraseFlashData
                data = PacketDataEraseFlashData(args)
            Case CmdType.WriteEEPROMData
                data = PacketDataWriteEEPROMData(args)
            Case CmdType.ReadingEEPROMData
                data = PacketDataReadingEEPROMData(args)
            Case CmdType.EraseEEPROMData
                data = PacketDataEraseEEPROMData(args)
            Case CmdType.SearchCommand
                data = PacketDataSearchCommand(args)
            Case Else
                Return Nothing
        End Select
        result.Add(m_config.MyAddress)
        result.Add(m_config.ReceiverType)
        result.Add(m_config.DeviceType)
        result.Add(m_config.ReceiverAddress)
        result.AddRange(DataProcessing.IntToByteHB(CUShort(data.Length + 7)))
        result.Add(0)
        result.AddRange(data)
        Dim crc As Byte = DataProcessing.SumAndMod(result.ToArray)
        result(6) = crc
        Return result.ToArray
    End Function

    Public Function AssembleCommandData1(command As Integer, ParamArray args() As String) As Byte()
        Dim result As List(Of Byte) = New List(Of Byte)
        'm_config.GetType()
        Dim data As Byte()
        m_config.SetReceiverType1(m_config.SingleSwitch, m_config.ResendSwitch, GetSN(),)

        Select Case command
            Case CmdType.CheckCommand
                data = PacketDataCheckCommand(args)
            Case CmdType.skipCommand
                data = PacketDataSkipCommand(args)
            Case CmdType.SetUpParameters
                data = PacketDataSetUpParameters(args)
            Case CmdType.WriteFlashData
                data = PacketDataWriteFlashData(args)
            Case CmdType.ReadingFlashData
                data = PacketDataReadingFlashData(args)
            Case CmdType.EraseFlashData
                data = PacketDataEraseFlashData(args)
            Case CmdType.WriteEEPROMData
                data = PacketDataWriteEEPROMData(args)
            Case CmdType.ReadingEEPROMData
                data = PacketDataReadingEEPROMData(args)
            Case CmdType.EraseEEPROMData
                data = PacketDataEraseEEPROMData(args)
            Case CmdType.SearchCommand
                data = PacketDataSearchCommand(args)
            Case Else
                Return Nothing
        End Select
        result.Add(m_config.MyAddress)
        result.Add(m_config.ReceiverType)
        result.Add(m_config.DeviceType)
        result.Add(m_config.ReceiverAddress)
        result.AddRange(DataProcessing.IntToByteHB(CUShort(data.Length + 7)))
        result.Add(0)
        result.AddRange(data)
        Dim crc As Byte = DataProcessing.SumAndMod(result.ToArray)
        result(6) = crc
        Return result.ToArray
    End Function

    '设置协议参数
    Public Overrides Sub SetProtocolParam(ParamArray args() As String)
        m_config.SetProtocolParam(args)
    End Sub
    '校验数据合法性
    Public Overrides Function CheckData(data As Byte()) As Boolean
        '判断包长是否一致
        Dim len As Integer = data(5) * 16 + data(4)
        If data.Length <> len Then Return False
        Dim sum As Integer
        For idx = 0 To data.Length - 1
            sum += data(idx)
            sum = sum And &HFF
        Next
        sum = (Not sum) And &HFF
        If CByte(sum) <> &HFF Then
            Return False    'CheckSum校验不通过，返回错误
        Else
            Return True
        End If
    End Function


    '主要工种流程流程
    Public Overrides Function UpgradeProcess(g_Cmdconfig As List(Of (number As Integer, Cmdconfig)), ParamArray args() As Object) As String

        Dim start As Integer = 0


        Dim g_RicText As RichTextBox = args(0)
        Dim g_SerialController As SerialController = m_Transmitter
        m_config.SearchEquipmentProcessSwitch = True
        Dim runnode As Cmdconfig
        '发送数据包
        Dim g_SendData As Byte()
        '我的地址
        Dim g_MyAddress As Integer = args(1)
        '接收地址
        Dim g_ReceiverAddress As Integer = args(2)
        Dim AppBaud As Integer = args(3)
        Dim UpdataBaud As Integer = args(4)
        Dim btn As Button = args(5)
        m_config.MyAddress = g_MyAddress
        m_config.ReceiverAddress = g_ReceiverAddress
        m_config.DeviceType = args(6)
        m_config.SingleSwitch = False
        m_config.SingleSwitch = False
        Dim gSendFileconig As SendFileconig
        Dim SetUpBaud As Integer = 2400
        Dim IsSetUpParameters = False
        Dim listnide As (number As Integer, List(Of Byte))
        If IsNothing(g_Cmdconfig) OrElse g_Cmdconfig.Count = 0 Then
            AddQueue(g_RicText, New RuningLogConfig("升级流程为空,升级失败!", Color.Black), 1)
            Return "升级流程为空,升级失败!"
        End If

        start = CmdType.SearchCommand
        Dim isCmdSendCount As Boolean = False
        Dim sp As TimeSpan
        Dim isCheckCommand As Boolean = False
        Dim skip As Integer
        While m_config.SearchEquipmentProcessSwitch
            If g_Cmdconfig.Count = 0 Then Exit While
            runnode = GetSendNode(start, g_Cmdconfig)
            Select Case start
                Case CmdType.SearchCommand '发送握手命令
                    If runnode.CmdSendCount < 3 Then
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)

                        '设置发送器波特率为2400
                        AddQueue(g_RicText, New RuningLogConfig($"设置发送器波特率为{SetUpBaud}!", Color.Black), 1)
                        g_SerialController.SetBaudRate(SetUpBaud)
                        g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                        runnode.CmdSendData = g_SendData
                        '发送搜索命令
                        AddQueue(g_RicText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        '等待APP返回数据
                        Delay(runnode.CmdReceiveTimeout * 500)
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                'If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 1 Then
                                    'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                    start = CmdType.SetUpParameters
                                    If IsSetUpParameters Then
                                        start = CmdType.EraseFlashData
                                    End If
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                ElseIf node.Item2(8) = 2 Then
                                    start = CmdType.skipCommand
                                    If IsSetUpParameters Then
                                        start = CmdType.EraseFlashData
                                    End If
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                End If
                                ' End If
                            Next
                        End If

                        AddQueue(g_RicText, New RuningLogConfig($"设置发送器波特率为{AppBaud}!", Color.Black), 1)
                        '设置发送器波特率为9600
                        g_SerialController.SetBaudRate(AppBaud)
                        '发送搜索命令
                        AddQueue(g_RicText, New RuningLogConfig($"发送搜索命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        '等待APP返回数据
                        Delay(runnode.CmdReceiveTimeout * 500)
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                ' If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 1 Then
                                    'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                    start = CmdType.SetUpParameters
                                    If IsSetUpParameters Then
                                        start = CmdType.EraseFlashData
                                    End If
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                ElseIf node.Item2(8) = 2 Then
                                    start = CmdType.skipCommand
                                    skip = AppBaud
                                    If IsSetUpParameters Then
                                        start = CmdType.EraseFlashData
                                    End If
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                End If
                                'End If
                            Next
                        End If
                        runnode.CmdSendCount += 1
                    Else
                        AddQueue(g_RicText, New RuningLogConfig("升级设备握手失败!", Color.Red), 1)
                        start = -1
                    End If



                Case CmdType.skipCommand '发送握手命令
                    If runnode.CmdSendCount < 3 Then
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)

                        AddQueue(g_RicText, New RuningLogConfig($"设置发送器波特率为{skip}!", Color.Black), 1)
                        '设置发送器波特率为9600
                        g_SerialController.SetBaudRate(skip)
                        g_SendData = AssembleCommandData(start， runnode.CmdArgs(0))
                        runnode.CmdSendData = g_SendData
                        '发送搜索命令
                        AddQueue(g_RicText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        '等待APP返回数据
                        Delay(runnode.CmdReceiveTimeout * 1000)
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                ' If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 0 Then
                                    AddQueue(g_RicText, New RuningLogConfig("设置跳转命令成功!", Color.Black), 1)
                                    AddQueue(g_RicText, New RuningLogConfig("开始重新握手!", Color.Black), 1)

                                    start = CmdType.SearchCommand
                                    If isCheckCommand Then
                                        start = -1
                                    End If
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                Else
                                    'AddQueue(g_RicText, New RuningLogConfig("跳转命令参数错误！!", Color.Red), 1)
                                    'runnode.CmdReceiveData.Clear()
                                End If
                                ' End If
                            Next
                        End If
                        runnode.CmdSendCount += 1
                    Else
                        AddQueue(g_RicText, New RuningLogConfig("设备跳转失败!", Color.Red), 1)
                        start = -1
                    End If

                Case CmdType.SetUpParameters '发送握手命令
                    IsSetUpParameters = False
                    If runnode.CmdSendCount < 3 Then
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)
                        g_SendData = AssembleCommandData(start， runnode.CmdArgs(0), runnode.CmdArgs(1))
                        runnode.CmdSendData = g_SendData
                        '发送搜索命令
                        AddQueue(g_RicText, New RuningLogConfig($"设置升级波特率为{UpdataBaud}!", Color.Black), 1)
                        AddQueue(g_RicText, New RuningLogConfig($"发送设置升级波特率命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        '等待APP返回数据
                        Delay(runnode.CmdReceiveTimeout * 1000)
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                '  If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 0 Then
                                    AddQueue(g_RicText, New RuningLogConfig("设置升级波特率命令成功!", Color.Black), 1)
                                    AddQueue(g_RicText, New RuningLogConfig("开始重新握手!", Color.Black), 1)
                                    start = CmdType.SearchCommand
                                    'g_Cmdconfig.RemoveAt(0)
                                    IsSetUpParameters = True
                                    SetUpBaud = UpdataBaud
                                    Continue While
                                Else
                                    'AddQueue(g_RicText, New RuningLogConfig("设置升级波特率命令参数错误！!", Color.Red), 1)
                                    'runnode.CmdReceiveData.Clear()
                                End If
                                ' End If

                            Next
                        End If
                        runnode.CmdSendCount += 1
                    Else
                        AddQueue(g_RicText, New RuningLogConfig("设置升级波特率跳转失败!", Color.Red), 1)
                        start = -1
                    End If

                Case CmdType.WriteFlashData '发送握手命令 256
                    gSendFileconig = runnode.CmdArgs(0)
                    If IsNothing(gSendFileconig) OrElse Not gSendFileconig.IsFileAnalysis Then
                        AddQueue(g_RicText, New RuningLogConfig("文件数据异常!", Color.Red), 1)
                        start = -1
                    End If
                    For i = 0 To gSendFileconig.Sendlist.Count - 1
                        listnide = gSendFileconig.Sendlist(i)
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)
                        g_SendData = AssembleCommandData(start， listnide.Item1, ByteArrayToHexString(listnide.Item2.ToArray))
                        If isCmdSendCount Then
                            runnode.CmdSendData(6) = 0
                            runnode.CmdSendData(1) = runnode.CmdSendData(1) Or 64
                            Dim crc As Byte = DataProcessing.SumAndMod(runnode.CmdSendData.ToArray)
                            runnode.CmdSendData(6) = crc
                            AddQueue(g_RicText, New RuningLogConfig($"开始第{runnode.CmdSendCount}重发升级数据包【{i.ToString}】!", Color.Blue), 1)
                        Else
                            runnode.CmdSendData = g_SendData
                            'AddQueue(g_RicText, New RuningLogConfig($"开始发送升级数据包【{i.ToString}】!", Color.Blue), 1)
                        End If
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        'Console.WriteLine($"runnode.CmdReceiveStatus:{Now.ToString("yyyy MM dd HH:mm:ss") }:{runnode.CmdReceiveStatus}")
                        sp = Now - runnode.CmdSendTime
                        While sp.TotalSeconds < runnode.CmdReceiveTimeout
                            If runnode.CmdReceiveStatus Then Exit While
                            Delay(100)
                            sp = Now - runnode.CmdSendTime
                        End While
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                'If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 0 Then
                                    AddQueue(g_RicText, New RuningLogConfig($"发送升级数据包成功【{i.ToString}】!", Color.Blue), 1) '
                                    isCmdSendCount = False
                                    Exit For
                                Else
                                    AddQueue(g_RicText, New RuningLogConfig($"发送升级数据包失败【{i.ToString}】!", Color.Red), 1)
                                    start = -1
                                    Continue While
                                End If
                                ' End If

                            Next
                        Else
                            AddQueue(g_RicText, New RuningLogConfig($"发送升级数据包超时【{i.ToString}】!", Color.Red), 1)
                            If runnode.CmdSendCount < 3 Then
                                runnode.CmdSendCount += 1
                                i = i - 1
                                isCmdSendCount = True
                                Continue For
                            End If
                            'isCmdSendCount = False
                            start = -1
                            Continue While
                        End If

                    Next
                    AddQueue(g_RicText, New RuningLogConfig("升级数据包发送完成，开始校验!", Color.Black), 1)
                    start = CmdType.CheckCommand
                     'g_Cmdconfig.RemoveAt(0)


                Case CmdType.ReadingFlashData '发送握手命令
                Case CmdType.EraseFlashData '发送握手命令
                    If runnode.CmdSendCount < 3 Then
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)
                        g_SendData = AssembleCommandData(start， runnode.CmdArgs(0), runnode.CmdArgs(1), runnode.CmdArgs(2))
                        runnode.CmdSendData = g_SendData
                        AddQueue(g_RicText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}!", Color.Black), 1)
                        AddQueue(g_RicText, New RuningLogConfig($"开始发送擦除Flash数据命令。{ByteToString2(g_SendData)}!", Color.Black), 1)
                        runnode.CmdReceiveData.Clear()
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        '等待APP返回数据
                        Delay(runnode.CmdReceiveTimeout * 1000)
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                ' If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 0 Then
                                    AddQueue(g_RicText, New RuningLogConfig("擦除Flash数据命令成功!", Color.Black), 1)
                                    start = CmdType.WriteFlashData
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                Else
                                    'AddQueue(g_RicText, New RuningLogConfig("擦除Flash数据命令参数错误！!", Color.Red), 1)
                                End If
                                ' End If
                            Next
                        End If
                        runnode.CmdSendCount += 1
                    Else
                        AddQueue(g_RicText, New RuningLogConfig("擦除Flash数据失败!", Color.Red), 1)
                        start = -1
                    End If


                Case CmdType.WriteEEPROMData '发送握手命令
                Case CmdType.ReadingEEPROMData '发送握手命令
                Case CmdType.EraseEEPROMData '发送握手命令
                Case CmdType.CheckCommand '发送握手命令 512
                    If runnode.CmdSendCount < 3 Then
                        g_SerialController.m_ReceiveQueue.Clear()
                        g_SerialController.m_ReceiveQueue.Add(runnode)
                        runnode.setCmdReceiveStatus(False)
                        gSendFileconig = runnode.CmdArgs(0)
                        isCheckCommand = False
                        Dim li As List(Of Integer) = CheckCommand(gSendFileconig)
                        g_SendData = AssembleCommandData(start, gSendFileconig.SendAddr, gSendFileconig.EndAddr, gSendFileconig.BlockLength, JsonConvert.SerializeObject(li))
                        AddQueue(g_RicText, New RuningLogConfig($"发送升级校验命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                        runnode.CmdSendData = g_SendData
                        g_SerialControllerSendData(g_RicText, g_SerialController, runnode)
                        Delay(runnode.CmdReceiveTimeout * 1000)
                        'Console.WriteLine(runnode.CmdReceiveStatus)
                        ' Console.WriteLine($"runnode.CmdReceiveStatus:{Now.ToString("yyyy MM dd HH:mm:ss") }:{runnode.CmdReceiveStatus}")
                        If runnode.CmdReceiveStatus Then
                            For Each node In runnode.CmdReceiveData
                                ' If runnode.CmdSendData(3) = node.Item2(3) AndAlso runnode.CmdSendData(2) = node.Item2(2) Then
                                If node.Item2(8) = 0 Then
                                    AddQueue(g_RicText, New RuningLogConfig("校验命令发送成功!", Color.Black), 1)
                                    isCheckCommand = True
                                    runnode = GetSendNode(CmdType.skipCommand, g_Cmdconfig)
                                    runnode.CmdArgs(0) = 2
                                    start = CmdType.skipCommand
                                    skip = UpdataBaud
                                    'g_Cmdconfig.RemoveAt(0)
                                    Continue While
                                Else
                                    ' AddQueue(g_RicText, New RuningLogConfig($"校验命令发送失败!{ByteToString2(runnode.CmdSendData) }", Color.Red), 1)
                                End If
                                ' End If
                            Next
                        End If
                        runnode.CmdSendCount += 1


                    Else
                        AddQueue(g_RicText, New RuningLogConfig("校验命令发送失败!", Color.Red), 1)
                        start = -1
                    End If
                Case CmdType.WaitReply '等待回复

                Case CmdType.ProcessReply '跳过


                Case Else
                    Exit While
            End Select
        End While
        AddQueue(g_RicText, New RuningLogConfig("升级流程结束!", Color.Black), 1)
        If m_config.SearchEquipmentProcessSwitch Then
            m_config.SearchEquipmentProcessSwitch = False
            ResetButton(btn)
        End If
    End Function

    '获取发送节点
    Public Function GetSendNode(g_WorkflowType As Integer, g_Cmdconfig As List(Of (number As Integer, Cmdconfig))） As Cmdconfig
        For Each node In g_Cmdconfig
            If node.Item1 = g_WorkflowType Then
                Return node.Item2
            End If
        Next
        Return Nothing
    End Function

    '获取校验数据发送列表
    Public Function CheckCommand(SendFileconig As SendFileconig) As List(Of Integer)
        Dim libuf As List(Of Byte) = New List(Of Byte)
        Dim li As New List(Of Integer)
        Dim yulen As Integer = 0
        '4096-libuf.Count>
        Dim kuai As Integer = SendFileconig.BlockLength '512
        ' For i As Integer = 0 To SendFileconig.SendLen / 4096
        For Each node In SendFileconig.Sendlist

            If libuf.Count < kuai Then
                yulen = kuai - libuf.Count
                If yulen >= node.Item2.Count Then
                    libuf.AddRange(node.Item2)
                Else
                    For j As Integer = 0 To yulen - 1
                        libuf.Add(node.Item2(j))
                        If libuf.Count = kuai Then
                            '计算CRC
                            li.Add(DataProcessing.GetCRC16(libuf.ToArray))
                            '添加到li
                            libuf.Clear()
                            '重置链表
                        End If
                    Next

                End If



            End If

            If libuf.Count = kuai Then
                li.Add(DataProcessing.GetCRC16(libuf.ToArray))
                '添加到li
                libuf.Clear()
            End If

        Next
        'If libuf.Count < kuai Then
        '    yulen = kuai - libuf.Count
        '    For j As Integer = 0 To yulen - 1
        '        libuf.Add(&H0)
        '    Next
        'End If

        If libuf.Count > 0 AndAlso libuf.Count < kuai Then
            li.Add(DataProcessing.GetCRC16(libuf.ToArray))
            '添加到li
            libuf.Clear()
        End If
        Return li
        '  Next
    End Function



    'byte数组转字符串
    'Private Function ByteToString2(ByVal bytes() As Byte) As String
    '    Dim str As String = ""
    '    Return Encoding.ASCII.GetString(bytes)
    'End Function
    ''字符串转byte数组
    'Private Function StringToByte(ByVal str As String) As Byte()
    '    Return Encoding.ASCII.GetBytes(str)
    'End Function


    '执行主要工作流程
    Public Overrides Function MainProcess(g_WorkflowType As Integer, g_Cmdconfig As List(Of (number As Integer, Cmdconfig)), ParamArray args() As Object) As Boolean
        '绑定串口接收事件

        Select Case g_WorkflowType
            Case WorkflowType.SearchEquipment
                SearchEquipmentProcess(g_Cmdconfig(0).Item2, args)
            Case WorkflowType.FlashWrite
                UpgradeProcess(g_Cmdconfig, args)
            Case WorkflowType.EEPROMWrite

        End Select

    End Function

    Private Sub SerialPort_DataReceived(sender As Object, e As IO.Ports.SerialDataReceivedEventArgs)

    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="limitTime">发送持续时间</param>
    ''' <param name="g_Cmdconfig">搜索命令节点</param>
    ''' <param name="args"></param>
    ''' <returns></returns>
    Public Overrides Function SearchEquipmentProcess(g_Cmdconfig As Cmdconfig, ParamArray args() As Object) As Boolean
        Dim g_SerialController As SerialController = m_Transmitter
        Dim limitTime As Integer = args(0)
        Dim g_Table As DataGridView = args(1)
        Dim g_RicText As RichTextBox = args(2)
        '我的地址
        Dim g_MyAddress As Integer = args(3)
        '开始地址
        Dim g_StartAddress As Integer = args(4)
        '结束地址
        Dim g_EndAddress As Integer = args(5)
        Dim AppBaud As Integer = args(6)
        Dim btn As Button = args(7)
        '当前时间
        Dim g_CurrentTime As DateTime = DateTime.Now
        '运行时间
        Dim g_RunTime As Integer = 0

        '发送数据包
        Dim g_SendData As Byte()
        m_config.SearchEquipmentProcessSwitch = True
        g_SerialController.m_ReceiveQueue.Add(g_Cmdconfig)
        g_Cmdconfig.setCmdReceiveStatus(False)
        '开始循环交替发送搜索命令
        While m_config.SearchEquipmentProcessSwitch AndAlso g_RunTime < limitTime

            If g_StartAddress > g_EndAddress Then Return True
            m_config.MyAddress = g_MyAddress
            m_config.ReceiverAddress = g_StartAddress
            '设置发送器波特率为2400
            AddQueue(g_RicText, New RuningLogConfig("设置发送器波特率为2400!", Color.Black), 1)
            g_SerialController.SetBaudRate(2400)
            g_SendData = AssembleCommandData(CmdType.SearchCommand， g_Cmdconfig.CmdArgs(0)， g_Cmdconfig.CmdArgs(1))
            g_Cmdconfig.CmdSendData = g_SendData
            '发送搜索命令
            AddQueue(g_RicText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
            g_SerialControllerSendData(g_RicText, g_SerialController, g_Cmdconfig)
            '等待bootloader返回数据
            Delay(1000)
            ParsingCommandResponse(g_Cmdconfig, g_Table, g_RicText)
            AddQueue(g_RicText, New RuningLogConfig($"设置发送器波特率为{AppBaud}!", Color.Black), 1)
            '设置发送器波特率为9600
            g_SerialController.SetBaudRate(AppBaud)
            '发送搜索命令
            AddQueue(g_RicText, New RuningLogConfig($"发送搜索命令!{ByteToString2(g_SendData)}", Color.Black), 1)
            g_SerialControllerSendData(g_RicText, g_SerialController, g_Cmdconfig)
            '等待APP返回数据
            Delay(1000)
            ParsingCommandResponse(g_Cmdconfig, g_Table, g_RicText)
            'Delay(1000)
            g_RunTime = DateTime.Now.Subtract(g_CurrentTime).TotalSeconds
            g_StartAddress += 1
        End While
        '设置发送器波特率为2400
        If m_config.SearchEquipmentProcessSwitch Then
            ResetButton(btn)
        End If

    End Function
    Delegate Sub delResetButton(btn As Button)
    Public Sub ResetButton(btn As Button)
        If btn.InvokeRequired Then
            Dim d As New delResetButton(AddressOf ResetButton)
            btn.Invoke(d, btn)
        Else
            btn.PerformClick()
        End If
    End Sub

    '定义一个数据结构
    Public Structure Stru_RS_485_Data
        Dim Data_Head As Byte
        Dim Data_Len As Byte

    End Structure
    Delegate Sub delSetUpgradeProgressProgressbar(gTable As DataGridView, addr As String, devtype As String, val As String, bcolor As Color, RText_OutputText As RichTextBox)
    '设置升级进度显示
    Public Overrides Sub SetUpgradeProgressProgressbar(gTable As DataGridView, addr As String, devtype As String, val As String, bcolor As Color, Optional RText_OutputText As RichTextBox = Nothing)

        If gTable.InvokeRequired Then
            Dim d As New delSetUpgradeProgressProgressbar(AddressOf SetUpgradeProgressProgressbar)
            gTable.Invoke(d, {gTable, addr, devtype, val, bcolor, RText_OutputText})
        Else
            If Not IsNothing(RText_OutputText) Then
                Dim valbuf As String() = val.Split("/")

                AddQueue(RText_OutputText, New RuningLogConfig($"开始发送升级数据包：【{valbuf(0)}】!", Color.DarkGreen), 1)
            End If

            For i = 0 To gTable.Rows.Count - 1
                If addr.Trim.Equals(gTable.Rows(i).Cells(2).Value.ToString) AndAlso devtype.Trim.Equals(gTable.Rows(i).Cells(3).Value.ToString) Then
                    gTable.Rows(i).Cells(6).Value = val
                    gTable.Rows(i).Cells(6).Style.BackColor = bcolor
                End If
            Next
        End If
    End Sub

    Delegate Sub delParsingCommandResponse(gCmdconfig As Cmdconfig, gTable As DataGridView, gRicText As RichTextBox)
    Public Sub ParsingCommandResponse(gCmdconfig As Cmdconfig, gTable As DataGridView, gRicText As RichTextBox)

        If gRicText.InvokeRequired Then
            Dim d As New delParsingCommandResponse(AddressOf ParsingCommandResponse)
            gRicText.Invoke(d, gCmdconfig, gTable, gRicText)
        Else
            'Dim g_SerialController As SerialController = m_Transmitter
            Dim ReceiveDataLen As Integer = gCmdconfig.CmdReceiveData.Count
            Dim isSearch As Boolean = False
            Dim uuidlen As Integer
            If ReceiveDataLen < 1 Then Return
            Select Case gCmdconfig.CmdValue
                Case CmdType.SearchCommand '解析搜索命令
                    Dim Chiplen, namelen As Integer
                    'Dim namebuf As Byte()
                    Dim ReceiveDataCount As Integer = gCmdconfig.CmdReceiveData.Count - 1
                    Dim node As (DateTime, Byte())
                    For k = 0 To ReceiveDataCount
                        node = gCmdconfig.CmdReceiveData(k)
                        Chiplen = node.Item2(11)
                        Dim namebuf2(Chiplen - 1) As Byte
                        Array.Copy(node.Item2, 12, namebuf2, 0, namebuf2.Length)
                        Dim guid As String = ByteArrayToHexString(namebuf2) 'System.Text.Encoding.ASCII.GetString(namebuf2)
                        '  uuidlen = node.Item2(10)
                        'If gTable.Rows.Count = 0 Then
                        '    gTable.Rows.Add()
                        '    If node.Item2(8) = 1 Then
                        '        gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                        '    ElseIf node.Item2(8) = 2 Then
                        '        gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "APP"
                        '    Else
                        '        gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "未知"
                        '    End If
                        '    Chiplen = Chiplen + 12
                        '    namelen = node.Item2(Chiplen)
                        '    Dim namebuf(namelen - 1) As Byte
                        '    Array.Copy(node.Item2, Chiplen + 1, namebuf, 0, namebuf.Length)
                        '    gTable.Rows(gTable.Rows.Count - 1).Cells(4).Value = System.Text.Encoding.ASCII.GetString(namebuf)

                        '    gTable.Rows(gTable.Rows.Count - 1).Cells(2).Value = node.Item2(0)
                        '    gTable.Rows(gTable.Rows.Count - 1).Cells(3).Value = node.Item2(2)
                        '    gTable.Rows(gTable.Rows.Count - 1).Cells(8).Value = node.Item2(9)
                        '    gTable.Rows(gTable.Rows.Count - 1).Cells(7).Value = node.Item2(10)
                        'Else
                        isSearch = True
                        For i = 0 To gTable.Rows.Count - 1
                            Chiplen = node.Item2(11)
                            If gTable.Rows(i).Cells(2).Value = node.Item2(0) AndAlso gTable.Rows(i).Cells(3).Value = node.Item2(2) AndAlso guid.Trim.Equals(gTable.Rows(i).Cells(9).Value) Then
                                If node.Item2(8) = 1 Then
                                    gTable.Rows(i).Cells(5).Value = "Boot"
                                ElseIf node.Item2(8) = 2 Then
                                    gTable.Rows(i).Cells(5).Value = "APP"
                                Else
                                    gTable.Rows(i).Cells(5).Value = "未知"
                                End If
                                Chiplen = Chiplen + 12
                                namelen = node.Item2(Chiplen)
                                Dim namebuf1(namelen - 1) As Byte
                                Try
                                    Array.Copy(node.Item2, Chiplen + 1, namebuf1, 0, namebuf1.Length)
                                Catch ex As Exception

                                End Try

                                gTable.Rows(i).Cells(4).Value = System.Text.Encoding.ASCII.GetString(namebuf1)
                                gTable.Rows(i).Cells(8).Value = node.Item2(9)
                                gTable.Rows(i).Cells(7).Value = node.Item2(10)
                                isSearch = False
                                Exit For
                            End If

                        Next
                        If isSearch Then
                            gTable.Rows.Add()
                            If node.Item2(8) = 1 Then
                                gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                            ElseIf node.Item2(8) = 2 Then
                                gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "APP"
                            Else
                                gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "未知"
                            End If
                            Chiplen = Chiplen + 12
                            namelen = node.Item2(Chiplen)
                            Dim namebuf(namelen - 1) As Byte
                            uuidlen = node.Item2(11)
                            Try
                                Array.Copy(node.Item2, Chiplen + 1, namebuf, 0, namebuf.Length)
                            Catch ex As Exception

                            End Try



                            gTable.Rows(gTable.Rows.Count - 1).Cells(4).Value = System.Text.Encoding.ASCII.GetString(namebuf)
                            gTable.Rows(gTable.Rows.Count - 1).Cells(2).Value = node.Item2(0)
                            gTable.Rows(gTable.Rows.Count - 1).Cells(3).Value = node.Item2(2)
                            gTable.Rows(gTable.Rows.Count - 1).Cells(8).Value = node.Item2(9)
                            gTable.Rows(gTable.Rows.Count - 1).Cells(7).Value = node.Item2(10)
                            gTable.Rows(gTable.Rows.Count - 1).Cells(0).Value = gTable.Rows.Count
                            gTable.Rows(gTable.Rows.Count - 1).Cells(9).Value = guid
                            'For i = 0 To gTable.Columns.Count - 1
                            '    gTable.Rows(gTable.Rows.Count - 1).Cells(i).Value = i
                            'Next
                        End If



                        'End If

                    Next
                    gCmdconfig.CmdReceiveData.Clear()

                Case CmdType.skipCommand '发送握手命令
                Case CmdType.SetUpParameters '发送握手命令
                Case CmdType.WriteFlashData '发送握手命令
                Case CmdType.ReadingFlashData '发送握手命令
                Case CmdType.EraseFlashData '发送握手命令
                Case CmdType.WriteEEPROMData '发送握手命令
                Case CmdType.ReadingEEPROMData '发送握手命令
                Case CmdType.EraseEEPROMData '发送握手命令
                Case CmdType.CheckCommand '发送握手命令
            End Select
        End If


    End Sub




    '解析接收数据
    Public Overrides Function ParseReceiveData(gCmdconfig As Cmdconfig, data As Byte()) As Boolean
        Dim saaa = DataProcessing.SumAndMod(data)
        ' Console.WriteLine($"SumAndMod:{saaa}")
        If saaa = 0 Then '进行求和检验整包数据
            '判断命令类型是否一致
            If data(7) = gCmdconfig.CmdValue Then
                ' Console.WriteLine($"data(7)=gCmdconfig.CmdValue{saaa}")
                '判断SN是否一致
                If (data(1) And &HF) = (gCmdconfig.CmdSendData(1) And &HF) AndAlso gCmdconfig.CmdSendData(0) = data(3) Then
                    gCmdconfig.CmdReceiveData.Add((Now, data))
                    gCmdconfig.CmdReceiveStatus = True
                    'Console.WriteLine($"gCmdconfig.CmdReceiveStatus:{Now.ToString("yyyy MM dd HH:mm:ss") }:{gCmdconfig.CmdReceiveStatus}")
                    Return True
                Else

                    Return False
                End If
            End If
            Return True
        End If
        Return False
    End Function


    '写入Flash流程
    Public Function WriteFlash(g_Cmdconfig As Cmdconfig, ParamArray args() As Object) As Boolean
        Dim g_SerialController As SerialController = m_Transmitter

        Dim g_Table As DataGridView = args(0)
        Dim g_RicText As RichTextBox = args(1)
        '我的地址
        Dim g_MyAddress As Integer = args(2)
        '发送数据包
        Dim g_SendData As Byte()
        While m_config.UpgradeProcessSwitch
            '枚举表格勾选
            For Each row As DataGridViewRow In g_Table.Rows
                If row.Cells(0).Value = True Then
                    '判断设备是否在BOOT
                    If row.Cells(2).Value = "BOOT" Then
                        '发送跳转APP命令
                        '设置发送器波特率为2400
                        AddQueue(g_RicText, New RuningLogConfig("设置发送器波特率为2400!", Color.Black), 1)
                        g_SerialController.SetBaudRate(2400)
                        g_SendData = AssembleCommandData(CmdType.skipCommand， 2)
                        '发送跳转APP命令
                        AddQueue(g_RicText, New RuningLogConfig($"发送跳转APP命令!", Color.Black), 1)
                        g_SerialControllerSendData(g_RicText, g_SerialController, g_Cmdconfig)
                        '等待APP返回数据
                        Delay(3000)
                        '设置发送器波特率为9600
                        AddQueue(g_RicText, New RuningLogConfig("设置发送器波特率为9600!", Color.Black), 1）
                        g_SerialController.SetBaudRate(9600)
                        '下发擦除Flash命令
                        AddQueue(g_RicText, New RuningLogConfig($"下发擦除Flash命令!", Color.Black), 1)
                        g_SendData = AssembleCommandData(CmdType.EraseFlashData, 2)
                        '等待擦除 Flash命令返回
                        Delay(1000)
                        g_SerialControllerSendData(g_RicText, g_SerialController, g_Cmdconfig)

                    Else

                    End If

                End If
            Next

        End While
    End Function

    Public Overrides Sub SetSearchEquipmentProcessSwitch(iswitch As Boolean)
        m_config.SearchEquipmentProcessSwitch = iswitch
    End Sub
    Public Overrides Sub WorkflowTypeNone(Parameterlist As Parameterlist, ByRef isRuning As Boolean)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)
        Dim g_SerialController As SerialController = m_Transmitter
        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim args As List(Of String） = New List(Of String)
        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                Parameterlist.NextAction = 1
                m_config.SingleSwitch = False
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1
                '获取发送地址
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未找读取设备地址！请将读接收起始地址 设置为目标地址", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType
                For Each argesindex In runnode.CmdArgs
                    args.Add(argesindex)
                Next


                g_SendData = AssembleCommandData1(runnode.CmdValue， args.ToArray)
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 5
            Case 5 '搜索结束
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("发送完毕!", Color.Black), 1)
                'ResetButton(Parameterlist.btn)
                SetSearchEquipmentProcessSwitch(False)
                'm_Receiver.SetThreadFlag(False)
                isRuning = False
                Parameterlist.EnableFlag = False
        End Select
    End Sub

    Public Overrides Sub OrdinaryOccurrenceCommand(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)
        Dim g_SerialController As SerialController = m_Transmitter
        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                Parameterlist.NextAction = 1
                m_config.SingleSwitch = False
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    m_config.ResendSwitch = False
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"跳转失败或跳转超时！！", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "跳转失败或跳转超时", Color.Red)

                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"重发跳转命令!", Color.DarkGreen), 1)
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 1)
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 11


            Case 11 '等待跳转命令回复 APP跳boot
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 12
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 13
                                Parameterlist.CurrentStep = CmdType.SearchCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "10", Color.White)
                                Return
                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 12
                        Return
                        'Parameterlist.NextAction = 4

                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 12 '处理跳转结果
                Parameterlist.NextAction = 10
                runnode.CmdSendCountNow += 1


            Case 13 '修改成boot波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SearchCommand
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 14

            Case 2
                '获取发送地址
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未找读取设备地址！请将读接收起始地址 设置为目标地址", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData1(CmdType.ReadingFlashData， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送读取设备命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 5
            Case 5 '搜索结束
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("读取设备结束!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                'End If
                Parameterlist.EnableFlag = False
        End Select
    End Sub

    Public Overrides Sub NewBootSearchEquipmentProcess(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As SerialController = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()

        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                Parameterlist.NextAction = 1
                m_config.SingleSwitch = False
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1 '’设置发送器波特率为2400

                '设置发送器波特率为2400
                ''If g_SerialController.IsSerialData Then
                '    '延时(1000)
                '    Thread.Sleep(100)
                '    Return
                'End If
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                Parameterlist.NextAction = 2

            Case 2 '’搜索boll设备
                '判断是否发送超时
                'If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                '    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                '    Parameterlist.NextAction = 5
                '    Return
                'End If
                ''获取发送地址
                'sendAddress = GetReceivingAddress(Parameterlist)
                'If sendAddress = -1 Then
                '    Parameterlist.NextAction = 5
                '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                '    Return
                'End If
                'm_config.MyAddress = Parameterlist.StartAddress
                'm_config.ReceiverAddress = sendAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                'g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                'runnode.CmdSendData = g_SendData

                'g_SerialController.m_ReceiveQueue.Clear()
                'g_SerialController.m_ReceiveQueue.Add(runnode)
                'runnode.setCmdReceiveStatus(False)
                ''发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                'g_SerialControllerSendData(g_SerialController,runnode)
                'Parameterlist.NextAction = 3



                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                    Parameterlist.NextAction = 5
                    Return
                End If
                '获取发送地址
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 3


            Case 3 '等待boll设备回复
                '判断超时
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 4
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 4
                        '如果有接收处理
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 4 '处理boll设备回复
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                Parameterlist.NextAction = 6

            Case 6 '设置发送器波特率为APP的波特率
                '设置发送器波特率为2400
                ''If g_SerialController.IsSerialData Then
                '    Thread.Sleep(100)
                '    Return
                'End If
                'g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                m_config.SingleSwitch = True
                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData
                Parameterlist.NextAction = 7
            Case 7 '搜索APP设备
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                    Parameterlist.NextAction = 5
                    Return
                End If
                '获取发送地址
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"群发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 8
            Case 8 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时跳处理
                    Parameterlist.NextAction = 9
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then
                    '    'Parameterlist.NextAction = 9
                    '    ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If
            Case 9 '处理APP设备回复
                'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                Parameterlist.NextAction = 2
                m_config.SingleSwitch = False


            Case 5 '搜索结束
                ' If m_config.SearchEquipmentProcessSwitch Then
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                'End If
                Parameterlist.EnableFlag = False
        End Select
    End Sub

    Public Overrides Sub NewSearchEquipmentProcess(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As SerialController = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()

        'Console.WriteLine($"流程处理步骤{Parameterlist.NextAction}!")
        Select Case Parameterlist.NextAction

            Case 0
                m_config.ResendSwitch = False
                Parameterlist.NextAction = 1
                m_config.SingleSwitch = False
                g_SerialController.m_SpecialReceiveFlag = WorkflowType.SearchEquipment
                g_SerialController.recvBufferliindex = 0

            Case 1 '’设置发送器波特率为2400


                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)

                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("设置发送器波特率为2400!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                Parameterlist.NextAction = 2




            Case 2 '’搜索boll设备
                '判断是否发送超时
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                    Parameterlist.NextAction = 5
                    Return
                End If
                '获取发送地址
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType
                runnode.CmdReceiveData.Clear()
                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 3





            Case 3 '等待boll设备回复
                '判断超时
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 4
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 4
                        '如果有接收处理
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 4 '处理boll设备回复
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                g_SerialController.recvBufferli.Clear()
                g_SerialController.recvBufferliindex = 0
                Parameterlist.NextAction = 6

            Case 6 '设置发送器波特率为APP的波特率
                '设置发送器波特率为2400
                ''If g_SerialController.IsSerialData Then
                '    Thread.Sleep(100)
                '    Return
                'End If
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                Parameterlist.NextAction = 7
                Thread.Sleep(100)
            Case 7 '搜索APP设备
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                    Parameterlist.NextAction = 5
                    Return
                End If
                '获取发送地址
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), runnode.CmdSendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 8
            Case 8 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时跳处理
                    Parameterlist.NextAction = 9
                    Return
                Else
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 9
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 9 '处理APP设备回复
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                g_SerialController.recvBufferli.Clear()
                g_SerialController.recvBufferliindex = 0
                Parameterlist.NextAction = 1
                'Thread.Sleep(1000)


            Case 5 '搜索结束
                ' If m_config.SearchEquipmentProcessSwitch Then
                g_SerialController.m_SpecialReceiveFlag = -1
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                'End If
                Parameterlist.EnableFlag = False
        End Select
    End Sub

    '获取接收地址
    Public Function GetReceivingAddress(Parameterlist As Parameterlist) As Integer
        If Parameterlist.ReceiveAddress = 255 Then
            Return 255
        End If

        If Parameterlist.ReceiveAddressRangeLength > 0 Then

            If Parameterlist.ReceiveAddress > m_config.ReceiverAddress Then
                Return Parameterlist.ReceiveAddress
            End If


            If m_config.ReceiverAddress < (Parameterlist.ReceiveAddress + Parameterlist.ReceiveAddressRangeLength) - 1 Then
                Return m_config.ReceiverAddress + 1
            Else
                Return Parameterlist.ReceiveAddress
            End If
        Else
            Return -1
        End If

    End Function



    Public Overrides Sub NewUpgradeProcess(Parameterlist As Parameterlist)

        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As SerialController = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim ReceiveData As Byte()

        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                m_config.SingleSwitch = False
                Parameterlist.NextAction = 1
                g_SerialController.m_SpecialReceiveFlag = -1
                For Each item In Parameterlist.ProcessList
                    item.Item2.CmdSendCountNow = 0
                    item.Item2.CmdWriteIndex = 0
                    item.Item2.CmdReceiveStatus = False
                Next

                m_config.MyAddress = Parameterlist.StartAddress
                If Parameterlist.addtypeliindx < Parameterlist.addtypeli.Count Then
                    m_config.ReceiverAddress = Parameterlist.addtypeli(Parameterlist.addtypeliindx).Item1
                    m_config.DeviceType = Parameterlist.addtypeli(Parameterlist.addtypeliindx).Item2
                    Parameterlist.addtypeliindx += 1
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "升级就绪", Color.White)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级就绪!", Color.White), 1)
                Else
                    Parameterlist.NextAction = 50
                End If



            Case 1 '’修改波特率
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                ' AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 2               '



            Case 2 '搜索boll设备
                '判断是否发送超时
                'If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                '    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                '    Parameterlist.NextAction = 5
                '    Return
                'End If
                '获取发送地址
                'sendAddress = 'GetReceivingAddress(Parameterlist)
                'If sendAddress = -1 Then
                '    Parameterlist.NextAction = 5
                '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                '    Return
                'End If
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"重发搜索命令!", Color.DarkGreen), 1)
                End If

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 3


            Case 3 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 5
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"重发搜索命令!", Color.Black), 1)
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        ' 判断在那个区
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 22
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                Parameterlist.NextAction = 9
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "5", Color.White)
                                Return

                            End If
                        Next


                        Parameterlist.NextAction = 5
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 4 '处理boll设备回复
                'If runnode.CmdReceiveStatus Then 'boot收到回复
                '    '判断回复设备地址是否正确
                '    ReceiveData = runnode.CmdReceiveData(0).Item2
                '    If ReceiveData(0) = runnode.CmdSendData(3) AndAlso ((ReceiveData(1) And 16) = (ReceiveData(1) And 16)) AndAlso ReceiveData(3) = runnode.CmdSendData(0) Then



                '    End If

                'Else
                '    '判断是否到达最大重发次数
                '    'If Parameterlist.CmdSendCount < 3 Then

                '    'Else
                '    Parameterlist.NextAction = 5
                '    'End If

                'End If
                Parameterlist.NextAction = 5



            Case 5 '设置发送器波特率为APP的波特率
                'If g_SerialController.IsSerialData Then Return
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 6

            Case 6 '搜索APP设备
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 7

            Case 7 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 8
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复
                        ' 判断在那个区
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 22
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                Parameterlist.NextAction = 9
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "5", Color.White)
                                Return

                            End If
                        Next
                        Parameterlist.NextAction = 8
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 8 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 1


            Case 9 '设置跳转波特率
                'If g_SerialController.IsSerialData Then Return
                ' AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 10
              '

            Case 10 '发送跳转命令

                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    m_config.ResendSwitch = False
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"跳转失败或跳转超时！！", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "跳转失败或跳转超时", Color.Red)

                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"重发跳转命令!", Color.DarkGreen), 1)
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 1)
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 11


            Case 11 '等待跳转命令回复 APP跳boot
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 12
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 13
                                Parameterlist.CurrentStep = CmdType.SearchCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "10", Color.White)
                                Return
                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 12
                        Return
                        'Parameterlist.NextAction = 4

                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 12 '处理跳转结果
                Parameterlist.NextAction = 10
                runnode.CmdSendCountNow += 1


            Case 13 '修改成boot波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SearchCommand
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 14
            Case 14 '搜索boll设备

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索失败或超时！！", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "搜索失败或超时", Color.Red)
                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"重发搜索命令!", Color.DarkGreen), 1)
                End If
                'm_config.MyAddress = Parameterlist.StartAddress
                'm_config.ReceiverAddress = Parameterlist.ReceiveAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 15



            Case 15 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 17
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 22
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                'Parameterlist.NextAction = 9
                                'Parameterlist.CurrentStep = CmdType.skipCommand
                                'm_config.ResendSwitch = False
                                'Return

                            End If
                        Next
                        Parameterlist.NextAction = 16
                        Return

                        ' Parameterlist.NextAction = 22
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 16 '处理boll设备回复
                Parameterlist.NextAction = 17

            Case 17 '设置APP波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 18



            Case 18 '搜索APP设备
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 19


            Case 19 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 20
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 22
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                'Parameterlist.NextAction = 9
                                'Parameterlist.CurrentStep = CmdType.skipCommand
                                'm_config.ResendSwitch = False
                                'Return

                            End If
                        Next
                        Parameterlist.NextAction = 20
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 20 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 21

            Case 21 '设置发送器波特率为2400
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 14


            Case 22  '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 23
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SetUpParameters

            Case 23 '发送设置波特率命令
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.EraseFlashData
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时!", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                g_SendData = AssembleCommandData1(CmdType.SetUpParameters， runnode.CmdArgs(0), runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送设置升级波特率命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 24

            Case 24 '等待设置波特率回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 25
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 41
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.EraseFlashData
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "25", Color.White)

                                Return
                            Else

                            End If
                        Next


                        Parameterlist.NextAction = 25
                        Return

                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 25 '处理设置波特率回复结果
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 23



            Case 41 '修改成boot波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SearchCommand
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 42
            Case 42 '搜索boll设备

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索设备失败或超时！！", Color.Black), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "搜索设备失败或超时", Color.Red)
                    Return
                End If
                'm_config.MyAddress = Parameterlist.StartAddress
                'm_config.ReceiverAddress = Parameterlist.ReceiveAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 43



            Case 43 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 44
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                Parameterlist.NextAction = 40
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.EraseFlashData
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "30", Color.White)
                                Return
                            Else

                            End If
                        Next
                        Parameterlist.NextAction = 44
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 44 '处理boll设备回复
                Parameterlist.NextAction = 48

            'Case 45 '设置APP波特率
            '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate  }!", Color.Black), 1)
            '    g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
            '    Parameterlist.NextAction = 46



            'Case 46 '搜索APP设备
            '    g_SerialController.m_ReceiveQueue.Clear()
            '    g_SerialController.m_ReceiveQueue.Add(runnode)
            '    runnode.setCmdReceiveStatus(False)
            '    '发送搜索命令
            '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
            '    g_SerialControllerSendData(g_SerialController,runnode)
            '    Parameterlist.NextAction = 47


            'Case 47 '等待APP设备回复
            '    If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
            '        '设置重发标志
            '        Parameterlist.NextAction = 48
            '        Return
            '    Else
            '        'If runnode.CmdReceiveStatus Then 'boot收到回复
            '        '    Parameterlist.NextAction = 4
            '        '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
            '        'Else
            '        '    Return
            '        'End If
            '    End If


            Case 48 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 49

            Case 49 '设置发送器波特率为2400
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                Parameterlist.NextAction = 42

            Case 40 '切换波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                Parameterlist.NextAction = 26
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.EraseFlashData
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 26

            Case 26 '发送 擦除Flash数据命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.WriteFlashData
                    m_config.ResendSwitch = False
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}失败或超时!", Color.Black), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "擦除Flash数据失败", Color.Red)
                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始重发发送擦除Flash数据命令!", Color.DarkGreen), 1)
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                g_SendData = AssembleCommandData1(CmdType.EraseFlashData， runnode.CmdArgs(0), runnode.CmdArgs(1), runnode.CmdArgs(2))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送擦除Flash数据命令。{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 27

            Case 27 '处理擦除结果
                '打印超时
                Console.WriteLine($"{runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval)} <{Now}")
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 28
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 29
                                Parameterlist.CurrentStep = CmdType.WriteFlashData
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "35", Color.White)
                                Return
                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 28
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 28 '处理擦除Flash数据命令返回
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 26

            Case 29 '发送写入EEPROM数据命令
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)

                If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                    Parameterlist.NextAction = 32
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.CheckCommand
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "90", Color.White)
                    Return
                Else '继续发送
                    If runnode.CmdSendCountNow >= runnode.CmdSendCount Then  '到达重上限
                        Parameterlist.NextAction = 39
                        runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                        runnode.CmdSendCountNow = 0
                        m_config.ResendSwitch = False
                        'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "发送升级数据包失败", Color.Red)
                        AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级数据包失败【{runnode.CmdWriteIndex.ToString}】失败或超时!", Color.Red), 1)
                        Return
                        'Else
                        '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始重发升级数据包【{runnode.CmdWriteIndex.ToString}】!", Color.DarkGreen), 1)
                    End If
                End If
                Dim listnide = gSendFileconig.Sendlist(runnode.CmdWriteIndex)
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                If runnode.CmdWriteIndex = 250 Then
                    Console.WriteLine("250")
                End If
                g_SendData = AssembleCommandData1(CmdType.WriteFlashData， listnide.Item1, ByteArrayToHexString(listnide.Item2.ToArray))
                runnode.CmdSendData = g_SendData

                SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, $"{runnode.CmdWriteIndex}/{gSendFileconig.Sendlist.Count}", Color.White, Parameterlist.RText_OutputText)
                runnode.CmdReceiveData.Clear()
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送升级数据包：【{runnode.CmdWriteIndex.ToString}】!", Color.DarkGreen), 0)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode， 0)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                ', New Font("宋体", 8), runnode.CmdSendData
                Parameterlist.NextAction = 30

            Case 30 'd处理写入EEPROM数据命令返回
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 31
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 29
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 29
                                runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                                runnode.CmdSendCountNow = 0
                                m_config.ResendSwitch = False
                                Return
                            Else

                            End If
                        Next


                        runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                        Parameterlist.NextAction = 29
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 31 '校验升级结果
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 29



            Case 32 '发送检测升级结果命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then

                    Parameterlist.NextAction = 39
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"校验失败!", Color.Black), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "校验失败", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)
                Dim li As List(Of Integer) = CheckCommand(gSendFileconig)
                g_SendData = AssembleCommandData1(CmdType.CheckCommand, gSendFileconig.SendAddr, gSendFileconig.EndAddr, gSendFileconig.BlockLength, JsonConvert.SerializeObject(li))
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级校验命令!", Color.Black), 1)
                runnode.CmdSendData = g_SendData
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData, 0))
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 33


            Case 33 '等待检测升级结果命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 34
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 32
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 35
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "100", Color.Green)
                                Return
                            Else

                            End If
                        Next


                        runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                        Parameterlist.NextAction = 32
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 34 '处理检测升级结果命令回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 32
            Case 35 '设置跳转参数

                runnode.CmdSendCountNow = 0
                ' m_config.ResendSwitch = False
                runnode.CmdArgs(0) = 2
                Parameterlist.NextAction = 36


            Case 36 '发送跳转命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令失败或超时！！", Color.Black), 1)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 2)
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 37

            Case 37 ' 等待跳转命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 38
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot

                                '判断升级列表是否为空
                                SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, $"升级完成", Color.Green)
                                Parameterlist.NextAction = 0
                                Parameterlist.CurrentStep = CmdType.SearchCommand
                                Return

                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 38
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 38 ' 处理跳转命令回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 36


            Case 39 '结束
                Parameterlist.NextAction = 0
                Parameterlist.CurrentStep = CmdType.SearchCommand
            Case 50
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束升级设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                Parameterlist.EnableFlag = False
        End Select



    End Sub

    Public Overrides Sub NewFlashGroupUpgrade(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As SerialController = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim ReceiveData As Byte()

        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                m_config.SingleSwitch = True
                Parameterlist.NextAction = 1
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1 '’修改波特率
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 2               '

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = Parameterlist.ReceiveAddress
                m_config.DeviceType = Parameterlist.DeviceType

            Case 2 '搜索boll设备
                '判断是否发送超时
                'If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                '    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"到达", Color.Red), 1)
                '    Parameterlist.NextAction = 5
                '    Return
                'End If
                '获取发送地址
                'sendAddress = 'GetReceivingAddress(Parameterlist)
                'If sendAddress = -1 Then
                '    Parameterlist.NextAction = 5
                '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                '    Return
                'End If
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 9
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    Return
                End If

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 3


            Case 3 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 4
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If


            Case 4 '处理boll设备回复
                'If runnode.CmdReceiveStatus Then 'boot收到回复
                '    '判断回复设备地址是否正确
                '    ReceiveData = runnode.CmdReceiveData(0).Item2
                '    If ReceiveData(0) = runnode.CmdSendData(3) AndAlso ((ReceiveData(1) And 16) = (ReceiveData(1) And 16)) AndAlso ReceiveData(3) = runnode.CmdSendData(0) Then



                '    End If

                'Else
                '    '判断是否到达最大重发次数
                '    'If Parameterlist.CmdSendCount < 3 Then

                '    'Else
                '    Parameterlist.NextAction = 5
                '    'End If

                'End If
                Parameterlist.NextAction = 5



            Case 5 '设置发送器波特率为APP的波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 6

            Case 6 '搜索APP设备
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 7

            Case 7 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 8
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If
            Case 8 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 1


            Case 9 '设置跳转波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 10
              '

            Case 10 '发送跳转命令

                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 13
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    m_config.ResendSwitch = False
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， runnode.CmdArgs(0))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 11


            Case 11 '等待跳转命令回复 APP跳boot
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 12
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If


            Case 12 '处理跳转结果
                Parameterlist.NextAction = 10
                runnode.CmdSendCountNow += 1


            Case 13 '修改成boot波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SearchCommand
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 14
            Case 14 '搜索boll设备

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 22
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = Parameterlist.ReceiveAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 15



            Case 15 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 16
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If
            Case 16 '处理boll设备回复
                Parameterlist.NextAction = 17

            Case 17 '设置APP波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.AppBaudRate)
                Parameterlist.NextAction = 18



            Case 18 '搜索APP设备
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 19


            Case 19 '等待APP设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 20
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If


            Case 20 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 21

            Case 21 '设置发送器波特率为2400
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 14


            Case 22  '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.BootBaudRate)
                Parameterlist.NextAction = 23
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SetUpParameters

            Case 23 '发送设置波特率命令
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 41
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.EraseFlashData
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                g_SendData = AssembleCommandData1(CmdType.SetUpParameters， runnode.CmdArgs(0), runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送设置升级波特率命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 24

            Case 24 '等待设置波特率回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 25
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If


            Case 25 '处理设置波特率回复结果
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 23



            Case 41 '修改成boot波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.SearchCommand
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 42
            Case 42 '搜索boll设备

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 40
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = Parameterlist.ReceiveAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                runnode.CmdSendData = g_SendData

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                '发送搜索命令
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 43



            Case 43 '等待boll设备回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 44
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If
            Case 44 '处理boll设备回复
                Parameterlist.NextAction = 48

            'Case 45 '设置APP波特率
            '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate  }!", Color.Black), 1)
            '    g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
            '    Parameterlist.NextAction = 46



            'Case 46 '搜索APP设备
            '    g_SerialController.m_ReceiveQueue.Clear()
            '    g_SerialController.m_ReceiveQueue.Add(runnode)
            '    runnode.setCmdReceiveStatus(False)
            '    '发送搜索命令
            '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(runnode.CmdSendData)}", Color.Black), 1)
            '    g_SerialControllerSendData(g_SerialController,runnode)
            '    Parameterlist.NextAction = 47


            'Case 47 '等待APP设备回复
            '    If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
            '        '设置重发标志
            '        Parameterlist.NextAction = 48
            '        Return
            '    Else
            '        'If runnode.CmdReceiveStatus Then 'boot收到回复
            '        '    Parameterlist.NextAction = 4
            '        '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
            '        'Else
            '        '    Return
            '        'End If
            '    End If


            Case 48 '处理APP设备回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 49

            Case 49 '设置发送器波特率为2400
                '设置发送器波特率为2400
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                Parameterlist.NextAction = 42

            Case 40 '切换波特率
                'If g_SerialController.IsSerialData Then Return
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                g_SerialController.SetBaudRate(Parameterlist.UpgradeBaudRate)
                Parameterlist.NextAction = 26
                m_config.ResendSwitch = False
                Parameterlist.CurrentStep = CmdType.EraseFlashData
                runnode.CmdSendCountNow = 0
                Parameterlist.NextAction = 26

            Case 26 '发送 擦除Flash数据命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 29
                    Parameterlist.CurrentStep = CmdType.WriteFlashData
                    m_config.ResendSwitch = False
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                g_SendData = AssembleCommandData1(CmdType.EraseFlashData， runnode.CmdArgs(0), runnode.CmdArgs(1), runnode.CmdArgs(2))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送擦除Flash数据命令。{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 27

            Case 27 '处理擦除结果
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 28
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If

            Case 28 '处理擦除Flash数据命令返回
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 26

            Case 29 '发送写入EEPROM数据命令
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)

                If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                    Parameterlist.NextAction = 32
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.CheckCommand
                    Return
                Else '继续发送
                    If runnode.CmdSendCountNow >= runnode.CmdSendCount Then  '到达重上限
                        runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                        runnode.CmdSendCountNow = 0
                        m_config.ResendSwitch = False
                    End If
                    If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                        AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                        Parameterlist.NextAction = 32
                        m_config.ResendSwitch = False
                        Parameterlist.CurrentStep = CmdType.CheckCommand
                        Return
                    End If
                End If
                Dim listnide = gSendFileconig.Sendlist(runnode.CmdWriteIndex)
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                g_SendData = AssembleCommandData1(CmdType.WriteFlashData， listnide.Item1, ByteArrayToHexString(listnide.Item2.ToArray))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送升级数据包【{runnode.CmdWriteIndex.ToString}】!", Color.Blue), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData, 1))
                Parameterlist.NextAction = 30

            Case 30 'd处理写入EEPROM数据命令返回
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 31
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 29
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If
            Case 31 '校验升级结果
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 29



            Case 32 '发送检测升级结果命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 35
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)
                Dim li As List(Of Integer) = CheckCommand(gSendFileconig)
                g_SendData = AssembleCommandData1(CmdType.CheckCommand, gSendFileconig.SendAddr, gSendFileconig.EndAddr, gSendFileconig.BlockLength, JsonConvert.SerializeObject(li))
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级校验命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdSendData = g_SendData
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 33


            Case 33 '等待检测升级结果命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 34
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 32
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If

            Case 34 '处理检测升级结果命令回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 32
            Case 35 '设置跳转参数

                runnode.CmdSendCountNow = 0
                ' m_config.ResendSwitch = False
                runnode.CmdArgs(0) = 2
                Parameterlist.NextAction = 36


            Case 36 '发送跳转命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， runnode.CmdArgs(0))
                runnode.CmdSendData = g_SendData
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 37

            Case 37 ' 等待跳转命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 38
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    '    Return
                    'End If
                End If

            Case 38 ' 处理跳转命令回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 36


            Case 39 '结束
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                Parameterlist.EnableFlag = False
        End Select



    End Sub
    Public Sub g_SerialControllerSendData(RText_OutputText As RichTextBox, SerialController As Transmitter, data As Cmdconfig, Optional lev As Integer = 1)
        AddQueue(RText_OutputText, New RuningLogConfig($"TX:", Color.DarkGreen, New Font("宋体", 8), data.CmdSendData), lev)
        SerialController.SendData(data)

    End Sub
    Public Sub g_SerialControllerSendData(RText_OutputText As RichTextBox, SerialController As Transmitter, data() As Byte, Optional lev As Integer = 1)
        AddQueue(RText_OutputText, New RuningLogConfig($"TX:", Color.DarkGreen, New Font("宋体", 8), data), lev)
        SerialController.SendData(data)

    End Sub
    Public Overrides Sub NewSearchEquipmentProcess2(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As DevNetworkCommunication = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim BootBaudindex As Integer
        Dim SendDatalist As List(Of Byte)
        Select Case Parameterlist.NextAction
            Case 0   '就绪
                m_config.ResendSwitch = False
                Parameterlist.NextAction = 1
                m_config.SingleSwitch = False
                g_SerialController.m_SpecialReceiveFlag = WorkflowType.SearchEquipment

                'g_SerialController.recvBufferliindex = 0
            Case 1 '设置为透传模式 boot波特率

                '判断是否发送超时
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    Parameterlist.NextAction = 5
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 2

            Case 2 '等待回复

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 3
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 3
                        'End If
                    End If
                End If



            Case 3 '发送询问模式
                '判断是否发送超时
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    Parameterlist.NextAction = 5
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 4



            Case 4 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 6
                        Else
                            Parameterlist.NextAction = 1
                            Return
                        End If
                    End If
                End If

            Case 6 '等待回复
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 7

            Case 7 '处理回复
                '判断超时
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 8
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 4
                        '如果有接收处理
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 8 '发送boot握手
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                g_SerialController.recvBufferli.Clear()
                'g_SerialController.recvBufferliindex = 0
                Parameterlist.NextAction = 9

            Case 9 '等待回复

                '判断是否发送超时


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.AppBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.NTimeOut, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置发送器波特率为{Parameterlist.AppBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 10

            Case 10 '处理回复

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 11
                        'End If
                    End If
                End If

            Case 11 '设置为透传模式 APP波特率
                '判断是否发送超时

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)

                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)


                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 12

            Case 12 '处理回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 13
                        Else
                            Parameterlist.NextAction = 9
                            Return
                        End If
                    End If
                End If
            Case 13 '等待回复
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                'runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 14

            Case 14 '发送询问模式
                '判断超时
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 15
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 4
                        '如果有接收处理
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 15 '等待回复
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                g_SerialController.recvBufferli.Clear()
                'g_SerialController.recvBufferliindex = 0
                Parameterlist.NextAction = 1
            Case 16 '发送APP握手

            Case 17 '等待回复

            Case 18 '处理回复

            Case 5 '处理回复
                ' If m_config.SearchEquipmentProcessSwitch Then
                g_SerialController.m_SpecialReceiveFlag = -1
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                'End If
                Parameterlist.EnableFlag = False
        End Select

    End Sub

    Public Overrides Sub NewBootSearchEquipmentProcess2(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As DevNetworkCommunication = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim ReceiveData As Byte()
        Dim BootBaudindex As Integer
        Dim SendDatalist As List(Of Byte)
        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                m_config.SingleSwitch = False
                Parameterlist.NextAction = 1
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1 '发送搜索命令
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    Parameterlist.NextAction = 5
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 2
            Case 2 '等待回复

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 3
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 3
                        'End If
                    End If
                End If



            Case 3 '发送询问模式
                '判断是否发送超时
                If runnode.NodeCreateTime.AddSeconds(runnode.CmdSendcontinueTime) < Now Then
                    Parameterlist.NextAction = 5
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 4



            Case 4 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 6
                        Else
                            Parameterlist.NextAction = 1
                            Return
                        End If
                    End If
                End If

            Case 6 '等待回复
                sendAddress = GetReceivingAddress(Parameterlist)
                If sendAddress = -1 Then
                    Parameterlist.NextAction = 5
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"搜索范围长度为0停止搜索", Color.Red), 1)
                    Return
                End If
                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.CmdReceiveData.Clear()
                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 7

            Case 7 '处理回复
                '判断超时
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 8
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then
                        'Parameterlist.NextAction = 4
                        '如果有接收处理
                        ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 8 '发送boot握手
                ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                g_SerialController.recvBufferli.Clear()
                'g_SerialController.recvBufferliindex = 0
                Parameterlist.NextAction = 1

            Case 5 '处理回复
                ' If m_config.SearchEquipmentProcessSwitch Then
                g_SerialController.m_SpecialReceiveFlag = -1
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束搜索设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                'End If
                Parameterlist.EnableFlag = False


        End Select
    End Sub

    Public Overrides Sub NewUpgradeProcess2(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As DevNetworkCommunication = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim ReceiveData As Byte()
        Dim BootBaudindex As Integer
        Dim SendDatalist As List(Of Byte)
        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                m_config.SingleSwitch = False
                Parameterlist.NextAction = 1
                g_SerialController.m_SpecialReceiveFlag = -1
                For Each item In Parameterlist.ProcessList
                    item.Item2.CmdSendCountNow = 0
                    item.Item2.CmdWriteIndex = 0
                    item.Item2.CmdReceiveStatus = False
                Next

                m_config.MyAddress = Parameterlist.StartAddress
                If Parameterlist.addtypeliindx < Parameterlist.addtypeli.Count Then
                    m_config.ReceiverAddress = Parameterlist.addtypeli(Parameterlist.addtypeliindx).Item1
                    m_config.DeviceType = Parameterlist.addtypeli(Parameterlist.addtypeliindx).Item2
                    Parameterlist.addtypeliindx += 1
                    ' SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "0%", Color.White)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级就绪!", Color.White), 1)
                Else
                    Parameterlist.NextAction = 70
                End If
            Case 1 '
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 2

            Case 2 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 3
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 3 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 4
            Case 4 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 3
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 5

                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If
            Case 5

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 7
                    runnode.CmdSendCountNow = 0
                    'Parameterlist.CurrentStep = CmdType.skipCommand
                    'm_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.CmdReceiveData.Clear()
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 6

            Case 6
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 5
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then 'boot收到回复
                        ' 判断在那个区
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 21
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                Parameterlist.NextAction = 13
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "5", Color.White)
                                Return

                            End If
                        Next

                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 7
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.AppBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.AppBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 8

            Case 8

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 7
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 9
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If
            Case 9

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 10

            Case 10

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 9
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 11
                            runnode.CmdSendCountNow = 0
                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If
            Case 11

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    runnode.CmdSendCountNow = 0
                    'Parameterlist.CurrentStep = CmdType.skipCommand
                    'm_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.CmdReceiveData.Clear()
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)





                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 12

            Case 12

                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 11
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then 'boot收到回复
                        ' 判断在那个区
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 21
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                Parameterlist.NextAction = 13
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "5", Color.White)
                                Return

                            End If
                        Next

                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 13 '跳转boot

                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    m_config.ResendSwitch = False
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"跳转失败或跳转超时！！", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "跳转失败或跳转超时", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut}) 'Parameterlist.NTimeOut
                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 1)
                SendDatalist.AddRange(g_SendData)

                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 14

            Case 14
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 13
                    runnode.CmdSendCountNow += 1
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 15
                                Parameterlist.CurrentStep = CmdType.SearchCommand
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "10", Color.White)
                                Return
                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 13
                        runnode.CmdSendCountNow += 1
                        Return
                        'Parameterlist.NextAction = 4

                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 15 '

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 16

            Case 16
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 15
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 17
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If


            Case 17 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 18
            Case 18 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 3
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 19
                            runnode.CmdSendCountNow = 0
                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If

            Case 19
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    runnode.CmdSendCountNow = 0
                    'Parameterlist.CurrentStep = CmdType.skipCommand
                    'm_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.CmdReceiveData.Clear()
                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 20

            Case 20
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 19
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '未超时
                    If runnode.CmdReceiveStatus Then 'boot收到回复
                        ' 判断在那个区
                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                'gTable.Rows(gTable.Rows.Count - 1).Cells(5).Value = "Boot"
                                Parameterlist.NextAction = 22
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.SetUpParameters
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "20", Color.White)
                                Return
                            ElseIf node.Item2(8) = 2 Then 'app
                                'Parameterlist.NextAction = 13
                                'Parameterlist.CurrentStep = CmdType.skipCommand
                                'm_config.ResendSwitch = False
                                ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "5", Color.White)
                                Return

                            End If
                        Next

                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If


            Case 21 '设置升级波特率

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.EraseFlashData
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时!", Color.Red), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SetUpParameters， runnode.CmdArgs(0), runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)



                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送设置升级波特率命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 22

            Case 22 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 21
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 41
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.EraseFlashData
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "25", Color.White)

                                Return
                            Else

                            End If
                        Next


                        Parameterlist.NextAction = 21
                        runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                        Return

                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If



            Case 41 '设置升级波特率

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.UpgradeBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.UpgradeBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 42

            Case 42 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 41
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 23
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 23 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 24
            Case 24 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 23
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 25
                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If
            Case 25

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    runnode.CmdSendCountNow = 0
                    'Parameterlist.CurrentStep = CmdType.skipCommand
                    'm_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                'm_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.CmdReceiveData.Clear()

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)



                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 26

            Case 26
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 25
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 1 Then 'boot
                                Parameterlist.NextAction = 27
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.EraseFlashData
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "30", Color.White)
                                Return
                            Else

                            End If
                        Next
                        Parameterlist.NextAction = 25
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If
            Case 27 '发送擦除
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.WriteFlashData
                    m_config.ResendSwitch = False
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}失败或超时!", Color.Black), 1)
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "擦除Flash数据失败", Color.Red)
                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始重发发送擦除Flash数据命令!", Color.DarkGreen), 1)
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.EraseFlashData， runnode.CmdArgs(0), runnode.CmdArgs(1), runnode.CmdArgs(2))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)



                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送擦除Flash数据命令。{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 28

            Case 28 '处理擦除结果
                '打印超时
                Console.WriteLine($"{runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval)} <{Now}")
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 27
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复

                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 29
                                Parameterlist.CurrentStep = CmdType.WriteFlashData
                                m_config.ResendSwitch = False
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "35", Color.White)
                                Return
                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 27
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 29 '发送写入

                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)

                If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                    Parameterlist.NextAction = 32
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.CheckCommand
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "90", Color.White)
                    Return
                Else '继续发送
                    If runnode.CmdSendCountNow >= runnode.CmdSendCount Then  '到达重上限
                        Parameterlist.NextAction = 39
                        runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                        runnode.CmdSendCountNow = 0
                        m_config.ResendSwitch = False
                        AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级数据包失败【{runnode.CmdWriteIndex.ToString}】失败或超时!", Color.Red), 1)
                        Return
                        'Else
                        '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始重发升级数据包【{runnode.CmdWriteIndex.ToString}】!", Color.DarkGreen), 1)
                    End If
                End If
                Dim listnide = gSendFileconig.Sendlist(runnode.CmdWriteIndex)
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.WriteFlashData， listnide.Item1, ByteArrayToHexString(listnide.Item2.ToArray))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)

                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送升级数据包【{runnode.CmdWriteIndex.ToString}】!", Color.Blue), 1)
                SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, $"{runnode.CmdWriteIndex}/{gSendFileconig.Sendlist.Count}", Color.White)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode， 0)
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData, 0))
                Parameterlist.NextAction = 30


            Case 30
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 31
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 29
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 29
                                runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                                runnode.CmdSendCountNow = 0
                                m_config.ResendSwitch = False
                                Return
                            Else

                            End If
                        Next


                        runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                        Parameterlist.NextAction = 29
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 31
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 29
            Case 32 '发送检测升级结果命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then

                    Parameterlist.NextAction = 39
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"校验失败!", Color.Black), 1)
                    'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "校验失败", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)
                Dim li As List(Of Integer) = CheckCommand(gSendFileconig)


                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.CheckCommand, gSendFileconig.SendAddr, gSendFileconig.EndAddr, gSendFileconig.BlockLength, JsonConvert.SerializeObject(li))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级校验命令!", Color.Black), 1)

                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData, 0))
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 33

            Case 33
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 34
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 32
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot
                                Parameterlist.NextAction = 35
                                m_config.ResendSwitch = False
                                Parameterlist.CurrentStep = CmdType.skipCommand
                                'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "100", Color.Green)
                                Return
                            Else

                            End If
                        Next


                        runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                        Parameterlist.NextAction = 32
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If

            Case 35 '设置跳转参数

                runnode.CmdSendCountNow = 0
                ' m_config.ResendSwitch = False
                runnode.CmdArgs(0) = 2
                Parameterlist.NextAction = 36


            Case 36 '发送跳转命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 39
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令失败或超时！！", Color.Black), 1)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 2)
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)

                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 37

            Case 37 ' 等待跳转命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 38
                    Return
                Else
                    If runnode.CmdReceiveStatus Then 'boot收到回复


                        For Each node In runnode.CmdReceiveData
                            If node.Item2(8) = 0 Then 'boot

                                '判断升级列表是否为空
                                SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, $"升级完成", Color.Green)
                                Parameterlist.NextAction = 0
                                Parameterlist.CurrentStep = CmdType.SearchCommand
                                Return

                            Else

                            End If
                        Next

                        Parameterlist.NextAction = 38
                        Return
                        'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    Else
                        Return
                    End If
                End If



            Case 38 ' 处理跳转命令回复
                runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                Parameterlist.NextAction = 36


            Case 39 '结束
                Parameterlist.NextAction = 0
                Parameterlist.CurrentStep = CmdType.SearchCommand

            Case 70
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束升级设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                Parameterlist.EnableFlag = False
        End Select


    End Sub

    Public Overrides Sub NewFlashGroupUpgrade2(Parameterlist As Parameterlist)
        Dim runnode As Cmdconfig = GetSendNode(Parameterlist.CurrentStep, Parameterlist.ProcessList)

        Dim g_SerialController As DevNetworkCommunication = m_Transmitter

        Dim sendAddress As Integer
        Dim g_SendData As Byte()
        Dim ReceiveData As Byte()
        Dim BootBaudindex As Integer
        Dim SendDatalist As List(Of Byte)

        Select Case Parameterlist.NextAction
            Case 0
                m_config.ResendSwitch = False
                m_config.SingleSwitch = True
                Parameterlist.NextAction = 1
                g_SerialController.m_SpecialReceiveFlag = -1
            Case 1
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 2

            Case 2 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 1
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 3
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 3 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 4
            Case 4 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 3
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 5

                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If


            Case 5

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 41
                    runnode.CmdSendCountNow = 0
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If




                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.CmdReceiveData.Clear()
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 6

            Case 6
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 5
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    Return
                    '未超时

                End If



            Case 41
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.AppBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.AppBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 42

            Case 42 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 41
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 43
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 43 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 44
            Case 44 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 43
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 45

                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If


            Case 45

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 7
                    runnode.CmdSendCountNow = 0
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If


                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.CmdReceiveData.Clear()
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 46

            Case 46
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 45
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    Return
                    '未超时

                End If

            Case 7
                '判断是否到达重发次数
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    runnode.CmdSendCountNow = 0
                    Parameterlist.NextAction = 9
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    m_config.ResendSwitch = False
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.CmdReceiveData.Clear()


                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut}) 'Parameterlist.NTimeOut
                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 1)
                SendDatalist.AddRange(g_SendData)

                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 8

            Case 8
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 7
                    runnode.CmdSendCountNow += 1
                    Return
                Else
                    Return
                End If


            Case 9 '

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    runnode.CmdSendCountNow = 0
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.BootBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.BootBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 10

            Case 10
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 15
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 11
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If


            Case 11 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 12
            Case 12 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 11
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 13
                            runnode.CmdSendCountNow = 0
                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If

            Case 13



                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 15
                    runnode.CmdSendCountNow = 0
                    Parameterlist.CurrentStep = CmdType.SetUpParameters
                    m_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If




                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.CmdReceiveData.Clear()
                runnode.setCmdReceiveStatus(False)

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)


                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 14

            Case 14
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 13
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    Return                    '未超时
                End If




            Case 15 '设置升级波特率

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 17
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.EraseFlashData
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时!", Color.Red), 1)
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "设置升级波特率为{Parameterlist.UpgradeBaudRate }失败或超时", Color.Red)
                    Thread.Sleep(5000)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SetUpParameters， runnode.CmdArgs(0), runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)



                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置升级波特率为{Parameterlist.UpgradeBaudRate }!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送设置升级波特率命令{ByteToString2(g_SendData)}!", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 16

            Case 16 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 15
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1

                    Return
                Else
                    Return

                End If



            Case 17 '设置升级波特率

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.UpgradeBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2}) '30 =Parameterlist.NTimeOut
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.UpgradeBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 18

            Case 18 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 17
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 19
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 19 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 20
            Case 20 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 19
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 21
                            Parameterlist.CurrentStep = CmdType.SearchCommand
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If
            Case 21

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 23
                    runnode.CmdSendCountNow = 0
                    Parameterlist.CurrentStep = CmdType.EraseFlashData
                    m_config.ResendSwitch = False
                    '''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"未搜索到设备或搜索超时", Color.Red), 1)
                    Return

                End If

                m_config.MyAddress = Parameterlist.StartAddress
                m_config.ReceiverAddress = sendAddress
                m_config.DeviceType = Parameterlist.DeviceType

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.CmdReceiveData.Clear()

                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.SearchCommand， runnode.CmdArgs(0)， runnode.CmdArgs(1))
                SendDatalist.AddRange(g_SendData)



                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                '发送搜索命令
                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:{ByteToString2(g_SendData)}", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送搜索命令!:", Color.Black, New Font("宋体", 8), g_SendData), 1)
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)


                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData), 1)
                Parameterlist.NextAction = 22

            Case 22
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 21
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    Return
                End If
            Case 23 '发送擦除
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 51
                    m_config.ResendSwitch = False

                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    runnode.CmdSendCountNow = 0
                    Thread.Sleep(3000)
                    ' AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}失败或超时!", Color.Black), 1)
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "擦除Flash数据失败", Color.Red)
                    Return
                    'Else
                    '    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始重发发送擦除Flash数据命令!", Color.DarkGreen), 1)
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.EraseFlashData， runnode.CmdArgs(0), runnode.CmdArgs(1), runnode.CmdArgs(2))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)



                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始擦除Flash数据。起始地址{runnode.CmdArgs(1)}-长度：{runnode.CmdArgs(2)}!", Color.Black), 1)
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送擦除Flash数据命令。{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 24

            Case 24 '处理擦除结果
                '打印超时
                'Console.WriteLine($"{runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval)} <{Now}")
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    Parameterlist.NextAction = 23
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    Return

                End If





            Case 51 '设置升级波特率

                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.WriteFlashData
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机透传模式超时！！", Color.Red), 1)
                    Return
                End If

                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                runnode.setUDPCommunicationnode()

                BootBaudindex = GetBaudRateIndex(Parameterlist.UpgradeBaudRate)
                g_SendData = FillSendDataPacket({2, Parameterlist.Throughport, BootBaudindex, Parameterlist.TransnDuion, 2}) '30 =Parameterlist.NTimeOut
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"设置主机为网络透传模式，波特率为{Parameterlist.UpgradeBaudRate}!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now
                Parameterlist.NextAction = 52

            Case 52 '等待回复
                Console.WriteLine(runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout))
                Console.WriteLine(Now)
                Console.WriteLine((Now - runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout)).TotalMilliseconds)
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 51
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_STATUS Then
                        'If runnode.OtherProtocol.UDP_TRANSPARENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                        Parameterlist.NextAction = 53
                        runnode.CmdSendCountNow = 0
                        'End If
                    End If
                End If

            Case 53 '发送升级握手


                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    m_config.ResendSwitch = False
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "未搜索到设备或搜索超时", Color.Red)
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机通讯模式超时！！", Color.Red), 1)
                    Return
                End If


                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)


                g_SendData = FillSendDataPacket({1, Parameterlist.Throughport})
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"查询主机是否进入透传模式!", Color.Black), 1)

                g_SerialControllerSendData(Parameterlist.RText_OutputText, m_Transmitter, g_SendData)
                runnode.CmdSendTime = DateTime.Now

                Parameterlist.NextAction = 54
            Case 54 '等待回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdReceiveTimeout) < Now Then
                    '超时
                    Parameterlist.NextAction = 53
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Return
                Else
                    '判断是否收到回复
                    If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_STATUS Then
                        If runnode.OtherProtocol.UDP_QUERY_HOST_CURRENT_MODE_COMMAND_REPLY_RESULT = 2 Then
                            Parameterlist.NextAction = 25
                            Parameterlist.CurrentStep = CmdType.WriteFlashData
                            m_config.ResendSwitch = False
                            runnode.CmdSendCountNow = 0
                        Else
                            Parameterlist.NextAction = 70
                            Return
                        End If
                    End If
                End If

            Case 25 '发送写入

                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)

                If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                    AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                    Parameterlist.NextAction = 27
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.CheckCommand
                    Return
                Else '继续发送
                    If runnode.CmdSendCountNow >= runnode.CmdSendCount Then  '到达重上限
                        runnode.CmdWriteIndex = runnode.CmdWriteIndex + 1
                        runnode.CmdSendCountNow = 0
                        m_config.ResendSwitch = False
                    End If
                    If runnode.CmdWriteIndex > gSendFileconig.Sendlist.Count - 1 Then ' 发送完成
                        AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"升级数据发送完毕!", Color.Black), 1)
                        Parameterlist.NextAction = 27 '发送检测升级结果命令
                        m_config.ResendSwitch = False
                        Parameterlist.CurrentStep = CmdType.CheckCommand
                        Return
                    End If
                End If
                Dim listnide = gSendFileconig.Sendlist(runnode.CmdWriteIndex)
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut}) 'Parameterlist.NTimeOut
                g_SendData = AssembleCommandData1(CmdType.WriteFlashData， listnide.Item1, ByteArrayToHexString(listnide.Item2.ToArray))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)

                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"开始发送升级数据包【{runnode.CmdWriteIndex.ToString}】!", Color.Blue), 1)
                SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, $"{runnode.CmdWriteIndex}/{gSendFileconig.Sendlist.Count}", Color.White)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode， 0)
                ' AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：{ByteToString2(runnode.CmdSendData)}", Color.DarkGreen), 1)
                Parameterlist.NextAction = 26

            Case 26 'd处理写入EEPROM数据命令返回
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 31
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 25
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复
                    '    Parameterlist.NextAction = 4
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    Return
                    'End If
                End If

            Case 27 '发送检测升级结果命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 29
                    m_config.ResendSwitch = False
                    Parameterlist.CurrentStep = CmdType.skipCommand
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"校验失败!", Color.Black), 1)
                    ''SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "校验失败", Color.Red)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)
                Dim gSendFileconig As SendFileconig = runnode.CmdArgs(0)
                Dim li As List(Of Integer) = CheckCommand(gSendFileconig)


                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(CmdType.CheckCommand, gSendFileconig.SendAddr, gSendFileconig.EndAddr, gSendFileconig.BlockLength, JsonConvert.SerializeObject(li))
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)


                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送升级校验命令!", Color.Black), 1)

                'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"TX：", Color.DarkGreen, New Font("宋体", 8), runnode.CmdSendData, 0))
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 28

            Case 28
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    'Parameterlist.NextAction = 34
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 27
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复


                    '    For Each node In runnode.CmdReceiveData
                    '        If node.Item2(8) = 0 Then 'boot
                    '            Parameterlist.NextAction = 35
                    '            m_config.ResendSwitch = False
                    '            Parameterlist.CurrentStep = CmdType.skipCommand
                    '            'SetUpgradeProgressProgressbar(Parameterlist.DataGrid, m_config.ReceiverAddress, m_config.DeviceType, "100", Color.Green)
                    '            Return
                    '        Else

                    '        End If
                    '    Next


                    '    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    '    Parameterlist.NextAction = 32
                    '    Return
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    Return
                    ' End If
                End If

            Case 29 '设置跳转参数

                runnode.CmdSendCountNow = 0
                'm_config.ResendSwitch = False
                runnode.CmdArgs(0) = 2
                Parameterlist.NextAction = 30


            Case 30 '发送跳转命令
                If runnode.CmdSendCountNow >= runnode.CmdSendCount Then
                    Parameterlist.NextAction = 70
                    Parameterlist.CurrentStep = CmdType.SearchCommand
                    'AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令失败或超时！！", Color.Black), 1)
                    Return
                End If
                g_SerialController.m_ReceiveQueue.Clear()
                g_SerialController.m_ReceiveQueue.Add(runnode)
                runnode.setCmdReceiveStatus(False)



                SendDatalist = New List(Of Byte)()
                SendDatalist.AddRange({3, Parameterlist.Throughport, Parameterlist.NTimeOut})
                g_SendData = AssembleCommandData1(Parameterlist.CurrentStep， 2)
                SendDatalist.AddRange(g_SendData)
                runnode.CmdSendData = FillSendDataPacket(SendDatalist.ToArray)

                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig($"发送跳转命令!{ByteToString2(g_SendData)}", Color.Black), 1)
                runnode.CmdReceiveData.Clear()
                g_SerialControllerSendData(Parameterlist.RText_OutputText, g_SerialController, runnode)
                Parameterlist.NextAction = 31

            Case 31 ' 等待跳转命令回复
                If runnode.CmdSendTime.AddMilliseconds(runnode.CmdSendInterval) < Now Then
                    '设置重发标志
                    runnode.CmdSendCountNow = runnode.CmdSendCountNow + 1
                    Parameterlist.NextAction = 30
                    Return
                Else
                    'If runnode.CmdReceiveStatus Then 'boot收到回复


                    '    For Each node In runnode.CmdReceiveData
                    '        If node.Item2(8) = 0 Then 'boot

                    '            '判断升级列表是否为空

                    '            Parameterlist.NextAction = 0
                    '            Parameterlist.CurrentStep = CmdType.SearchCommand
                    '            Return

                    '        Else

                    '        End If
                    '    Next

                    '    Parameterlist.NextAction = 38
                    '    Return
                    '    'ParsingCommandResponse(runnode, Parameterlist.DataGrid, Parameterlist.RText_OutputText)
                    'Else
                    Return
                    'End If
                End If








            Case 70
                AddQueue(Parameterlist.RText_OutputText, New RuningLogConfig("结束升级设备!", Color.Black), 1)
                ResetButton(Parameterlist.btn)
                Parameterlist.EnableFlag = False
        End Select

    End Sub




    ''' <summary>
    ''' 填充发送数据包
    ''' </summary>
    ''' <param name="data"></param>
    ''' <returns></returns>
    Public Function FillSendDataPacket(data As Byte()) As Byte()
        Dim byteHead As Byte()
        Dim crc16 As Byte()
        Dim sendPacket As Byte()

        byteHead = SendDataHead(data)       '获取DataHaed
        crc16 = CheckSendData(byteHead, data)   '获取Data检验值
        sendPacket = FillSendPacket(byteHead, data, crc16)  '组合发送数据

        Return sendPacket
    End Function

    ''' <summary>
    ''' 填充发送数据包
    ''' </summary>
    ''' <param name="head">数据包头</param>
    ''' <param name="data">数据内容</param>
    ''' <param name="crc16">CRC16校验</param>
    ''' <returns></returns>
    Public Function FillSendPacket(head() As Byte, data() As Byte, crc16() As Byte) As Byte()
        Dim dataList As New List(Of Byte)
        dataList.AddRange(head)
        dataList.AddRange(data)
        dataList.AddRange(crc16)
        Return dataList.ToArray
    End Function

    ''' <summary>
    ''' 填充发送校验数据
    ''' </summary>
    ''' <param name="byteHead"></param>
    ''' <param name="data"></param>
    ''' <returns></returns>
    Public Function CheckSendData(byteHead As Byte(), data As Byte()) As Byte()
        Dim crc16 As Byte()
        Dim dataList As New List(Of Byte)
        dataList.AddRange(byteHead)
        dataList.AddRange(data)
        crc16 = GetCRC16CheckSum(dataList.ToArray, dataList.Count)
        Return crc16
    End Function

    ''' <summary>
    ''' CRC16校验
    ''' </summary>
    ''' <param name="dataBuff"></param>
    ''' <param name="length"></param>
    ''' <returns></returns>
    Public Function GetCRC16CheckSum(dataBuff() As Byte, length As Integer) As Byte()
        Dim crc16 As UInteger
        Dim crcBytes() As Byte

        crc16 = &HFFFF
        For i = 0 To length - 1
            crc16 = crc16 And &HFFFF
            crc16 = crc16 Xor dataBuff(i)
            For bit = 0 To 7
                crc16 = IIf((crc16 And 1) = 0, crc16 >> 1, (crc16 >> 1) Xor &HA001)
            Next
        Next
        crc16 = crc16 And &HFFFF
        crcBytes = BitConverter.GetBytes(UShort.Parse(crc16))
        Return crcBytes
    End Function
    ''' <summary>
    ''' 包头数据长度
    ''' </summary>
    Public _dataHeadLength As UShort = 15


    ''' <summary>
    ''' 数据CRC校验长度
    ''' </summary>
    Public _dataCRCLength As UShort = 2
    ''' <summary>
    ''' 透传数据包头
    ''' </summary>
    Public _fixedHead As Byte() = {&HAA, &H55}


    ''' <summary>
    ''' 透传数据固定ID
    ''' </summary>
    Public _fixeSystemId As Byte() = {&H54, &H33, &H53, &H41}


    ''' <summary>
    ''' 透传数据房间信息
    ''' </summary>
    Public _fixeRoomInfo As Byte() = {&HFF, &HFF, &HFF, &HFF}

    ''' <summary>
    ''' 填充发送包头数据
    ''' </summary>
    ''' <param name="data"></param>
    ''' <returns></returns>
    Public Function SendDataHead(data As Byte()) As Byte()
        Dim byteHead As Byte()
        Dim packetLength As Short = _dataHeadLength + _dataCRCLength + data.Length
        Dim cmdType As Byte = &H70
        Dim frameNum As Short = 1
        byteHead = FillSendPacketHead(packetLength, cmdType, frameNum)
        Return byteHead
    End Function

    ''' <summary>
    ''' 填充发送信息包头
    ''' </summary>
    ''' <param name="length"></param>
    ''' <param name="cmdType"></param>
    ''' <param name="frameNum"></param>
    ''' <returns></returns>
    Public Function FillSendPacketHead(length As Short, cmdType As Byte, frameNum As Short) As Byte()
        Dim dataHead As New List(Of Byte)
        dataHead.AddRange(_fixedHead)
        dataHead.AddRange(BitConverter.GetBytes(length))
        dataHead.AddRange(_fixeSystemId)
        dataHead.Add(cmdType)
        dataHead.AddRange(BitConverter.GetBytes(frameNum))
        dataHead.AddRange(_fixeRoomInfo)
        Return dataHead.ToArray
    End Function

    '获取波特率序号
    Public Function GetBaudRateIndex(baudRate As Integer) As Integer
        '0x01：9600
        '  0x02：14400
        '  0x03：19200
        '  0x04：38400
        '  0x05：56000
        '  0x06：57600
        '  0x07：115200
        Select Case baudRate
            Case 9600
                Return 1
            Case 14400
                Return 2
            Case 19200
                Return 3
            Case 38400
                Return 4
            Case 56000
                Return 5
            Case 57600
                Return 6
            Case 115200
                Return 7
            Case 2400
                Return 8
            Case Else
                Return 0
        End Select
    End Function

    Public Overrides Function ParseReceiveData2(gCmdconfig As Cmdconfig, data() As Byte) As Boolean
        Dim saaa = DataProcessing.SumAndMod(data)
        ' Console.WriteLine($"SumAndMod:{saaa}")
        If saaa = 0 Then '进行求和检验整包数据
            '判断命令类型是否一致
            If data(7) = gCmdconfig.CmdValue Then
                ' Console.WriteLine($"data(7)=gCmdconfig.CmdValue{saaa}")
                '判断SN是否一致
                If (data(1) And &HF) = (gCmdconfig.CmdSendData(1 + 18) And &HF) AndAlso gCmdconfig.CmdSendData(0 + 18) = data(3) Then
                    gCmdconfig.CmdReceiveData.Add((Now, data))
                    gCmdconfig.CmdReceiveStatus = True
                    'Console.WriteLine($"gCmdconfig.CmdReceiveStatus:{Now.ToString("yyyy MM dd HH:mm:ss") }:{gCmdconfig.CmdReceiveStatus}")
                    Return True
                Else

                    Return False
                End If
            End If
            Return True
        End If
        Return False
    End Function
End Class
