初始化提交
仓库转移到Gitea,初始化提交,可能丢失以前的git版本日志
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class CloseAllComportExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _portList As List(Of ComPort)
|
||||
|
||||
Public Sub New(command As TestCommand, portList As List(Of ComPort))
|
||||
MyBase.New(command)
|
||||
|
||||
_portList = portList
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询,未查询到也视为成功
|
||||
For Each comPort As ComPort In _portList
|
||||
Try
|
||||
comPort.Close()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResultTipString = $"串口关闭失败:{ex.Message}"
|
||||
CommandReturn.ExecuteResult = False
|
||||
|
||||
Return CommandReturn
|
||||
End Try
|
||||
Next
|
||||
|
||||
CommandReturn.ExecuteResultTipString = $"串口全部关闭成功"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,26 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class CloseComPortExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
|
||||
Private _comPort As ComPort
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'查询串口成功则关闭,未查询成功则视为已关闭
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) then
|
||||
_comPort.Close()
|
||||
End If
|
||||
|
||||
|
||||
CommandReturn.ExecuteResultTipString = $"串口关闭成功"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
235
UTS_Core/UTSModule/Test/Command/ComPortCommand/ComPort.vb
Normal file
235
UTS_Core/UTSModule/Test/Command/ComPortCommand/ComPort.vb
Normal file
@@ -0,0 +1,235 @@
|
||||
Imports System.IO.Ports
|
||||
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
|
||||
Public Class ComPort
|
||||
Private _serialPort As SerialPort '串口操作对象
|
||||
|
||||
''' <summary>
|
||||
''' 串口名
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property PortName As String
|
||||
|
||||
''' <summary>
|
||||
''' 串口别名
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property PortAlias As String
|
||||
|
||||
''' <summary>
|
||||
''' 默认接收超时时间,通讯时超时设置为0时使用该值
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property DefaultTimeout() As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 串口接受单字节间隔接受超时
|
||||
''' </summary>
|
||||
Private recevieInterval As Integer
|
||||
|
||||
Sub New()
|
||||
_serialPort = New SerialPort
|
||||
|
||||
PortName = String.Empty
|
||||
PortAlias = String.Empty
|
||||
End Sub
|
||||
|
||||
Sub New(name As String, [alias] As String)
|
||||
PortName = name
|
||||
PortAlias = [alias]
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 当前串口是否已经打开
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function IsOpen() As Boolean
|
||||
If _serialPort Is Nothing Then Return False
|
||||
Return _serialPort.IsOpen
|
||||
End Function
|
||||
|
||||
Public Function InitializePort(comParam As String) As Boolean
|
||||
Dim param() As String = comParam.Split(New Char() {","c, ":"c, ":"c, ","c})
|
||||
_serialPort = New SerialPort()
|
||||
With _serialPort
|
||||
_serialPort.ReceivedBytesThreshold = 1
|
||||
recevieInterval = 50
|
||||
.PortName = PortName
|
||||
If Integer.TryParse(param(0), .BaudRate) = False Then Return False '波特率
|
||||
If Integer.TryParse(param(2), .DataBits) = False Then Return False '数据位
|
||||
If [Enum].TryParse(param(3), .StopBits) = False Then Return False '停止位
|
||||
|
||||
Select Case param(1).ToUpper
|
||||
Case "N"
|
||||
.Parity = Parity.None '无校验
|
||||
Case "O"
|
||||
.Parity = Parity.Odd '奇校验
|
||||
Case "E"
|
||||
.Parity = Parity.Even '偶校验
|
||||
Case "M"
|
||||
.Parity = Parity.Mark '保留为1
|
||||
Case "S"
|
||||
.Parity = Parity.Space '保留为0
|
||||
Case Else
|
||||
Return False
|
||||
End Select
|
||||
End With
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function Open() As Boolean
|
||||
If _serialPort Is Nothing Then Return False
|
||||
If _serialPort.IsOpen Then Return True
|
||||
Try
|
||||
_serialPort.Open()
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function Close() As Boolean
|
||||
If _serialPort Is Nothing Then Return True
|
||||
If IsOpen() = False Then Return True
|
||||
Try
|
||||
_serialPort.Close()
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function Write(sendText As String, Optional sendType As SendTypes = SendTypes.StringAndCrlf) As Boolean
|
||||
Dim result As Boolean = False
|
||||
Select Case sendType
|
||||
Case SendTypes.String
|
||||
result = WriteText(sendText)
|
||||
Case SendTypes.StringAndCrlf
|
||||
sendText = sendText & vbCrLf
|
||||
result = WriteText(sendText)
|
||||
Case SendTypes.ByteString
|
||||
result = WriteBytes(sendText)
|
||||
End Select
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
|
||||
Public Function WriteText(text As String) As Boolean
|
||||
Dim buf() As Byte = System.Text.Encoding.UTF8.GetBytes(text)
|
||||
Try
|
||||
_serialPort.Write(buf, 0, buf.Length)
|
||||
While _serialPort.BytesToWrite > 0
|
||||
Threading.Thread.Sleep(1)
|
||||
End While
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Shared Function HexStringToBytes(hexString As String) As Byte()
|
||||
Dim hex() As String = hexString.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
|
||||
Dim buf(hex.Length - 1) As Byte
|
||||
For i As Integer = 0 To hex.Length - 1
|
||||
buf(i) = Convert.ToByte(hex(i), 16)
|
||||
Next
|
||||
Return buf
|
||||
End Function
|
||||
|
||||
Public Function WriteBytes(hexString As String) As Boolean
|
||||
Try
|
||||
Dim buf() As Byte = HexStringToBytes(hexString)
|
||||
_serialPort.Write(buf, 0, buf.Length)
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function WriteBytes(buf() As Byte) As Boolean
|
||||
Try
|
||||
_serialPort.Write(buf, 0, buf.Length)
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function ReadBytes(timeout As Integer) As Byte()
|
||||
'处理在512内的字节的接收包有效
|
||||
If _serialPort Is Nothing Then Return New Byte() {}
|
||||
|
||||
Static watch As New Stopwatch
|
||||
Dim receiveBuf As New List(Of Byte)
|
||||
Dim length As Integer
|
||||
Dim readTime As Long = 0
|
||||
|
||||
watch.Restart()
|
||||
While timeout > watch.ElapsedMilliseconds
|
||||
Try
|
||||
length = _serialPort.BytesToRead
|
||||
|
||||
If length > 0 Then
|
||||
Dim buf(length - 1) As Byte
|
||||
_serialPort.Read(buf, 0, buf.Length)
|
||||
|
||||
receiveBuf.AddRange(buf)
|
||||
|
||||
readTime = watch.ElapsedMilliseconds
|
||||
Else
|
||||
If receiveBuf.Count > 0 Then
|
||||
If watch.ElapsedMilliseconds - readTime > recevieInterval Then
|
||||
Exit While
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Return New Byte() {}
|
||||
End Try
|
||||
|
||||
Threading.Thread.Sleep(1)
|
||||
End While
|
||||
watch.Stop()
|
||||
|
||||
Return receiveBuf.ToArray()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 清空接受缓冲区内容
|
||||
''' </summary>
|
||||
Public Sub ClearRecvCache()
|
||||
Try
|
||||
_serialPort.DiscardInBuffer()
|
||||
_serialPort.DiscardOutBuffer()
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"ClearRecvCache Error:{ex.Message}")
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Public Function NameEqual(name As String) As Boolean
|
||||
If String.IsNullOrWhiteSpace(name) Then Return False
|
||||
If String.Compare(PortName, name, True) <> 0 Then Return False
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function AliasEqual(name As String) As Boolean
|
||||
If String.IsNullOrWhiteSpace(name) Then Return False
|
||||
If String.Compare(PortAlias, name, True) <> 0 Then Return False
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Enum SendTypes
|
||||
''' <summary>字符串发送</summary>
|
||||
[String]
|
||||
|
||||
''' <summary>字符串发送,添加回车换行</summary>
|
||||
StringAndCrlf
|
||||
|
||||
''' <summary>十六进制字符串发送</summary>
|
||||
ByteString
|
||||
End Enum
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComPortCommandManager
|
||||
Private Shared ReadOnly PortList As New List(Of ComPort)
|
||||
|
||||
Private Shared _delayedSend As Boolean
|
||||
|
||||
Private Shared _delaySendParam As DelaySendParam
|
||||
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "Config_Comm_Alias"
|
||||
executor = New ConfigComAliasExecutor(command, PortList)
|
||||
Case "Open_CommPort"
|
||||
executor = New OpenComPortExecutor(command, PortList)
|
||||
Case "Close_CommPort"
|
||||
executor = New CloseComPortExecutor(command)
|
||||
Case "Close_All_CommPort"
|
||||
executor = New CloseAllComportExecutor(command, PortList)
|
||||
Case "Comm_Write"
|
||||
executor = New ComWriteExecutor(command)
|
||||
Case "Comm_Read"
|
||||
If _delayedSend Then
|
||||
executor = New ComReadExecutor(command, _delaySendParam)
|
||||
_delayedSend = False
|
||||
Else
|
||||
executor = New ComReadExecutor(command, Nothing)
|
||||
End If
|
||||
Case "Comm_Write_Read"
|
||||
executor = New ComWriteReadExecutor(command)
|
||||
Case "Get_CommPort"
|
||||
executor = New GetComExecutor(command, PortList)
|
||||
'Case "Comm_Write_Text"
|
||||
' executor = New ComWriteTextExecutor(command)
|
||||
'Case "Comm_Read_Text"
|
||||
' executor = New ComReadTextExecutor(command)
|
||||
'Case "Comm_WR_Text"
|
||||
' executor = New ComWrTextExecutor(command)
|
||||
'Case "Comm_Write_Bytes"
|
||||
' executor = New ComWriteBytesExecutor(command)
|
||||
'Case "Comm_Read_Bytes"
|
||||
' executor = New ComReadBytesExecutor(command)
|
||||
'Case "Comm_WR_Bytes"
|
||||
' executor = New ComWrBytesExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"ComPort集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 根据串口名,查询对应串口
|
||||
''' </summary>
|
||||
''' <param name="portName"></param>
|
||||
''' <param name="port"></param>
|
||||
''' <returns></returns>
|
||||
Friend Shared Function FindComPort(portName As String, ByRef port As ComPort) As Boolean
|
||||
For Each comPort As ComPort In PortList
|
||||
If comPort.NameEqual(portName) OrElse comPort.AliasEqual(portName) Then
|
||||
port = comPort
|
||||
Return True
|
||||
End If
|
||||
Next
|
||||
Return False
|
||||
End Function
|
||||
|
||||
|
||||
Friend Shared Sub FillDelaySendParam(port As ComPort, sendText As String, sendType As ComPort.SendTypes)
|
||||
_delaySendParam = New DelaySendParam(port, sendText, sendType)
|
||||
_delayedSend = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Class DelaySendParam
|
||||
Sub New(port As ComPort, text As String, type As ComPort.SendTypes)
|
||||
ComPort = port
|
||||
SendText = text
|
||||
SendType = type
|
||||
End Sub
|
||||
|
||||
Public ComPort As ComPort
|
||||
|
||||
Public SendText As String
|
||||
|
||||
Public SendType As ComPort.SendTypes
|
||||
|
||||
End Class
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,75 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComReadBytesExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _expression As String
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
|
||||
_receiveTimeout = CInt(command.Parameter(1))
|
||||
_expression = command.Parameter(2)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(3)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(4)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,157 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.UTSModule.Test.Command.TestCommandManger
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComReadExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
Private ReadOnly _dealType As DealTypes
|
||||
Private ReadOnly _expression As String
|
||||
Private ReadOnly _delaySendParam As ComPortCommandManager.DelaySendParam
|
||||
|
||||
Sub New(command As TestCommand, delaySendParam As ComPortCommandManager.DelaySendParam)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_receiveTimeout = CInt(command.Parameter(1))
|
||||
|
||||
If [Enum].TryParse(TestCommand.Parameter(2), _dealType) = False Then
|
||||
_dealType = DealTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_expression = TestCommand.Parameter(3)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
|
||||
_delaySendParam = delaySendParam
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'处理延时发送
|
||||
If _delaySendParam IsNot Nothing Then
|
||||
If _delaySendParam.ComPort.IsOpen() = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "延时发送串口未打开"
|
||||
End If
|
||||
|
||||
If _delaySendParam.ComPort.Write(_delaySendParam.SendText, _delaySendParam.SendType) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口延时发送失败"
|
||||
Return CommandReturn
|
||||
End If
|
||||
End If
|
||||
|
||||
'检测串口打开
|
||||
If _comPort.IsOpen() = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "接受串口未打开"
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'范围判断
|
||||
Select Case _dealType
|
||||
Case DealTypes.String
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.StringAndCrlf
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf).Replace(vbCrLf, "")
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.StringContain
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringContain(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.IntegerString
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.IntegerCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.DoubleString
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.ByteString
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
buf = ComPort.HexStringToBytes(CommandReturn.RecordValue)
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
Case DealTypes.Byte
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
End Select
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,51 @@
|
||||
Imports System.Text
|
||||
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComReadTextExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_receiveTimeout = CInt(command.Parameter(1))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(2)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(3)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End NameSpace
|
||||
@@ -0,0 +1,86 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWrBytesExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
Private ReadOnly _expression As String
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_sendText = command.Parameter(1)
|
||||
|
||||
_expression = command.Parameter(2)
|
||||
_receiveTimeout = CInt(command.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口发送数据
|
||||
_comPort.ClearRecvCache()
|
||||
If _comPort.WriteBytes(_sendText) = False Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收正常,判断数据是否在有效范围内
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,62 @@
|
||||
Imports System.Text
|
||||
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWrTextExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_sendText = command.Parameter(1)
|
||||
If command.Parameter(2) = "1" Then _sendText = _sendText & vbCrLf
|
||||
|
||||
_receiveTimeout = CInt(command.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口发送
|
||||
_comPort.ClearRecvCache()
|
||||
If _comPort.WriteText(_sendText) = False Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,37 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWriteBytesExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_sendText = command.Parameter(1)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口发送数据
|
||||
If _comPort.WriteBytes(_sendText) Then
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送成功"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,51 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWriteExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
Private ReadOnly _sendType As ComPort.SendTypes
|
||||
Private ReadOnly _delayedSend As Boolean
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_sendText = command.Parameter(1)
|
||||
If [Enum].TryParse(command.Parameter(2), _sendType) = False Then
|
||||
_sendType = ComPort.SendTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_delayedSend = String.Compare(command.Parameter(3), "1") = 0
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If _delayedSend Then
|
||||
ComPortCommandManager.FillDelaySendParam(_comPort, _sendText, _sendType)
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口延时发送填充成功"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If _comPort.Write(_sendText, _sendType) = False Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送成功"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,147 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.UTSModule.Test.Command.TestCommandManger
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWriteReadExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _comPort As ComPort
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
Private ReadOnly _sendType As ComPort.SendTypes
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
Private ReadOnly _dealType As DealTypes
|
||||
Private ReadOnly _expression As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
|
||||
_sendText = command.Parameter(1)
|
||||
If [Enum].TryParse(command.Parameter(2), _sendType) = False Then
|
||||
_sendType = ComPort.SendTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_receiveTimeout = CInt(command.Parameter(3))
|
||||
|
||||
If [Enum].TryParse(TestCommand.Parameter(4), _dealType) = False Then
|
||||
_dealType = DealTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_expression = TestCommand.Parameter(5)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(6)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(7)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口发送
|
||||
_comPort.ClearRecvCache()
|
||||
If _comPort.Write(_sendText, _sendType) = False Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'范围判断
|
||||
Select Case _dealType
|
||||
Case DealTypes.String
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.StringAndCrlf
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf).Replace(vbCrLf, "")
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.StringContain
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringContain(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.IntegerString
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.IntegerCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.DoubleString
|
||||
CommandReturn.RecordValue = Encoding.UTF8.GetString(buf)
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case DealTypes.ByteString
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = BitConverter.ToString(buf).Replace("-", " ")
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
buf = ComPort.HexStringToBytes(CommandReturn.RecordValue)
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
Case DealTypes.Byte
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = BitConverter.ToString(buf).Replace("-", " ")
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{str}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = Expression.StringExpression.GetDoubleExpressionResult(str).ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{str}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
End Select
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,36 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ComWriteTextExecutor
|
||||
Inherits TestCommandExecutor
|
||||
Private _comPort As ComPort
|
||||
Private ReadOnly _portName As String
|
||||
Private ReadOnly _sendText As String
|
||||
|
||||
Public Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_sendText = command.Parameter(1)
|
||||
If command.Parameter(2) = "1" Then _sendText = _sendText & vbCrLf
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"无效的串口名"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If _comPort.WriteText(_sendText) = False Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送成功"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,60 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class ConfigComAliasExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
|
||||
Private ReadOnly _portAlias As String
|
||||
|
||||
Private ReadOnly _portList As List(Of ComPort)
|
||||
|
||||
Public Sub New(command As TestCommand, portList As List(Of ComPort))
|
||||
MyBase.New(command)
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_portAlias = command.Parameter(1)
|
||||
|
||||
_portList = portList
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
For Each comPort As ComPort In _portList
|
||||
If comPort.NameEqual(_portName) Then
|
||||
comPort.PortAlias = _portAlias
|
||||
|
||||
CommandReturn.ExecuteResultTipString = $"串口重命名成功"
|
||||
CommandReturn.ExecuteResult = True
|
||||
|
||||
Return CommandReturn
|
||||
Else
|
||||
'如果已设置的串口别名与新的别名重名,则清除那个串口的别名
|
||||
If comPort.AliasEqual(_portAlias) Then
|
||||
comPort.PortAlias = String.Empty
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
'从当前设备上串口中查询
|
||||
Dim names As String() = IO.Ports.SerialPort.GetPortNames()
|
||||
For Each name As String In names
|
||||
If String.Compare(_portName, name, True) = 0 Then
|
||||
_portList.Add(New ComPort(_portName, _portAlias))
|
||||
|
||||
CommandReturn.ExecuteResultTipString = $"串口重命名成功"
|
||||
CommandReturn.ExecuteResult = True
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
Next
|
||||
|
||||
'未查询到历史使用的串口
|
||||
CommandReturn.ExecuteResultTipString = $"串口重命名失败,未查询到串口[{_portName}]存在"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
126
UTS_Core/UTSModule/Test/Command/ComPortCommand/GetComExecutor.vb
Normal file
126
UTS_Core/UTSModule/Test/Command/ComPortCommand/GetComExecutor.vb
Normal file
@@ -0,0 +1,126 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.UTSModule.Test.Command.TestCommandManger
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class GetComExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _portList As List(Of ComPort)
|
||||
|
||||
Private ReadOnly _portAlias As String
|
||||
Private ReadOnly _portParam As String
|
||||
Private ReadOnly _sendText As String
|
||||
Private ReadOnly _sendType As ComPort.SendTypes
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
Private ReadOnly _dealType As DealTypes
|
||||
Private ReadOnly _expression As String
|
||||
|
||||
Sub New(command As TestCommand, portList As List(Of ComPort))
|
||||
MyBase.New(command)
|
||||
|
||||
_portList = portList
|
||||
|
||||
_portAlias = command.Parameter(0)
|
||||
|
||||
_portParam = command.Parameter(1)
|
||||
|
||||
_sendText = command.Parameter(2)
|
||||
If [Enum].TryParse(command.Parameter(3), _sendType) = False Then
|
||||
_sendType = ComPort.SendTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_receiveTimeout = CInt(command.Parameter(4))
|
||||
|
||||
If [Enum].TryParse(TestCommand.Parameter(5), _dealType) = False Then
|
||||
_dealType = DealTypes.StringAndCrlf
|
||||
End If
|
||||
|
||||
_expression = TestCommand.Parameter(6)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(7)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(7)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从当前设备上串口中查询
|
||||
Dim names As String() = IO.Ports.SerialPort.GetPortNames()
|
||||
Dim _comPort As New ComPort
|
||||
_comPort.PortAlias = _portAlias
|
||||
For Each name As String In names
|
||||
If _comPort.IsOpen Then _comPort.Close()
|
||||
|
||||
'串口初始化
|
||||
_comPort.PortName = name
|
||||
If _comPort.InitializePort(_portParam) = False Then Continue For
|
||||
|
||||
'串口打开
|
||||
If _comPort.Open() = False Then Continue For
|
||||
|
||||
'串口发送
|
||||
_comPort.ClearRecvCache()
|
||||
If _comPort.Write(_sendText, _sendType) = False Then Continue For
|
||||
|
||||
'串口接收
|
||||
Dim buf() As Byte = _comPort.ReadBytes(_receiveTimeout)
|
||||
If buf.Length = 0 Then Continue For
|
||||
|
||||
'范围判断
|
||||
Select Case _dealType
|
||||
Case DealTypes.String
|
||||
If CompareFunction.StringCompare(Encoding.UTF8.GetString(buf), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Case DealTypes.StringAndCrlf
|
||||
If CompareFunction.StringCompare(Encoding.UTF8.GetString(buf).Replace(vbCrLf, ""), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Case DealTypes.StringContain
|
||||
If CompareFunction.StringContain(Encoding.UTF8.GetString(buf), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Case DealTypes.IntegerString
|
||||
If CompareFunction.IntegerCompare(Encoding.UTF8.GetString(buf), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Case DealTypes.DoubleString
|
||||
If CompareFunction.DoubleCompare(Encoding.UTF8.GetString(buf), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Case DealTypes.ByteString
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) = False Then
|
||||
'检测表达式的有效性
|
||||
buf = ComPort.HexStringToBytes(CommandReturn.RecordValue)
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then Continue For
|
||||
|
||||
Try
|
||||
If CompareFunction.DoubleCompare(Expression.StringExpression.GetDoubleExpressionResult(str).ToString(), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Catch ex As Exception
|
||||
Continue For
|
||||
End Try
|
||||
End If
|
||||
Case DealTypes.Byte
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) = False Then
|
||||
'检测表达式的有效性
|
||||
Dim str As String = Expression.StringExpression.ReplaceBytes(buf, _expression)
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then Continue For
|
||||
|
||||
Try
|
||||
If CompareFunction.DoubleCompare(Expression.StringExpression.GetDoubleExpressionResult(str).ToString(), CommandReturn.LowerLimit, CommandReturn.UpperLimit) = False Then Continue For
|
||||
Catch ex As Exception
|
||||
Continue For
|
||||
End Try
|
||||
End If
|
||||
End Select
|
||||
|
||||
'查询到目标串口
|
||||
_comPort.Close()
|
||||
_portList.Add(_comPort)
|
||||
|
||||
CommandReturn.RecordValue = name
|
||||
CommandReturn.ExecuteResultTipString = $"设备上已查询到可用串口:{name}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
Next
|
||||
|
||||
'未查询到目标串口
|
||||
If _comPort.IsOpen Then _comPort.Close()
|
||||
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"设备上未查询到可用串口"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,67 @@
|
||||
Namespace UTSModule.Test.Command.ComPortCommand
|
||||
Public Class OpenComPortExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _portList As List(Of ComPort)
|
||||
|
||||
Private ReadOnly _portName As String
|
||||
|
||||
Private ReadOnly _portParam As String
|
||||
|
||||
Private ReadOnly _receiveTimeout As Integer
|
||||
|
||||
Private _comPort As ComPort
|
||||
|
||||
|
||||
Public Sub New(command As TestCommand, portList As List(Of ComPort))
|
||||
MyBase.New(command)
|
||||
|
||||
_portList = portList
|
||||
|
||||
_portName = command.Parameter(0)
|
||||
_portParam = command.Parameter(1)
|
||||
_receiveTimeout = CInt(command.Parameter(2))
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'从历史使用串口中查询
|
||||
If ComPortCommandManager.FindComPort(_portName, _comPort) = False Then
|
||||
Dim names As String() = IO.Ports.SerialPort.GetPortNames()
|
||||
For Each name As String In names
|
||||
If String.Compare(_portName, name, True) = 0 Then
|
||||
_comPort = New ComPort(_portName, String.Empty)
|
||||
_portList.Add(_comPort)
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
'未查询到有效串口
|
||||
If _comPort Is Nothing Then
|
||||
CommandReturn.ExecuteResultTipString = $"串口打开失败,未查询到串口[{_portName}]存在"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'未初始化成功
|
||||
_comPort.DefaultTimeout = _receiveTimeout
|
||||
If _comPort.InitializePort(_portParam) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"串口打开失败,无效的串口参数"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'打开串口
|
||||
If _comPort.Open() Then
|
||||
CommandReturn.ExecuteResultTipString = $"串口打开成功"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = $"串口打开失败"
|
||||
CommandReturn.ExecuteResult = False
|
||||
End If
|
||||
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
517
UTS_Core/UTSModule/Test/Command/CompareFunction.vb
Normal file
517
UTS_Core/UTSModule/Test/Command/CompareFunction.vb
Normal file
@@ -0,0 +1,517 @@
|
||||
Namespace UTSModule.Test.Command
|
||||
''' <summary>
|
||||
''' UTS串口通讯返回值比较函数静态类
|
||||
''' </summary>
|
||||
Public Class CompareFunction
|
||||
|
||||
#Region "String"
|
||||
''' <summary>
|
||||
''' 仅一个参数字符串比较,忽略大小写
|
||||
''' </summary>
|
||||
''' <param name="testReturn">测试命令返回集合</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringCompare(testReturn As TestCommandReturn) As Boolean
|
||||
Return StringCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 判断目标字符串是否是上限或下限字符串中的某一个,忽略大小写,符合上下线中的任何一个则返回True
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
''' Momo 2022-09-19 添加命令,等于上下限其中的一个就返回true
|
||||
Public Shared Function StringEquals(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
|
||||
If String.Equals(value, lowerLimit) = False Then '不符合条件
|
||||
result = False
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
|
||||
If String.Equals(value, upperLimit) = False Then '不符合条件
|
||||
result = False
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数字符串是否包含关系,忽略大小写,下限则为目标字符串包含下限,上限则为上限字符串包含目标字符串,包含则返回False,不包含则返回True
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
''' Momo 2022-09-15 添加命令,包含指定字符则返回false,否则返回true
|
||||
Public Shared Function StringIsNotContain(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
|
||||
If value.Contains(lowerLimit) = True Then '不符合条件
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
|
||||
If upperLimit.Contains(value) = True Then '不符合条件
|
||||
result = False
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数字符串是否包含关系,忽略大小写,下限则为目标字符串包含下限,上限则为上限字符串包含目标字符串
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringContain(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
|
||||
If value.Contains(lowerLimit) = False Then '不符合条件
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
|
||||
If upperLimit.Contains(value) = False Then '不符合条件
|
||||
result = False
|
||||
End If
|
||||
End If
|
||||
Return result
|
||||
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数字符串是否包含关系,忽略大小写,返回数据包含上下限中任意一个字符串即算ok
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringContain_Momo(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
'Momo 2022-11-14 字符串比较不区分大小写
|
||||
value = Trim(value.ToUpper)
|
||||
lowerLimit = Trim(lowerLimit.ToUpper)
|
||||
upperLimit = Trim(upperLimit.ToUpper)
|
||||
|
||||
'MsgBox("value = " & value & vbCrLf &
|
||||
' "lowerLimit = " & lowerLimit & vbCrLf &
|
||||
' "upperLimit = " & upperLimit)
|
||||
|
||||
'Momo 2022-11-14 待比较字符串为空白则返回错误
|
||||
If String.IsNullOrWhiteSpace(value) = True Then
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
|
||||
If value <> lowerLimit Then '不符合条件
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
|
||||
If value <> upperLimit Then '符合条件
|
||||
result = False 'Momo 2023-06-09 字符串判断方式:包含方式 : 包含下限则返回true’
|
||||
Return result
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数字符串比较,忽略大小写
|
||||
''' </summary>
|
||||
''' <param name="value">当前值</param>
|
||||
''' <param name="lowerLimit">下限</param>
|
||||
''' <param name="upperLimit">上限</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False Then '需要比较下限
|
||||
If String.Compare(value, lowerLimit, True) < 0 Then '不符合条件
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False Then '需要比较上限
|
||||
If String.Compare(value, upperLimit, True) > 0 Then '不符合条件
|
||||
result = False
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 确认字符串长度
|
||||
''' </summary>
|
||||
''' <param name="value">当前值</param>
|
||||
''' <param name="lowerLimit">下限</param>
|
||||
''' <param name="upperLimit">上限</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringLengthCheck(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
Dim int_lowerlimt As Integer = 0 '’
|
||||
Dim int_upperlimit As Integer = 0 '’Int(upperLimit)
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = True Then
|
||||
int_lowerlimt = 0
|
||||
Else
|
||||
int_lowerlimt = CInt(lowerLimit)
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = True Then
|
||||
int_upperlimit = 0
|
||||
Else
|
||||
int_upperlimit = CInt(upperLimit)
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(lowerLimit) = False AndAlso int_lowerlimt > 0 Then '需要比较下限
|
||||
If value.Length < int_lowerlimt Then '不符合条件
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
If String.IsNullOrWhiteSpace(upperLimit) = False AndAlso int_upperlimit > 0 Then '需要比较上限
|
||||
If value.Length > int_upperlimit Then '不符合条件
|
||||
result = False
|
||||
Return result
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 确认字符串中每个字符的格式
|
||||
''' </summary>
|
||||
''' <param name="value">当前值</param>
|
||||
''' <param name="charMode">字符校验模式</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringEachCharCheck(value As String, charMode As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
Dim tmpString_tobe_process As String = value
|
||||
Dim int_charMode As Integer = 0 ' CInt(charMode)
|
||||
Dim i As Integer = 0
|
||||
|
||||
|
||||
If String.IsNullOrWhiteSpace(charMode) = True Then
|
||||
int_charMode = 0
|
||||
Else
|
||||
int_charMode = CInt(charMode)
|
||||
End If
|
||||
|
||||
If value.Length > 0 Then
|
||||
'对每个字符都做格式检查:
|
||||
'空白:不对每个字符进行检查
|
||||
'0:不对每个字符进行检查
|
||||
'1:每个字符都必须是数字0~9
|
||||
'2:每个字符都必须是十六进制, 即0~9, A~F, 包括空格
|
||||
'3:每个字符都必须是数字或字母, 用以排除乱码
|
||||
'对字符逐个进行格式检查
|
||||
Select Case int_charMode
|
||||
Case 0 '不对每个字符进行检查
|
||||
|
||||
Case 1 '每个字符都必须是数字0~9
|
||||
If IsNumeric(tmpString_tobe_process) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Case 2 '每个字符都必须是十六进制, 即0~9, A~F, 包括空格
|
||||
'0~9: 48~57
|
||||
'A~F: 65~70
|
||||
'space:32
|
||||
' -:45
|
||||
If tmpString_tobe_process.Length > 0 Then
|
||||
For i = 1 To tmpString_tobe_process.Length
|
||||
Dim tmpChar As Char = CChar(Mid(tmpString_tobe_process, i, 1).ToUpper)
|
||||
|
||||
If (Asc(tmpChar) >= 48 AndAlso Asc(tmpChar) <= 57) OrElse '0~9
|
||||
(Asc(tmpChar) >= 65 AndAlso Asc(tmpChar) <= 70) OrElse 'A~F
|
||||
(Asc(tmpChar) = 32) Then 'space
|
||||
'合法内容
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Case 3 '每个字符都必须是数字或字母, 用以排除乱码
|
||||
If tmpString_tobe_process.Length > 0 Then
|
||||
For i = 1 To tmpString_tobe_process.Length
|
||||
Dim tmpChar As Char = CChar(Mid(tmpString_tobe_process, i, 1))
|
||||
|
||||
If (Asc(tmpChar) >= 32 AndAlso Asc(tmpChar) <= 126) Then 'space
|
||||
'合法内容
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Case Else '其他情况
|
||||
|
||||
End Select
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 多参数字符串列表比较上下限
|
||||
''' </summary>
|
||||
''' <param name="param">参数列表</param>
|
||||
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ParamStringListCompare(param As List(Of String), lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim lowerList As String() = lowerLimit.Split(":"c)
|
||||
Dim upperList As String() = upperLimit.Split(":"c)
|
||||
Dim lower As String
|
||||
Dim upper As String
|
||||
|
||||
If param.Count() = 0 Then
|
||||
If StringCompare("", lowerList(0), upperList(0)) = False Then Return False
|
||||
End If
|
||||
|
||||
For i As Integer = 0 To param.Count - 1
|
||||
If i >= lowerList.Count() Then
|
||||
lower = String.Empty
|
||||
Else
|
||||
lower = lowerList(i)
|
||||
End If
|
||||
|
||||
If i >= upperList.Count() Then
|
||||
upper = String.Empty
|
||||
Else
|
||||
upper = upperList(i)
|
||||
End If
|
||||
|
||||
|
||||
If StringCompare(param(i), lower, upper) = False Then Return False
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
#Region "Double"
|
||||
''' <summary>
|
||||
''' 浮点型比较方式
|
||||
''' </summary>
|
||||
''' <param name="testReturn"></param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function DoubleCompare(testReturn As TestCommandReturn) As Boolean
|
||||
|
||||
Return DoubleCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数浮点型比较
|
||||
''' </summary>
|
||||
''' <param name="value">当前值</param>
|
||||
''' <param name="lowerLimit">下限</param>
|
||||
''' <param name="upperLimit">上限</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function DoubleCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
|
||||
'Momo 2023-12 15 如果上下限都为控制则默认为不需比较,返回True
|
||||
If String.IsNullOrEmpty(lowerLimit) AndAlso String.IsNullOrEmpty(upperLimit) Then Return True
|
||||
|
||||
Dim result As Boolean = True
|
||||
|
||||
Dim compareLower As Boolean = IsNumeric(lowerLimit)
|
||||
Dim compareUpper As Boolean = IsNumeric(upperLimit)
|
||||
|
||||
If IsNumeric(value) = False Then
|
||||
If compareLower OrElse compareUpper Then result = False
|
||||
Else
|
||||
Dim val As Double = CDbl(value)
|
||||
|
||||
If compareLower Then
|
||||
If val < CDbl(lowerLimit) Then
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
If compareUpper Then
|
||||
If val > CDbl(upperLimit) Then result = False
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 多参数浮点型列表比较上下限
|
||||
''' </summary>
|
||||
''' <param name="param">参数列表</param>
|
||||
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ParamDoubleListCompare(param As List(Of String),
|
||||
lowerLimit As String,
|
||||
upperLimit As String,
|
||||
Optional lowerLimit_2 As String = "",
|
||||
Optional upperLimit_2 As String = "") As Boolean
|
||||
Dim lowerList As String() = lowerLimit.Split(":"c)
|
||||
Dim upperList As String() = upperLimit.Split(":"c)
|
||||
Dim lower As String
|
||||
Dim upper As String
|
||||
|
||||
Dim lowerList_2 As String() = lowerLimit_2.Split(":"c)
|
||||
Dim upperList_2 As String() = upperLimit_2.Split(":"c)
|
||||
Dim lower_2 As String
|
||||
Dim upper_2 As String
|
||||
|
||||
Dim reslut_1 As Boolean = False
|
||||
Dim result_2 As Boolean = False
|
||||
|
||||
If param.Count = 0 Then
|
||||
If DoubleCompare("", lowerList(0), upperList(0)) = False Then
|
||||
If DoubleCompare("", lowerLimit_2(0), upperLimit_2(0)) = False Then 'Momo 2023-12-15 增加第二个标准判定,两个标准任意一个满足则为true
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
End If
|
||||
|
||||
For i As Integer = 0 To param.Count - 1
|
||||
If i >= lowerList.Count() Then
|
||||
lower = String.Empty
|
||||
lower_2 = String.Empty
|
||||
Else
|
||||
lower = lowerList(i)
|
||||
lower_2 = lowerList_2(i)
|
||||
End If
|
||||
|
||||
If i >= upperList.Count() Then
|
||||
upper = String.Empty
|
||||
upper_2 = String.Empty
|
||||
Else
|
||||
upper = upperList(i)
|
||||
upper_2 = upperList_2(i)
|
||||
End If
|
||||
|
||||
|
||||
'Momo 2023-12-15 增加第二个标准判定,两个标准任意一个满足则为true
|
||||
reslut_1 = DoubleCompare(param(i), lower, upper)
|
||||
result_2 = DoubleCompare(param(i), lower_2, upper_2)
|
||||
|
||||
If String.IsNullOrEmpty(lower_2) AndAlso String.IsNullOrEmpty(upper_2) Then
|
||||
If reslut_1 = False Then Return False
|
||||
Else
|
||||
If reslut_1 = False AndAlso result_2 = False Then Return False
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
#Region "Integer"
|
||||
''' <summary>
|
||||
''' 整数型比较方式
|
||||
''' </summary>
|
||||
''' <param name="testReturn"></param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function IntegerCompare(testReturn As TestCommandReturn) As Boolean
|
||||
|
||||
Return IntegerCompare(testReturn.RecordValue, testReturn.LowerLimit, testReturn.UpperLimit)
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 仅一个参数整数比较,忽略大小写
|
||||
''' </summary>
|
||||
''' <param name="value">当前值</param>
|
||||
''' <param name="lowerLimit">下限</param>
|
||||
''' <param name="upperLimit">上限</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function IntegerCompare(value As String, lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim result As Boolean = True
|
||||
|
||||
Dim compareLower As Boolean = IsNumeric(lowerLimit)
|
||||
Dim compareUpper As Boolean = IsNumeric(upperLimit)
|
||||
|
||||
If IsNumeric(value) = False Then
|
||||
If compareLower OrElse compareUpper Then result = False
|
||||
Else
|
||||
Dim val As Double = CInt(value)
|
||||
|
||||
If compareLower Then
|
||||
If val < CInt(lowerLimit) Then
|
||||
result = False
|
||||
Return result '失败则不用比较上限
|
||||
End If
|
||||
End If
|
||||
|
||||
If compareUpper Then
|
||||
If val > CInt(upperLimit) Then result = False
|
||||
End If
|
||||
End If
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 多参数整数型列表比较上下限
|
||||
''' </summary>
|
||||
''' <param name="param">参数列表</param>
|
||||
''' <param name="lowerLimit">下限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <param name="upperLimit">上限字符串,切割时按冒号切割,位数不足则默认不比较</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ParamIntegerListCompare(param As List(Of String), lowerLimit As String, upperLimit As String) As Boolean
|
||||
Dim lowerList As String() = lowerLimit.Split(":"c)
|
||||
Dim upperList As String() = upperLimit.Split(":"c)
|
||||
Dim lower As String
|
||||
Dim upper As String
|
||||
|
||||
If param.Count = 0 Then
|
||||
If IntegerCompare("", lowerList(0), upperList(0)) = False Then Return False
|
||||
End If
|
||||
|
||||
For i As Integer = 0 To param.Count - 1
|
||||
If i >= lowerList.Count() Then
|
||||
lower = String.Empty
|
||||
Else
|
||||
lower = lowerList(i)
|
||||
End If
|
||||
|
||||
If i >= upperList.Count() Then
|
||||
upper = String.Empty
|
||||
Else
|
||||
upper = upperList(i)
|
||||
End If
|
||||
|
||||
|
||||
If IntegerCompare(param(i), lower, upper) = False Then Return False
|
||||
Next
|
||||
|
||||
Return True
|
||||
End Function
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,58 @@
|
||||
Imports UTS_Core.Expression
|
||||
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
|
||||
Public Class CompareExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _strSource As String
|
||||
Private _compareType As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_strSource = TestCommand.Parameter(0)
|
||||
_compareType = TestCommand.Parameter(1)
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(2)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(3)
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
|
||||
Select Case _compareType
|
||||
Case "1" '浮点比较
|
||||
CommandReturn.ExecuteResult = CompareFunction.DoubleCompare(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case "2" '字符串包含,包含字符串则返回true
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringContain(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case "3" '字符串比较
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case "4" 'Momo 2022-09-15 字符串比较,和StringContain 相反,不包含指定字符串则返回true
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringIsNotContain(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case "5" 'Momo 2022-09-19 字符串全字匹配,等于upperlimit或lowwerlimit中的一个就返回true
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringEquals(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
Case "6" 'Momo 2025-04-10 字符串长度比较,字符串长度在上下限范围以内
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringLengthCheck(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
|
||||
Case Else '默认字符串比较
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(_strSource, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
End Select
|
||||
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = "数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = "数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class ConverterCommandManager
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "GetString"
|
||||
executor = New GetStringExecutor(command)
|
||||
Case "GetUTF8String"
|
||||
executor = New GetUTF8StringExecutor(command)
|
||||
Case "GetValue"
|
||||
executor = New GetValueExecutor(command)
|
||||
Case "GetBoolean"
|
||||
executor = New GetBooleanExecutor(command)
|
||||
Case "SubString"
|
||||
executor = New SubStringExecutor(command)
|
||||
Case "FormatString" 'Momo 2022-03-24
|
||||
executor = New FormatStringExecutor(command)
|
||||
Case "Compare"
|
||||
executor = New CompareExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"Converter集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
|
||||
Return executor
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,369 @@
|
||||
'
|
||||
'用于对字符串进行分隔后重新整形组合
|
||||
'例如:Source String:12.23.456
|
||||
' OutputString:012.023.456
|
||||
'
|
||||
'History:
|
||||
'Momo 2022-03-25 : 第一版
|
||||
'
|
||||
'-----------------------------------------------------
|
||||
'FormatMode = 1:FormatMode_Split_Alignment_And_Regroup '按照固定字符分隔,格式化,然后重组
|
||||
' = 2:FormatMode_Split_String '分隔字符串,例如:“OK,23” 从中间提取出“OK”和“23”
|
||||
' = 3: FormatMode_Check_Each_Character '对每个字符进行格式检测
|
||||
'
|
||||
'
|
||||
'
|
||||
'-----------------------------------------------------
|
||||
'ElementConvetModeEnum = 1: ElementConvetModeEnum_FixedLenght_Front_Fill_Zero '按照固定长度,前面补零,适合于数值转换场合
|
||||
' 2:FormatMode_Split_String_GetElement_By_Idx '分隔后按指定索引获取分隔后的字符,索引从0开始,每次只返回一个结果,指定索引超过长度是无返回
|
||||
|
||||
|
||||
|
||||
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class FormatStringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private Enum ElementConvetModeEnum
|
||||
ElementConvetModeEnum_FixedLenght_Front_Fill_Zero = 1 '固定长度,不足长度加0
|
||||
FormatMode_Split_String_GetElement_By_Idx '分隔后按指定下标获取分隔后的字符,下标从0开始,每次只返回一个结果,指定下标超过长度是无返回
|
||||
End Enum
|
||||
|
||||
Private Enum FormatModeEnum
|
||||
FormatMode_Split_Alignment_And_Regroup = 1 '按照固定字符分隔,格式化,然后重组
|
||||
FormatMode_Split_String '分隔字符串,例如:“OK,23” 从中间提取出“OK”和“23”
|
||||
FormatMode_Check_Each_Character
|
||||
End Enum
|
||||
Private Enum ParasEnum
|
||||
SourceString '源字符串
|
||||
FormatMode '整形模式’
|
||||
Symbol_Of_Split '分隔符’
|
||||
Len_Of_SplitByFixedLength '按固定模式分隔的情况下,分隔长度依据’
|
||||
Element_Convet_Mode '分隔后元素转换模式’
|
||||
Length_Format '转换后元素格式化’
|
||||
Connect_Symbol '连接字符’
|
||||
OutputString '处理后字符串’
|
||||
MAX
|
||||
End Enum
|
||||
Private ReadOnly _Para(ParasEnum.MAX) As String
|
||||
|
||||
'提取参数,与数据表中描述相同
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
Dim idx As Integer
|
||||
For idx = 0 To ParasEnum.MAX - 1
|
||||
_Para(idx) = command.Parameter(idx)
|
||||
Next
|
||||
End Sub
|
||||
|
||||
'执行模块’
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim tmpStrReslut As String = ""
|
||||
Dim tmpStrErrMsg As String = ""
|
||||
'源字符串为空则为返回错误
|
||||
If String.IsNullOrEmpty(_Para(ParasEnum.SourceString)) Then
|
||||
CommandReturn.RecordValue = "" '字符串处理后的返回值
|
||||
CommandReturn.ExecuteResultTipString = $"源字符串不能为空" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'根据格式化模式确定格式化处理方法’
|
||||
Select Case Val(_Para(ParasEnum.FormatMode))
|
||||
'按照固定字符分隔,格式化,然后重组
|
||||
Case FormatModeEnum.FormatMode_Split_Alignment_And_Regroup
|
||||
Dim tmpReslut As Boolean = Run_FormatMode_Split_Alignment_And_Regroup(_Para(ParasEnum.SourceString),
|
||||
_Para(ParasEnum.Symbol_Of_Split),
|
||||
_Para(ParasEnum.Element_Convet_Mode),
|
||||
_Para(ParasEnum.Length_Format),
|
||||
_Para(ParasEnum.Connect_Symbol),
|
||||
tmpStrReslut,
|
||||
tmpStrErrMsg)
|
||||
|
||||
If tmpReslut = True Then
|
||||
'执行成功
|
||||
CommandReturn.RecordValue = tmpStrReslut
|
||||
CommandReturn.ExecuteResultTipString = ""
|
||||
CommandReturn.ExecuteResult = True
|
||||
Else
|
||||
'执行失败’
|
||||
CommandReturn.RecordValue = "" '字符串处理后的返回值
|
||||
CommandReturn.ExecuteResultTipString = tmpStrErrMsg '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False
|
||||
End If
|
||||
Return CommandReturn
|
||||
|
||||
'分隔字符串,例如:“OK,23” 从中间提取出“OK”和“23”
|
||||
Case FormatModeEnum.FormatMode_Split_String
|
||||
Dim tmpReslut As Boolean = Run_FormatMode_Split_String(_Para(ParasEnum.SourceString),
|
||||
_Para(ParasEnum.Symbol_Of_Split),
|
||||
_Para(ParasEnum.Len_Of_SplitByFixedLength),
|
||||
_Para(ParasEnum.Element_Convet_Mode),
|
||||
tmpStrReslut,
|
||||
tmpStrErrMsg)
|
||||
If tmpReslut = True Then
|
||||
'执行成功
|
||||
CommandReturn.RecordValue = tmpStrReslut
|
||||
CommandReturn.ExecuteResultTipString = ""
|
||||
CommandReturn.ExecuteResult = True
|
||||
Else
|
||||
'执行失败’
|
||||
CommandReturn.RecordValue = "" '字符串处理后的返回值
|
||||
CommandReturn.ExecuteResultTipString = tmpStrErrMsg '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False
|
||||
End If
|
||||
Return CommandReturn
|
||||
|
||||
''对每个字符进行格式检测
|
||||
Case FormatModeEnum.FormatMode_Check_Each_Character
|
||||
Dim tmpReslut As Boolean = Run_FormatMode_Check_Each_Character(_Para(ParasEnum.SourceString),
|
||||
_Para(ParasEnum.Symbol_Of_Split),
|
||||
_Para(ParasEnum.Len_Of_SplitByFixedLength),
|
||||
_Para(ParasEnum.Element_Convet_Mode),
|
||||
_Para(ParasEnum.Length_Format),
|
||||
tmpStrReslut,
|
||||
tmpStrErrMsg)
|
||||
If tmpReslut = True Then
|
||||
'执行成功
|
||||
CommandReturn.RecordValue = tmpStrReslut
|
||||
CommandReturn.ExecuteResultTipString = ""
|
||||
CommandReturn.ExecuteResult = True
|
||||
Else
|
||||
'执行失败’
|
||||
CommandReturn.RecordValue = tmpStrReslut '字符串处理后的返回值
|
||||
CommandReturn.ExecuteResultTipString = tmpStrErrMsg '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False
|
||||
End If
|
||||
Return CommandReturn
|
||||
|
||||
Case Else
|
||||
|
||||
CommandReturn.RecordValue = "" '字符串处理后的返回值
|
||||
CommandReturn.ExecuteResultTipString = $"FormatMode 参数不正确" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return CommandReturn
|
||||
End Select
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
'Dim tmpReslut As Boolean = Run_FormatMode_Check_Each_Character(_Para(ParasEnum.SourceString),
|
||||
' _Para(ParasEnum.Symbol_Of_Split),
|
||||
' _Para(ParasEnum.Len_Of_SplitByFixedLength),
|
||||
' _Para(ParasEnum.Element_Convet_Mode),
|
||||
' _Para(ParasEnum.Length_Format),
|
||||
' tmpStrReslut,
|
||||
' tmpStrErrMsg)
|
||||
Function Run_FormatMode_Check_Each_Character(ByVal strSourceString As String,
|
||||
ByVal strSymbol_Of_Split As String,
|
||||
ByVal strLen_Of_SplitByFixedLength As String,
|
||||
ByVal strElement_Convet_Mode As String,
|
||||
ByVal strLength_Format As String,
|
||||
ByRef strOutputString As String,
|
||||
ByRef strErrMsg As String) As Boolean
|
||||
'Momo 2022-03-03 add code here !
|
||||
Dim tmpString_tobe_process As String = strSourceString '待处理字符串
|
||||
Dim tmpIs_check_string_lenght As Integer = CInt(Val(strSymbol_Of_Split)) '是否确认字符串长度
|
||||
Dim tmp_stringLen_lowlimit As Integer = CInt(Val(strLen_Of_SplitByFixedLength)) '字符串长度下限
|
||||
Dim tmp_stringLen_upperlimit As Integer = CInt(Val(strElement_Convet_Mode)) '字符串长度上限
|
||||
Dim tmp_format_check_for_each_characher As Integer = CInt(Val(strLength_Format)) '字符格式化比对模式
|
||||
Dim i As Integer = 0
|
||||
|
||||
If String.IsNullOrEmpty(tmpString_tobe_process) Then
|
||||
strOutputString = "FALSE" '字符串处理后的返回值
|
||||
strErrMsg = $"空字符串" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End If
|
||||
|
||||
'判断字符串长度
|
||||
If tmpIs_check_string_lenght > 0 Then
|
||||
If tmpString_tobe_process.Length < tmp_stringLen_lowlimit OrElse
|
||||
tmpString_tobe_process.Length > tmp_stringLen_upperlimit Then
|
||||
strOutputString = "FALSE" '字符串处理后的返回值
|
||||
strErrMsg = $"字符串长度不正确" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
|
||||
'对字符逐个进行格式检查
|
||||
'对每个字符都做格式检查:
|
||||
'0:不对每个字符进行检查
|
||||
'1:每个字符都必须是数字0~9
|
||||
'2:每个字符都必须是十六进制, 即0~9, A~F, 包括空格
|
||||
'3:每个字符都必须是数字或字母, 用以排除乱码
|
||||
Select Case tmp_format_check_for_each_characher
|
||||
Case 0 '不对每个字符进行检查
|
||||
|
||||
Case 1 '每个字符都必须是数字0~9
|
||||
If IsNumeric(tmpString_tobe_process) = False Then
|
||||
strOutputString = "FALSE" '字符串处理后的返回值
|
||||
strErrMsg = $"字符串中包含非数字内容" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End If
|
||||
|
||||
Case 2 '每个字符都必须是十六进制, 即0~9, A~F, 包括空格
|
||||
'0~9: 48~57
|
||||
'A~F: 65~70
|
||||
'space:32
|
||||
If tmpString_tobe_process.Length > 0 Then
|
||||
For i = 1 To tmpString_tobe_process.Length
|
||||
Dim tmpChar As Char = CChar(Mid(tmpString_tobe_process, i, 1).ToUpper)
|
||||
|
||||
If (Asc(tmpChar) >= 48 AndAlso Asc(tmpChar) <= 57) OrElse '0~9
|
||||
(Asc(tmpChar) >= 65 AndAlso Asc(tmpChar) <= 70) OrElse 'A~F
|
||||
(Asc(tmpChar) = 32) Then 'space
|
||||
'合法内容
|
||||
Else
|
||||
strOutputString = "FALSE" '字符串处理后的返回值
|
||||
strErrMsg = $"字符串中包含非 hex 字符" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Case 3 '每个字符都必须是数字或字母, 用以排除乱码
|
||||
If tmpString_tobe_process.Length > 0 Then
|
||||
For i = 1 To tmpString_tobe_process.Length
|
||||
Dim tmpChar As Char = CChar(Mid(tmpString_tobe_process, i, 1))
|
||||
|
||||
If (Asc(tmpChar) >= 32 AndAlso Asc(tmpChar) <= 126) Then 'space
|
||||
'合法内容
|
||||
Else
|
||||
strOutputString = "FALSE" '字符串处理后的返回值
|
||||
strErrMsg = $"字符串中包含非文本字符" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
|
||||
Case Else '其他情况
|
||||
|
||||
End Select
|
||||
|
||||
strOutputString = "TRUE"
|
||||
strErrMsg = ""
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
|
||||
Function Run_FormatMode_Split_String(ByVal strSourceString As String,
|
||||
ByVal strSymbol_Of_Split As String,
|
||||
ByVal strReturnIdx As String,
|
||||
ByVal strElemnetConvetMode As String,
|
||||
ByRef strOutputString As String,
|
||||
ByRef strErrMsg As String) As Boolean
|
||||
|
||||
'strSourceString As String, : 1 源数据串
|
||||
'strSymbol_Of_Split As String, : 3 分隔符号
|
||||
'strReturnIdx As String, : 4 分隔后返回元素索引
|
||||
'strElemnetConvetMode As String, : 5 执行模式
|
||||
|
||||
Dim tmpStrElements() As String
|
||||
Dim tmpProcessedElements() As String
|
||||
Dim idx As Integer = CInt(Val(strReturnIdx))
|
||||
|
||||
Try
|
||||
'Step1:按字符对字符串进行分隔
|
||||
tmpStrElements = Split(strSourceString, strSymbol_Of_Split)
|
||||
ReDim tmpProcessedElements(tmpStrElements.Count)
|
||||
|
||||
'Step2:对每个字符串进行格式化处理
|
||||
Select Case Val(strElemnetConvetMode)
|
||||
Case ElementConvetModeEnum.FormatMode_Split_String_GetElement_By_Idx '分隔后按指定下标获取分隔后的字符,下标从0开始,每次只返回一个结果,指定下标超过长度是无返回
|
||||
If idx < tmpStrElements.Count Then
|
||||
'指定索引小于分隔后索引
|
||||
Dim tmpStr As String = Trim(tmpStrElements(idx))
|
||||
strOutputString = tmpStr '字符串处理后的返回值
|
||||
strErrMsg = "" '调试时显示在log窗口的信息’
|
||||
End If
|
||||
|
||||
Case Else
|
||||
strOutputString = "" '字符串处理后的返回值
|
||||
strErrMsg = $"Element_Convet_Mode 参数不正确" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End Select
|
||||
|
||||
'Step3:完成
|
||||
strErrMsg = ""
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
strOutputString = "" '字符串处理后的返回值
|
||||
strErrMsg = ex.Message.ToString '调试时显示在log窗口的信息’
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
Function Run_FormatMode_Split_Alignment_And_Regroup(ByVal strSourceString As String,
|
||||
ByVal strSymbol_Of_Split As String,
|
||||
ByVal strElement_Convet_Mode As String,
|
||||
ByVal strLength_Format As String,
|
||||
ByVal strConnect_Symbol As String,
|
||||
ByRef strOutputString As String,
|
||||
ByRef strErrMsg As String) As Boolean
|
||||
|
||||
Dim tmpStrElements() As String
|
||||
Dim tmpProcessedElements() As String
|
||||
Dim idx As Integer
|
||||
|
||||
Try
|
||||
'Step1:按字符对字符串进行分隔
|
||||
tmpStrElements = Split(strSourceString, strSymbol_Of_Split)
|
||||
ReDim tmpProcessedElements(tmpStrElements.Count)
|
||||
|
||||
'Step2:对每个字符串进行格式化处理
|
||||
For idx = 0 To tmpStrElements.Count - 1
|
||||
'Select Case Val(_Para(ParasEnum.Element_Convet_Mode))
|
||||
Select Case Val(strElement_Convet_Mode) 'Momo 2023-02-25 修正数据引用---未验证
|
||||
Case ElementConvetModeEnum.ElementConvetModeEnum_FixedLenght_Front_Fill_Zero '固定长度,不足长度加0
|
||||
tmpProcessedElements(idx) = Format(Val(tmpStrElements(idx)), "000").ToString
|
||||
|
||||
Case Else
|
||||
strOutputString = "" '字符串处理后的返回值
|
||||
strErrMsg = $"Element_Convet_Mode 参数不正确" '调试时显示在log窗口的信息’
|
||||
CommandReturn.ExecuteResult = False '函数处理结果,只能是bool类型’
|
||||
Return False
|
||||
End Select
|
||||
Next idx
|
||||
|
||||
'Step3:重组字符串
|
||||
strOutputString = ""
|
||||
For idx = 0 To tmpStrElements.Count - 1
|
||||
strOutputString = strOutputString & tmpProcessedElements(idx)
|
||||
If idx < tmpStrElements.Count - 1 Then strOutputString = strOutputString & strConnect_Symbol
|
||||
Next idx
|
||||
|
||||
|
||||
'Step4:完成
|
||||
strErrMsg = ""
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
strOutputString = "" '字符串处理后的返回值
|
||||
strErrMsg = ex.Message.ToString '调试时显示在log窗口的信息’
|
||||
Return False
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
'SourceString '源字符串
|
||||
' FormatMode '整形模式’
|
||||
' Symbol_Of_Split '分隔符’
|
||||
' Len_Of_SplitByFixedLength '按固定模式分隔的情况下,分隔长度依据’
|
||||
' Element_Convet_Mode '分隔后元素转换模式’
|
||||
' Length_Format '转换后元素格式化’
|
||||
' Connect_Symbol '连接字符’
|
||||
' OutputString '处理后字符串’
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
Imports UTS_Core.Expression
|
||||
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class GetBooleanExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _expression As String
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_expression = command.Parameter(0)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
If StringExpression.CheckExpressionString(_expression) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{_expression}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.ExecuteResult = StringExpression.GetBooleanResult(_expression)
|
||||
CommandReturn.RecordValue = CommandReturn.ExecuteResult.ToString()
|
||||
CommandReturn.ExecuteResultTipString = $"[{_expression}]获取的字符串结果为:{ CommandReturn.RecordValue}"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"TestCommandExecutor Error:{ex.Message}"
|
||||
End Try
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,20 @@
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class GetStringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _exp As String
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_exp = command.Parameter(0)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
CommandReturn.RecordValue = _exp
|
||||
CommandReturn.ExecuteResultTipString = $"获取的字符串结果为:{_exp}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,53 @@
|
||||
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class GetUTF8StringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _hexString As String
|
||||
Private ReadOnly _startIndex As Integer
|
||||
Private ReadOnly _length As Integer
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_hexString = command.Parameter(0)
|
||||
_startIndex = CInt(command.Parameter(1))
|
||||
_length = CInt(command.Parameter(2))
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim tmp As String() = _hexString.Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
|
||||
If tmp.Length = 0 Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"转换结果长度为0"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Dim bytes(tmp.Length - 1) As Byte
|
||||
Try
|
||||
For j As Integer = 0 To tmp.Length - 1
|
||||
bytes(j) = CByte($"&H{tmp(j)}")
|
||||
Next
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"转换失败,数组数据转换为Hex数据失败。"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End Try
|
||||
|
||||
If _startIndex + _length > bytes.Length Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"转换失败,目标长度超过原数据长度"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
CommandReturn.RecordValue = Text.Encoding.UTF8.GetString(bytes, _startIndex, _length).Replace(vbNullChar, "")
|
||||
CommandReturn.ExecuteResultTipString = $"获取的字符串结果为:{_hexString}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
Imports UTS_Core.Expression
|
||||
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class GetValueExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _expression As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_expression = command.Parameter(0)
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'检测有无需要计算的表达式
|
||||
If String.IsNullOrWhiteSpace(_expression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无表达式默认通过"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'检测表达式的有效性
|
||||
If StringExpression.CheckExpressionString(_expression) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"无效的表达式[{_expression}]"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = StringExpression.GetDoubleExpressionResult(_expression).ToString()
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{_expression}]计算的结果为:{CommandReturn.RecordValue}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"表达式[{_expression}]计算失败"
|
||||
Return CommandReturn
|
||||
End Try
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,76 @@
|
||||
Namespace UTSModule.Test.Command.ConverterCommand
|
||||
Public Class SubStringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _exp As String
|
||||
|
||||
Private ReadOnly _startString As String
|
||||
|
||||
Private ReadOnly _stringLenght As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_exp = command.Parameter(0)
|
||||
_startString = command.Parameter(1)
|
||||
_stringLenght = command.Parameter(2)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
If String.IsNullOrEmpty(_exp) Then
|
||||
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"源字符串不能为空"
|
||||
CommandReturn.ExecuteResult = False
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Dim startIndex As Integer
|
||||
If Integer.TryParse(_startString, startIndex) = False Then
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"无效的起始位置"
|
||||
CommandReturn.ExecuteResult = False
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
If String.IsNullOrWhiteSpace(_stringLenght) Then
|
||||
Try
|
||||
CommandReturn.RecordValue = _exp.Substring(startIndex)
|
||||
CommandReturn.ExecuteResultTipString = $"获取的字符串结果为:{CommandReturn.RecordValue}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"{ex.Message}"
|
||||
CommandReturn.ExecuteResult = False
|
||||
End Try
|
||||
|
||||
Else
|
||||
Dim length As Integer
|
||||
|
||||
If Integer.TryParse(_stringLenght, length) = False Then
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"无效的字符长度"
|
||||
CommandReturn.ExecuteResult = False
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
Try
|
||||
CommandReturn.RecordValue = _exp.Substring(startIndex, length)
|
||||
CommandReturn.ExecuteResultTipString = $"获取的字符串结果为:{CommandReturn.RecordValue}"
|
||||
CommandReturn.ExecuteResult = True
|
||||
Catch ex As Exception
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"{ex.Message}"
|
||||
CommandReturn.ExecuteResult = False
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,20 @@
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class CombindRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'链接本地库
|
||||
'获取本地库数据
|
||||
|
||||
'链接云端库
|
||||
'获取云端库数据
|
||||
'失败则写入同步表格
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,18 @@
|
||||
Namespace UTSModule.Test.Command.DatabaseCommand
|
||||
Public Class DatabaseCommandManager
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "GetRecord"
|
||||
Return New GetRecordCommand(command)
|
||||
Case "SetRecord"
|
||||
Return New SetRecordCommand(command)
|
||||
Case "CombindRecord"
|
||||
Return New CombindRecordCommand(command)
|
||||
Case Else
|
||||
Throw New Exception($"Database集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,25 @@
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class GetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
|
||||
Private _sn As String
|
||||
Private dbFiledName As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'链接云端库
|
||||
'获取云端库数据
|
||||
|
||||
|
||||
'链接本地库
|
||||
'获取本地库数据
|
||||
|
||||
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,19 @@
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class SetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'链接本地库
|
||||
'获取本地库数据
|
||||
|
||||
'链接云端库
|
||||
'获取云端库数据
|
||||
'失败则写入同步表格
|
||||
End Function
|
||||
End Class
|
||||
11
UTS_Core/UTSModule/Test/Command/ITestExecutor.vb
Normal file
11
UTS_Core/UTSModule/Test/Command/ITestExecutor.vb
Normal file
@@ -0,0 +1,11 @@
|
||||
Namespace UTSModule.Test.Command
|
||||
Public Interface ITestExecutor
|
||||
Function Execute() As TestCommandReturn
|
||||
|
||||
Function GetResult() As Boolean
|
||||
Function GetRecordValue() As String
|
||||
Function GetLowerLimit() As String
|
||||
Function GetUpperLimit() As String
|
||||
|
||||
End Interface
|
||||
End Namespace
|
||||
@@ -0,0 +1,291 @@
|
||||
Imports System.ComponentModel
|
||||
Imports System.IO
|
||||
|
||||
Namespace UTSModule.Test.Command.ProcessCommand
|
||||
Public Class ProcessCommandManager
|
||||
|
||||
Const ERROR_FILE_NOT_FOUND As Integer = 2
|
||||
Const ERROR_ACCESS_DENIED As Integer = 5
|
||||
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "Proc_Execute"
|
||||
executor = New ProcessExecuteExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"Process集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
|
||||
Return executor
|
||||
End Function
|
||||
|
||||
|
||||
'''' <summary>
|
||||
'''' 运行CMD命令并获取返回值
|
||||
'''' </summary>
|
||||
'''' <param name="filePath"></param>
|
||||
'''' <param name="arguments"></param>
|
||||
'''' <returns></returns>
|
||||
'Public Shared Function RunCmdGetReturn(filePath As String, arguments As String, ByRef result As String) As Boolean
|
||||
' Dim proc As New Process
|
||||
' With proc.StartInfo
|
||||
' .FileName = filePath
|
||||
' .Arguments = arguments
|
||||
' .UseShellExecute = False
|
||||
' .RedirectStandardInput = True
|
||||
' .RedirectStandardOutput = True
|
||||
' .RedirectStandardError = True
|
||||
' .CreateNoWindow = True
|
||||
' End With
|
||||
|
||||
' Dim errorMsg As String
|
||||
|
||||
' Try
|
||||
' proc.Start()
|
||||
' proc.WaitForExit()
|
||||
' result = proc.StandardOutput.ReadToEnd()
|
||||
' errorMsg = proc.StandardError.ReadToEnd()
|
||||
|
||||
' proc.Close()
|
||||
|
||||
' If errorMsg.Length > 0 Then
|
||||
' result = errorMsg
|
||||
' Return False
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' result = ex.Message
|
||||
' Return False
|
||||
' End Try
|
||||
|
||||
' Return True
|
||||
'End Function
|
||||
|
||||
'''' <summary>
|
||||
'''' 运行CMD命令并获取返回值
|
||||
'''' </summary>
|
||||
'''' <param name="filePath"></param>
|
||||
'''' <param name="arguments"></param>
|
||||
'''' <returns></returns>
|
||||
'Public Shared Function RunCmdGetReturn(filePath As String, arguments As String, timeout As Integer, ByRef result As String) As Boolean
|
||||
' Dim proc As New Process
|
||||
' With proc.StartInfo
|
||||
' .FileName = filePath
|
||||
' .Arguments = arguments
|
||||
' .UseShellExecute = False
|
||||
' .RedirectStandardInput = True
|
||||
' .RedirectStandardOutput = True
|
||||
' .RedirectStandardError = True
|
||||
' .CreateNoWindow = True
|
||||
' End With
|
||||
|
||||
' Dim errorMsg As String
|
||||
|
||||
' Try
|
||||
' proc.Start()
|
||||
' proc.WaitForExit(timeout)
|
||||
' result = proc.StandardOutput.ReadToEnd()
|
||||
' errorMsg = proc.StandardError.ReadToEnd()
|
||||
|
||||
' proc.Close()
|
||||
|
||||
' If errorMsg.Length > 0 Then
|
||||
' result = errorMsg
|
||||
' Return False
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' result = ex.Message
|
||||
' Return False
|
||||
' End Try
|
||||
|
||||
' Return True
|
||||
'End Function
|
||||
|
||||
'''' <summary>
|
||||
'''' 运行CMD命令并获取返回值 2022-10-25 1.6.1 版本,有时会出现外部程序已关闭后调用,结果弹出错误框
|
||||
'''' </summary>
|
||||
'''' <param name="filePath">执行文件路径</param>
|
||||
'''' <param name="arguments">执行参数</param>
|
||||
'''' <param name="timeout">超时时间</param>
|
||||
'''' <param name="sr">获取输出流内容</param>
|
||||
'''' <param name="destStr">目标字符串,为空则错误输出流有内容则判定失败</param>
|
||||
'''' <param name="result"></param>
|
||||
'''' <returns></returns>
|
||||
'Public Shared Function RunCmdGetReturn(filePath As String, arguments As String, timeout As Integer, sr As Integer, destStr As String, ByRef result As String) As Boolean
|
||||
|
||||
' 'Process used tips
|
||||
' 'Dim Process As Process = New Process()
|
||||
' 'Process.StartInfo.UseShellExecute = False '// 是否使用外壳程序
|
||||
' 'Process.StartInfo.CreateNoWindow = True '// 是否在新窗口中启动该进程的值
|
||||
' 'Process.StartInfo.RedirectStandardInput = True '// 重定向输入流
|
||||
' 'Process.StartInfo.RedirectStandardOutput = True '// 重定向输出流
|
||||
' 'Process.StartInfo.RedirectStandardError = True '// 重定向错误流
|
||||
|
||||
' '需要注意的是: 若要使用 StandardOutput, 必须将
|
||||
' 'Process.StartInfo.UseShellExecute = False
|
||||
' 'Process.StartInfo.RedirectStandardOutput = True
|
||||
' '否则, 读取StandardOutput 流时将引发异常;
|
||||
' 'https://blog.csdn.net/e295166319/article/details/77932082?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-77932082-blog-6859166.pc_relevant_vip_default&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-77932082-blog-6859166.pc_relevant_vip_default&utm_relevant_index=1
|
||||
|
||||
' Dim proc As New Process
|
||||
' With proc.StartInfo
|
||||
' .FileName = filePath '//待输入的执行文件路径
|
||||
' .Arguments = arguments
|
||||
' .UseShellExecute = False
|
||||
' ' .RedirectStandardInput = True
|
||||
|
||||
' If sr = 1 Then '标准错误流
|
||||
' .RedirectStandardError = True
|
||||
' Else
|
||||
' .RedirectStandardOutput = True
|
||||
' End If
|
||||
|
||||
' .CreateNoWindow = True
|
||||
' End With
|
||||
|
||||
' Dim pid As Integer
|
||||
' Try
|
||||
' proc.Start()
|
||||
|
||||
' pid = proc.Id
|
||||
' If timeout = 0 Then
|
||||
' proc.WaitForExit() '无限期等待进程结束
|
||||
' Else
|
||||
' If proc.WaitForExit(timeout) = False Then
|
||||
' result = "进程超时退出"
|
||||
' proc.Close()
|
||||
|
||||
' Try
|
||||
' Dim p As Process = Process.GetProcessById(pid)
|
||||
' If p IsNot Nothing Then p.Kill()
|
||||
' Catch ex As Exception
|
||||
' result &= $",{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' Return False
|
||||
' End If
|
||||
' End If
|
||||
|
||||
' Select Case sr
|
||||
' Case 0 '标准输出流
|
||||
' result = proc.StandardOutput.ReadToEnd()
|
||||
' Case 1 '标准错误流
|
||||
' result = proc.StandardError.ReadToEnd()
|
||||
' Case Else '默认标准输出流
|
||||
' result = proc.StandardOutput.ReadToEnd()
|
||||
' End Select
|
||||
|
||||
' proc.Close()
|
||||
|
||||
' If String.IsNullOrEmpty(destStr) Then
|
||||
' Return True
|
||||
' Else
|
||||
' Return result.Contains(destStr)
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' result = ex.Message
|
||||
' proc.Close()
|
||||
' Return False
|
||||
' End Try
|
||||
|
||||
' Return True
|
||||
'End Function
|
||||
|
||||
''' <summary>
|
||||
''' 运行CMD命令并获取返回值 2022-10-25 1.6.2 版本
|
||||
''' </summary>
|
||||
''' <param name="filePath">执行文件路径</param>
|
||||
''' <param name="arguments">执行参数</param>
|
||||
''' <param name="timeout">超时时间</param>
|
||||
''' <param name="sr">获取输出流内容</param>
|
||||
''' <param name="destStr">目标字符串,为空则错误输出流有内容则判定失败</param>
|
||||
''' <param name="result"></param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function RunCmdGetReturn(filePath As String, arguments As String, timeout As Integer, sr As Integer, destStr As String, ByRef result As String) As Boolean
|
||||
|
||||
'Process used tips
|
||||
'Dim Process As Process = New Process()
|
||||
'Process.StartInfo.UseShellExecute = False '// 是否使用外壳程序
|
||||
'Process.StartInfo.CreateNoWindow = True '// 是否在新窗口中启动该进程的值
|
||||
'Process.StartInfo.RedirectStandardInput = True '// 重定向输入流
|
||||
'Process.StartInfo.RedirectStandardOutput = True '// 重定向输出流
|
||||
'Process.StartInfo.RedirectStandardError = True '// 重定向错误流
|
||||
|
||||
'需要注意的是: 若要使用 StandardOutput, 必须将
|
||||
'Process.StartInfo.UseShellExecute = False
|
||||
'Process.StartInfo.RedirectStandardOutput = True
|
||||
'否则, 读取StandardOutput 流时将引发异常;
|
||||
'https://blog.csdn.net/e295166319/article/details/77932082?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-77932082-blog-6859166.pc_relevant_vip_default&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-1-77932082-blog-6859166.pc_relevant_vip_default&utm_relevant_index=1
|
||||
|
||||
Dim proc As New Process
|
||||
With proc.StartInfo
|
||||
.FileName = filePath '//待输入的执行文件路径
|
||||
.Arguments = arguments
|
||||
.UseShellExecute = False
|
||||
' .RedirectStandardInput = True
|
||||
|
||||
If sr = 1 Then '标准错误流
|
||||
.RedirectStandardError = True
|
||||
Else
|
||||
.RedirectStandardOutput = True
|
||||
End If
|
||||
|
||||
.CreateNoWindow = True
|
||||
End With
|
||||
|
||||
Dim pid As Integer
|
||||
Try
|
||||
proc.Start() '启动程序
|
||||
pid = proc.Id
|
||||
|
||||
'把读取返回的代码放到进程结束之前
|
||||
Select Case sr
|
||||
Case 0 '标准输出流
|
||||
result = proc.StandardOutput.ReadToEnd()
|
||||
Case 1 '标准错误流
|
||||
result = proc.StandardError.ReadToEnd()
|
||||
Case Else '默认标准输出流
|
||||
result = proc.StandardOutput.ReadToEnd()
|
||||
End Select
|
||||
|
||||
'等待程序执行完退出进
|
||||
If timeout = 0 Then
|
||||
proc.WaitForExit() '无限期等待进程结束
|
||||
Else
|
||||
If proc.WaitForExit(timeout) = False Then
|
||||
result = "进程超时退出"
|
||||
proc.Close()
|
||||
|
||||
Try
|
||||
Dim p As Process = Process.GetProcessById(pid)
|
||||
If p IsNot Nothing Then p.Kill()
|
||||
Catch ex As Exception
|
||||
result &= $",{ex.Message}"
|
||||
End Try
|
||||
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
|
||||
proc.Close()
|
||||
|
||||
If String.IsNullOrEmpty(destStr) Then
|
||||
Return True
|
||||
Else
|
||||
Return result.Contains(destStr)
|
||||
End If
|
||||
|
||||
Catch e As Win32Exception
|
||||
If e.NativeErrorCode = ERROR_FILE_NOT_FOUND Then result = e.Message & ",检查文件路径."
|
||||
If e.NativeErrorCode = ERROR_ACCESS_DENIED Then result = e.Message & ",没有权限操作文件."
|
||||
|
||||
Catch ex As Exception
|
||||
result = ex.Message
|
||||
proc.Close()
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,58 @@
|
||||
Namespace UTSModule.Test.Command.ProcessCommand
|
||||
Public Class ProcessExecuteExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _exePath As String
|
||||
Private ReadOnly _exeArgs As String
|
||||
|
||||
Private ReadOnly _timeout As Integer '程序执行的超时时间
|
||||
Private ReadOnly _stream As Integer '获取输出信息的对象
|
||||
Private ReadOnly _destSrc As String
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_exePath = TestCommandManger.ReplacePath(command.Parameter(0))
|
||||
_exeArgs = command.Parameter(1)
|
||||
|
||||
If IsNumeric(command.Parameter(2)) Then
|
||||
_timeout = CInt(command.Parameter(2))
|
||||
Else
|
||||
_timeout = 0
|
||||
End If
|
||||
|
||||
If IsNumeric(command.Parameter(3)) Then
|
||||
_stream = CInt(command.Parameter(3))
|
||||
Else
|
||||
_stream = 0
|
||||
End If
|
||||
|
||||
_destSrc = command.Parameter(4)
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'路径检测
|
||||
If IO.File.Exists(_exePath) = False Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"[{_exePath}]文件不存在"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
Dim exeResult As String = ""
|
||||
'进程执行
|
||||
|
||||
If ProcessCommandManager.RunCmdGetReturn(_exePath, _exeArgs, _timeout, _stream, _destSrc, exeResult) = False Then
|
||||
CommandReturn.ExecuteResultTipString = $"进程执行失败,{exeResult}"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Else
|
||||
CommandReturn.RecordValue = exeResult
|
||||
CommandReturn.ExecuteResultTipString = $"进程执行完成"
|
||||
CommandReturn.ExecuteResult = True
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,43 @@
|
||||
Imports UTS_Core.UTSModule.Station
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class CallExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _moduleName As String
|
||||
Private ReadOnly _localVariable As New Dictionary(Of String,String)
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_moduleName = command.Parameter(0)
|
||||
|
||||
Dim varNames() as String = command.Parameter(1).Split(":"c)
|
||||
Dim varValues() as String = command.Parameter(2).Split(":"c)
|
||||
For i As Integer = 0 To varNames.Count-1
|
||||
_localVariable.Add(varNames(i),varValues(i))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim tester As UtsTester = UtsTester.CreateTester()
|
||||
Dim rowNode As RowNode = tester.GetModule(_moduleName)
|
||||
|
||||
If rowNode Is Nothing Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = $"未查询到[{_moduleName}]模块存在"
|
||||
Else
|
||||
rowNode.IsRetry = IsRetry
|
||||
|
||||
Dim moduleResult As TestCommandReturn = tester.ExecutePlan(rowNode, _localVariable)
|
||||
|
||||
CommandReturn.ExecuteResult = moduleResult.ExecuteResult
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = moduleResult.ExecuteResultTipString
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,41 @@
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class CheckUtsPlatformExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _isWin As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_isWin = command.Parameter(0)
|
||||
|
||||
CommandReturn.LowerLimit = "True"
|
||||
|
||||
CommandReturn.UpperLimit = "True"
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
If String.Compare(_isWin, "False", True) = 0 Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = "流程未允许在当前平台测试"
|
||||
ElseIf String.Compare(_isWin, "0", True) = 0 Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = "流程未允许在当前平台测试"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = "当前平台测试允许测试"
|
||||
End If
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,65 @@
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class CheckUtsVersionExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _destVer As String
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
If IsNumeric(command.Parameter(0)) Then
|
||||
|
||||
_destVer = command.Parameter(0)
|
||||
Else
|
||||
_destVer = $"0"
|
||||
End If
|
||||
|
||||
If IsNumeric(command.Parameter(1)) Then
|
||||
|
||||
_destVer &= $".{command.Parameter(1)}"
|
||||
Else
|
||||
_destVer &= $".0"
|
||||
End If
|
||||
|
||||
If IsNumeric(command.Parameter(2)) Then
|
||||
_destVer &= $".{command.Parameter(2)}"
|
||||
Else
|
||||
_destVer &= $".0"
|
||||
|
||||
End If
|
||||
|
||||
|
||||
CommandReturn.LowerLimit = _destVer
|
||||
|
||||
CommandReturn.UpperLimit = _destVer
|
||||
|
||||
CommandReturn.RecordValue = Windows.Forms.Application.ProductVersion
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim appVer As Version = Version.Parse(CommandReturn.RecordValue)
|
||||
Dim cmdVer As New Version()
|
||||
|
||||
If Version.TryParse(_destVer, cmdVer) Then
|
||||
If appVer < cmdVer Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"应用程序版本 {appVer} 低于 指定版本 {_destVer}"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = $"版本校验成功"
|
||||
End If
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = $"非法的字符串:{_destVer}"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,97 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbConnect
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
Imports System.Linq
|
||||
|
||||
Public Class CombindRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedNames As New List(Of String)
|
||||
Private _dutSn As String
|
||||
Private _dutSn2 As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
'合并逻辑:将源SN指定字段的值复制到目标SN,如果目标SN已经有值,则进行覆盖操作
|
||||
'如果合并字段名为 S1~S12,则对应的Result1~Result12 也进行合并,即Sx与Resultx配对进行操作
|
||||
'覆盖方向:源SN -》 目标SN’
|
||||
_dutSn = command.Parameter(0) '目标SN’
|
||||
_dutSn2 = command.Parameter(1) '源SN’
|
||||
|
||||
'_filedNames.Add(command.Parameter(2)) '字段名,多个字段名之间用“:”分割,大小写不敏感,去掉前后空格
|
||||
|
||||
'Dim upperArr = arr.Select(Function(x) x.ToUpper()).ToArray()
|
||||
' upperArr = {"A", "B", "C"}
|
||||
|
||||
_filedNames.AddRange(command.Parameter(2).Split(":"c).Select(Function(x) x.Trim()))
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
|
||||
Dim filedName As String = _filedNames(0)
|
||||
Dim updateString As String = $"t1.`{filedName}` = t2.`{filedName}`"
|
||||
For i As Integer = 1 To _filedNames.Count - 1
|
||||
filedName = _filedNames(i)
|
||||
updateString += $",t1.`{filedName}` = t2.`{filedName}` "
|
||||
Next
|
||||
|
||||
|
||||
Dim saveDbCmdText As String = String.Empty
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim cmdText As String = $"UPDATE `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 On t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"数据库更新失败,{ex.Message}"
|
||||
End Try
|
||||
End Using
|
||||
|
||||
''本地存储
|
||||
'Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
' Try
|
||||
' db.Open()
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' Try
|
||||
' Dim cmdText As String = $"UPDATE `{SnListTable.TableName}` t1 JOIN `{UtsDb.RemotePrivateDb}`.`{SnListTable.TableName}` t2 ON t2.`{SnListTable.ColNames.BarCode}` = '{_dutSn2}' SET {updateString} WHERE t1.`{SnListTable.ColNames.BarCode}` = '{_dutSn}';"
|
||||
' db.ExecuteNonQuery(cmdText)
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
|
||||
' '本地缓存
|
||||
' Try
|
||||
' If Not String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
' DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
|
||||
' CommandReturn.ExecuteResultTipString = "本地缓存成功"
|
||||
' End If
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = "False"
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
|
||||
' db.Close()
|
||||
'End Using
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,35 @@
|
||||
Imports System.Threading
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class DelayMsExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
CommandReturn.LowerLimit = "True"
|
||||
|
||||
CommandReturn.UpperLimit = "True"
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim sleepTime As Integer = CInt(TestCommand.Parameter(0))
|
||||
|
||||
Thread.Sleep(sleepTime)
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = $"成功延时 {sleepTime} ms"
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
Imports System.Text
|
||||
Imports UTS_Core.Database
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
|
||||
''' <summary>
|
||||
''' 对数据库进行执行操作,用于查询单个字段内容
|
||||
''' </summary>
|
||||
Public Class GetDBDataExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _searchType As String
|
||||
Private _dbName As String
|
||||
Private _tbName As String
|
||||
Private _colNames As String
|
||||
Private _condition As String
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
_searchType = command.Parameter(0)
|
||||
_dbName = command.Parameter(1)
|
||||
_tbName = command.Parameter(2)
|
||||
_colNames = command.Parameter(3)
|
||||
_condition = command.Parameter(4)
|
||||
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Dim db As DbExecutor
|
||||
|
||||
Select Case _searchType
|
||||
Case "1"
|
||||
db = New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Case Else
|
||||
db = New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
End Select
|
||||
|
||||
'todo:此处有Sql注入的风险,应改为插值查询
|
||||
Dim cmd As New StringBuilder
|
||||
cmd.Append($"Select {_colNames} From ")
|
||||
If String.IsNullOrEmpty(_dbName) = False Then
|
||||
cmd.Append($" {_dbName}.")
|
||||
End If
|
||||
cmd.Append($"{_tbName}")
|
||||
|
||||
If String.IsNullOrWhiteSpace(_condition) = False Then
|
||||
cmd.Append($" WHERE {_condition}")
|
||||
End If
|
||||
cmd.Append(";")
|
||||
|
||||
'执行查询
|
||||
Try
|
||||
db.Open()
|
||||
|
||||
' db.AddDbParameter(DbType.AnsiString, "colNames", _colNames)
|
||||
'db.AddDbParameter(DbType.AnsiString, "dbName", _dbName)
|
||||
' db.AddDbParameter(DbType.AnsiString, "tbName", _tbName)
|
||||
'db.AddDbParameter(DbType.AnsiString, "condition", _condition)
|
||||
|
||||
Dim scalar As Object = db.ExecuteScalar(cmd.ToString)
|
||||
If scalar Is Nothing Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = "查询数据成功,返回值为空"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = scalar.ToString
|
||||
CommandReturn.ExecuteResultTipString = "查询数据成功"
|
||||
End If
|
||||
|
||||
db.ClearDbParameter()
|
||||
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = ex.Message
|
||||
End Try
|
||||
|
||||
'回收连接
|
||||
Try
|
||||
db.Dispose()
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,145 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class GetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedName As String
|
||||
Private _dutSn As String
|
||||
Private _mode As String
|
||||
|
||||
Private _LowerLimit As String = ""
|
||||
Private _UpperLimit As String = ""
|
||||
Private _stringLen_LowwerLimit As String = ""
|
||||
Private _stringLen_UpperLimit As String = ""
|
||||
Private _Char_VerfiyMode As String = ""
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_dutSn = command.Parameter(0)
|
||||
_filedName = command.Parameter(1)
|
||||
_mode = command.Parameter(2) 'Local:只查询本地 Remote:只查询云端 Both:查询本地和云端(云端优先)
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub GetByLocal()
|
||||
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
Try
|
||||
db.Open()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
Try
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
db.Close()
|
||||
End Using
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
Private Function GetByRemote() As Boolean
|
||||
Dim useLocalSearch As Boolean = False
|
||||
|
||||
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
CommandReturn.ExecuteResult = True
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
useLocalSearch = True '云端查询失败,使用本地查询
|
||||
End Try
|
||||
End Using
|
||||
|
||||
Return useLocalSearch
|
||||
End Function
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Select Case _mode
|
||||
Case "Local", "0"
|
||||
GetByLocal()
|
||||
Case "Both", "2"
|
||||
If GetByRemote() = False Then GetByLocal()
|
||||
|
||||
Case "Remote", "1"
|
||||
GetByRemote()
|
||||
Case Else
|
||||
GetByRemote()
|
||||
End Select
|
||||
|
||||
'todo:数据验证
|
||||
|
||||
|
||||
|
||||
|
||||
''优先查询云端
|
||||
'Dim useLocalSearch As Boolean = False
|
||||
'Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim cmdText As String = db.CmdHelper.DbSearch(UtsDb.RemotePrivateDb, _filedName, SnListTable.TableName, condition)
|
||||
|
||||
' Try
|
||||
' db.Open()
|
||||
' CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' db.Close()
|
||||
' Catch ex As Exception
|
||||
' useLocalSearch = True '云端查询失败,使用本地查询
|
||||
' End Try
|
||||
'End Using
|
||||
|
||||
|
||||
''本地存储
|
||||
'If useLocalSearch Then
|
||||
' Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
' Try
|
||||
' db.Open()
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = ""
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' Try
|
||||
' ' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
' Dim cmdText As String = db.CmdHelper.Search(_filedName, SnListTable.TableName, condition)
|
||||
' CommandReturn.RecordValue = db.ExecuteScalar(cmdText).ToString()
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库查询成功"
|
||||
' Catch ex As Exception
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.RecordValue = ""
|
||||
' CommandReturn.ExecuteResultTipString = $"本地数据库查询失败,{ex.Message}"
|
||||
' End Try
|
||||
|
||||
' db.Close()
|
||||
' End Using
|
||||
'End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,86 @@
|
||||
Imports UTS_Core.Database
|
||||
Imports UTS_Core.UTSModule
|
||||
Imports UTS_Core.UTSModule.DbConnect
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Public Class SetRecordCommand
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private _filedName As String
|
||||
Private _filedValue As String
|
||||
Private _dutSn As String
|
||||
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_dutSn = command.Parameter(0)
|
||||
_filedName = command.Parameter(1)
|
||||
_filedValue = command.Parameter(2)
|
||||
|
||||
'todo:SetRecord 只能对自定义字段进行写入,保护字段不执行’
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
|
||||
'优先储存云端
|
||||
Dim saveDbCmdText As String = String.Empty
|
||||
Using db As New DbExecutor(UtsDb.RemoteDbType, UtsDb.RemoteConnString)
|
||||
Dim updateString As String = $"`{_filedName}` = {_filedValue}"
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.DbUpdate(UtsDb.RemotePrivateDb, SnListTable.TableName, updateString, condition)
|
||||
|
||||
Try
|
||||
db.Open()
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
db.Close()
|
||||
Catch ex As Exception
|
||||
saveDbCmdText = cmdText '云端存储失败,转存本地
|
||||
End Try
|
||||
End Using
|
||||
|
||||
'本地存储
|
||||
Using db As New DbExecutor(UtsDb.LocalDbType, UtsDb.LocalConnString)
|
||||
Try
|
||||
db.Open()
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库连接失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
Try
|
||||
Dim updateString As String = $"`{_filedName}` = {_filedValue}"
|
||||
' Dim condition As String = $"`{SnListTable.ColNames.ProductID}` = '{Station.ParentProject.Index}' and `{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim condition As String = $"`{SnListTable.ColNames.BarCode}` = '{_dutSn}'"
|
||||
Dim cmdText As String = db.CmdHelper.Update(SnListTable.TableName, updateString, condition)
|
||||
db.ExecuteNonQuery(cmdText)
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库保存失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
|
||||
'本地缓存
|
||||
Try
|
||||
If Not String.IsNullOrEmpty(saveDbCmdText) Then
|
||||
DbConnector.SaveCmdStringToCacheTable(db, saveDbCmdText)
|
||||
CommandReturn.ExecuteResultTipString = "本地缓存成功"
|
||||
End If
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"本地数据库缓存失败,{ex.Message}"
|
||||
End Try
|
||||
|
||||
|
||||
db.Close()
|
||||
End Using
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
@@ -0,0 +1,97 @@
|
||||
Imports System.Windows.Forms
|
||||
Imports UTS_Core.UTSModule.Test.Controls
|
||||
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class ShowInputBoxExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _tipText As String
|
||||
Private ReadOnly _title As String
|
||||
Private ReadOnly _defaultText As String
|
||||
|
||||
Private stringLen_LowwerLimit As String = ""
|
||||
Private stringLen_UpperLimit As String = ""
|
||||
Private Char_VerfiyMode As String = ""
|
||||
Private InputBox_InputString As String = ""
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_tipText = TestCommand.Parameter(0)
|
||||
_title = TestCommand.Parameter(1)
|
||||
_defaultText = TestCommand.Parameter(2)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(3)
|
||||
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(4)
|
||||
|
||||
If TestCommand.Parameter.Count > 5 Then '判断参数数量,以便新版本软件与旧版本testplan兼容
|
||||
stringLen_LowwerLimit = Trim(TestCommand.Parameter(5))
|
||||
stringLen_UpperLimit = Trim(TestCommand.Parameter(6))
|
||||
Char_VerfiyMode = Trim(TestCommand.Parameter(7))
|
||||
End If
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Using box As New UtsInputBox
|
||||
box.DefaultText = _defaultText
|
||||
box.TipText = _tipText
|
||||
box.Title = _title
|
||||
box.StartPosition = FormStartPosition.CenterScreen
|
||||
box.TopMost = True
|
||||
If box.ShowDialog() = DialogResult.OK Then
|
||||
'CommandReturn.RecordValue = box.InputText
|
||||
InputBox_InputString = Trim(box.InputText)
|
||||
Else
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = "已取消输入框的输入"
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
End Using
|
||||
|
||||
'对比上下限 (忽略大小写,上下限字符均包含则返回TRUE,上下限为空白返回 TRUE)
|
||||
If CompareFunction.StringContain_Momo(InputBox_InputString, CommandReturn.LowerLimit, CommandReturn.UpperLimit) = True Then
|
||||
'对比字符串长度(长度符合上下限范围返回 TRUE,长度上下限为空白返回 TRUE)
|
||||
If CompareFunction.StringLengthCheck(InputBox_InputString, stringLen_LowwerLimit, stringLen_UpperLimit) = True Then
|
||||
'逐个字符格式比对
|
||||
If CompareFunction.StringEachCharCheck(InputBox_InputString, Char_VerfiyMode) = True Then
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = InputBox_InputString
|
||||
CommandReturn.ExecuteResultTipString = "输入框显示成功"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度:{InputBox_InputString.Length}, 逐字符格式匹配失败,匹配模式: {Char_VerfiyMode} "
|
||||
End If
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度:{InputBox_InputString.Length}, 不在 {stringLen_LowwerLimit} ~ {stringLen_UpperLimit} 之间"
|
||||
End If
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {InputBox_InputString},长度:{InputBox_InputString.Length}, 未包含:{stringLen_LowwerLimit} 或 {stringLen_UpperLimit} "
|
||||
End If
|
||||
|
||||
'If CommandReturn.ExecuteResult Then
|
||||
' CommandReturn.RecordValue = InputBox_InputString
|
||||
' CommandReturn.ExecuteResultTipString = "输入框显示成功"
|
||||
'Else
|
||||
' CommandReturn.ExecuteResultTipString = $"返回值 {CommandReturn.RecordValue} 不在 { CommandReturn.LowerLimit} ~ { CommandReturn.UpperLimit} 之间"
|
||||
'End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,80 @@
|
||||
Imports System.Diagnostics.Eventing.Reader
|
||||
Imports System.Windows.Forms
|
||||
Imports UTS_Core.UTSModule.Test.Controls
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class ShowMessageBoxExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _msgText As String
|
||||
Private ReadOnly _msgType As UtsMsgBox.UtsMsgBoxTypeEnum
|
||||
Private ReadOnly _msgTitle As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
If TestCommand.Parameter(1) = "0" Then
|
||||
_msgType = UtsMsgBox.UtsMsgBoxTypeEnum.OkOnly
|
||||
ElseIf TestCommand.Parameter(1) = "4" Then
|
||||
_msgType = UtsMsgBox.UtsMsgBoxTypeEnum.YesNo
|
||||
Else
|
||||
_msgType = UtsMsgBox.UtsMsgBoxTypeEnum.OkOnly
|
||||
End If
|
||||
|
||||
_msgText = TestCommand.Parameter(0)
|
||||
_msgTitle = TestCommand.Parameter(2)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(3)
|
||||
|
||||
CommandReturn.UpperLimit = String.Empty
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
|
||||
Using msg As New UtsMsgBox
|
||||
msg.MsgType = _msgType
|
||||
msg.MsgTitle = _msgTitle
|
||||
msg.MsgText = _msgText
|
||||
msg.StartPosition = FormStartPosition.CenterScreen
|
||||
msg.TopMost = True
|
||||
If msg.ShowDialog() = DialogResult.OK Then
|
||||
CommandReturn.RecordValue = "Yes"
|
||||
Else
|
||||
CommandReturn.RecordValue = "No"
|
||||
End If
|
||||
|
||||
CommandReturn.ExecuteResult = CompareFunction.StringCompare(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "显示消息框执行成功"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {CommandReturn.RecordValue} 不在 { CommandReturn.LowerLimit} ~ { CommandReturn.UpperLimit} 之间"
|
||||
End If
|
||||
|
||||
'If String.IsNullOrWhiteSpace(CommandReturn.LowerLimit) Then '无期望值
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' CommandReturn.ExecuteResultTipString = "显示消息框执行完成"
|
||||
'Else
|
||||
|
||||
|
||||
' If String.Compare(CommandReturn.LowerLimit, CommandReturn.RecordValue, True) = 0 Then '与期望值相符
|
||||
' CommandReturn.ExecuteResult = True
|
||||
' CommandReturn.ExecuteResultTipString = "显示消息框执行完成"
|
||||
' Else
|
||||
' CommandReturn.ExecuteResult = False
|
||||
' CommandReturn.ExecuteResultTipString = $"期望值 {CommandReturn.LowerLimit} 实际结果:{ CommandReturn.RecordValue} ,不相符"
|
||||
' End If
|
||||
'End If
|
||||
End Using
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,53 @@
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
''' <summary>
|
||||
''' 显示提示图像执行器
|
||||
''' 耦合了
|
||||
''' </summary>
|
||||
Public Class ShowTipImageExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Public Shared TipImageControl As PictureBox
|
||||
|
||||
Private ReadOnly _imgPath As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_imgPath =TestCommandManger.ReplacePath(TestCommand.Parameter(0))
|
||||
|
||||
CommandReturn.LowerLimit = "True"
|
||||
|
||||
CommandReturn.UpperLimit = "True"
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
If IO.File.Exists(_imgPath) Then
|
||||
Try
|
||||
TipImageControl.Image = ImageProcessor.ImageProcessor.GetBitmapImage(_imgPath)
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = "提示图像设置成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"未知错误:{ex.Message}"
|
||||
End Try
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"路径 {_imgPath} 不存在"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,111 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class ShowTipsExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
''' <summary>显示提示的控件</summary>
|
||||
Public Shared TipControl As Label
|
||||
|
||||
''' <summary>提示文本</summary>
|
||||
Private ReadOnly _tipTxt As String
|
||||
|
||||
''' <summary>背景颜色</summary>
|
||||
Private ReadOnly _bgColor As String
|
||||
|
||||
''' <summary>字体颜色</summary>
|
||||
Private ReadOnly _fontColor As String
|
||||
|
||||
''' <summary>字体名称</summary>
|
||||
Private ReadOnly _fontName As String
|
||||
|
||||
''' <summary>字体大小</summary>
|
||||
Private ReadOnly _fontSize As Integer
|
||||
|
||||
''' <summary>字体加粗</summary>
|
||||
Private ReadOnly _fontBold As Integer
|
||||
|
||||
''' <summary>显示模式</summary>
|
||||
Private ReadOnly _mode As Integer
|
||||
|
||||
''' <summary>模式参数</summary>
|
||||
Private ReadOnly _modeParam As String
|
||||
|
||||
Private Function HexStringToColor(hexString As String) As Color
|
||||
Dim val As Integer = Convert.ToInt32(hexString, 16)
|
||||
Return Color.FromArgb(val >> 16 And &HFF, val >> 8 And &HFF, val And &HFF)
|
||||
End Function
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_tipTxt = TestCommand.Parameter(0)
|
||||
|
||||
_bgColor = TestCommand.Parameter(1)
|
||||
|
||||
_fontColor = TestCommand.Parameter(2)
|
||||
|
||||
_fontName = TestCommand.Parameter(3)
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(4), _fontSize) = False Then
|
||||
_fontSize = 12 '默认字体大小
|
||||
End If
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(5), _fontBold) = False Then
|
||||
_fontBold = 0 '默认不加粗
|
||||
End If
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(6), _mode) = False Then
|
||||
_mode = 0 '默认正常显示
|
||||
End If
|
||||
|
||||
_modeParam = TestCommand.Parameter(7)
|
||||
|
||||
CommandReturn.LowerLimit = "True"
|
||||
|
||||
CommandReturn.UpperLimit = "True"
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
Try
|
||||
'委托执行
|
||||
TipControl.Text = _tipTxt
|
||||
TipControl.BackColor = HexStringToColor(_bgColor)
|
||||
TipControl.ForeColor = HexStringToColor(_fontColor)
|
||||
|
||||
If String.IsNullOrEmpty(_fontName) = False Then
|
||||
If _fontBold = 1 Then
|
||||
TipControl.Font = New Font(_fontName, _fontSize, FontStyle.Bold)
|
||||
Else
|
||||
TipControl.Font = New Font(_fontName, _fontSize)
|
||||
End If
|
||||
End If
|
||||
|
||||
Select Case _mode
|
||||
Case 0
|
||||
'默认模式
|
||||
Case 1
|
||||
'闪烁模式
|
||||
Case 2
|
||||
'滚动模式
|
||||
End Select
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = "提示文字设置成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"未知错误:{ex.Message}"
|
||||
End Try
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,124 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Imports UTS_Core.UTSModule.Test.Controls
|
||||
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class ShowTipsExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
''' <summary>显示提示的控件</summary>
|
||||
Public Shared TipControl As utsLabel
|
||||
|
||||
''' <summary>提示文本</summary>
|
||||
Private ReadOnly _tipTxt As String
|
||||
|
||||
''' <summary>背景颜色</summary>
|
||||
Private ReadOnly _bgColor As String
|
||||
|
||||
''' <summary>字体颜色</summary>
|
||||
Private ReadOnly _fontColor As String
|
||||
|
||||
''' <summary>字体名称</summary>
|
||||
Private ReadOnly _fontName As String
|
||||
|
||||
''' <summary>字体大小</summary>
|
||||
Private ReadOnly _fontSize As Integer
|
||||
|
||||
''' <summary>字体加粗</summary>
|
||||
Private ReadOnly _fontBold As Integer
|
||||
|
||||
''' <summary>显示模式</summary>
|
||||
Private ReadOnly _mode As Integer
|
||||
|
||||
''' <summary>模式参数</summary>
|
||||
Private ReadOnly _modeParam As String
|
||||
|
||||
Private Function HexStringToColor(hexString As String) As Color
|
||||
Dim val As Integer = Convert.ToInt32(hexString, 16)
|
||||
Return Color.FromArgb(val >> 16 And &HFF, val >> 8 And &HFF, val And &HFF)
|
||||
End Function
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_tipTxt = TestCommand.Parameter(0)
|
||||
|
||||
_bgColor = TestCommand.Parameter(1)
|
||||
|
||||
_fontColor = TestCommand.Parameter(2)
|
||||
|
||||
_fontName = TestCommand.Parameter(3)
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(4), _fontSize) = False Then
|
||||
_fontSize = 12 '默认字体大小
|
||||
End If
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(5), _fontBold) = False Then
|
||||
_fontBold = 0 '默认不加粗
|
||||
End If
|
||||
|
||||
If Integer.TryParse(TestCommand.Parameter(6), _mode) = False Then
|
||||
_mode = 0 '默认正常显示
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(TestCommand.Parameter(7)) Then
|
||||
_modeParam = "0:0:0:0:0"
|
||||
Else
|
||||
_modeParam = TestCommand.Parameter(7)
|
||||
End If
|
||||
|
||||
|
||||
CommandReturn.LowerLimit = "True"
|
||||
|
||||
CommandReturn.UpperLimit = "True"
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
If TipControl Is Nothing Then
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"未指定控件"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
If TipControl.InvokeRequired Then
|
||||
Return CType(TipControl.Invoke(New Func(Of TestCommandReturn)(AddressOf Execute)), TestCommandReturn)
|
||||
End If
|
||||
|
||||
Try
|
||||
'委托执行
|
||||
TipControl.Text = _tipTxt
|
||||
TipControl.BackColor = HexStringToColor(_bgColor)
|
||||
TipControl.ForeColor = HexStringToColor(_fontColor)
|
||||
|
||||
If String.IsNullOrEmpty(_fontName) = False Then
|
||||
If _fontBold = 1 Then
|
||||
TipControl.Font = New Font(_fontName, _fontSize, FontStyle.Bold)
|
||||
Else
|
||||
TipControl.Font = New Font(_fontName, _fontSize)
|
||||
End If
|
||||
End If
|
||||
|
||||
TipControl.modePara = _modeParam
|
||||
TipControl.dispMode = _mode
|
||||
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = "True"
|
||||
CommandReturn.ExecuteResultTipString = "提示文字设置成功"
|
||||
Catch ex As Exception
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = "False"
|
||||
CommandReturn.ExecuteResultTipString = $"未知错误:{ex.Message}"
|
||||
End Try
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,37 @@
|
||||
Namespace UTSModule.Test.Command.SystemCommand
|
||||
Public Class SystemCommandManger
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "Check_UTS_Platform"
|
||||
executor = New CheckUtsPlatformExecutor(command)
|
||||
Case "Check_UTS_Version"
|
||||
executor = New CheckUtsVersionExecutor(command)
|
||||
Case "Show_TipImage"
|
||||
executor = New ShowTipImageExecutor(command)
|
||||
Case "Show_InputBox"
|
||||
executor = New ShowInputBoxExecutor(command)
|
||||
Case "Show_MessageBox"
|
||||
executor = New ShowMessageBoxExecutor(command)
|
||||
Case "Delay_mS"
|
||||
executor = New DelayMsExecutor(command)
|
||||
Case "Show_Tips"
|
||||
executor = New ShowTipsExecutor(command)
|
||||
Case "Get_DB_Data"
|
||||
executor = New GetDBDataExecutor(command)
|
||||
Case "Call"
|
||||
executor = New CallExecutor(command)
|
||||
Case "GetRecord"
|
||||
Return New GetRecordCommand(command)
|
||||
Case "SetRecord"
|
||||
Return New SetRecordCommand(command)
|
||||
Case "CombindRecord"
|
||||
Return New CombindRecordCommand(command)
|
||||
Case Else
|
||||
Throw New Exception($"System集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
46
UTS_Core/UTSModule/Test/Command/TestCommand.vb
Normal file
46
UTS_Core/UTSModule/Test/Command/TestCommand.vb
Normal file
@@ -0,0 +1,46 @@
|
||||
Imports UTS_Core.UTSModule.Station
|
||||
|
||||
Namespace UTSModule.Test.Command
|
||||
Public Class TestCommand
|
||||
''' <summary>
|
||||
''' 测试命令类型
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Type() As String
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令名称
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Name() As String
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令参数
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Parameter() As List(Of String)
|
||||
|
||||
Sub New()
|
||||
Type = String.Empty
|
||||
Name = String.Empty
|
||||
Parameter = New List(Of String)()
|
||||
End Sub
|
||||
|
||||
Sub New(node As RowNode)
|
||||
Parameter = New List(Of String)()
|
||||
|
||||
If IsNothing(node) Then
|
||||
Type = String.Empty
|
||||
Name = String.Empty
|
||||
Else
|
||||
Type = node.CommandType
|
||||
Name = node.Command
|
||||
|
||||
For i As Integer = 0 To node.Parameters.Count - 1
|
||||
Parameter.Add(node.Parameters(i).Value)
|
||||
Next
|
||||
End If
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
35
UTS_Core/UTSModule/Test/Command/TestCommandExecutor.vb
Normal file
35
UTS_Core/UTSModule/Test/Command/TestCommandExecutor.vb
Normal file
@@ -0,0 +1,35 @@
|
||||
Namespace UTSModule.Test.Command
|
||||
Public MustInherit Class TestCommandExecutor
|
||||
Implements ITestExecutor
|
||||
|
||||
Public ReadOnly Property TestCommand() As TestCommand
|
||||
|
||||
Protected Property CommandReturn() As TestCommandReturn
|
||||
|
||||
Public Property IsRetry As Boolean
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
TestCommand = command
|
||||
CommandReturn = New TestCommandReturn()
|
||||
End Sub
|
||||
|
||||
Public MustOverride Function Execute() As TestCommandReturn Implements ITestExecutor.Execute
|
||||
|
||||
Public Function GetResult() As Boolean Implements ITestExecutor.GetResult
|
||||
Return CommandReturn.ExecuteResult
|
||||
End Function
|
||||
|
||||
Public Function GetRecordValue() As String Implements ITestExecutor.GetRecordValue
|
||||
Return CommandReturn.RecordValue
|
||||
End Function
|
||||
|
||||
|
||||
Public Function GetLowerLimit() As String Implements ITestExecutor.GetLowerLimit
|
||||
Return CommandReturn.LowerLimit
|
||||
End Function
|
||||
|
||||
Public Function GetUpperLimit() As String Implements ITestExecutor.GetUpperLimit
|
||||
Return CommandReturn.UpperLimit
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
67
UTS_Core/UTSModule/Test/Command/TestCommandManger.vb
Normal file
67
UTS_Core/UTSModule/Test/Command/TestCommandManger.vb
Normal file
@@ -0,0 +1,67 @@
|
||||
Imports UTS_Core.UTSModule.Test.Command.ComPortCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.ConverterCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.ProcessCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.SystemCommand
|
||||
Imports UTS_Core.UTSModule.Test.Command.UtsComPortCommand
|
||||
|
||||
Namespace UTSModule.Test.Command
|
||||
Public Class TestCommandManger
|
||||
''' <summary>
|
||||
''' 创建命令执行器
|
||||
''' </summary>
|
||||
''' <param name="command"></param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Select Case command.Type
|
||||
Case "System"
|
||||
Return SystemCommandManger.CreateExecutor(command)
|
||||
Case "Process"
|
||||
Return ProcessCommandManager.CreateExecutor(command)
|
||||
Case "ComPort"
|
||||
Return ComPortCommandManager.CreateExecutor(command)
|
||||
Case "UtsComPort"
|
||||
Return UtsComPortCommandManager.CreateExecutor(command)
|
||||
Case "Converter"
|
||||
Return ConverterCommandManager.CreateExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"Unknown CommandType :{command.Type}")
|
||||
End Select
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 将参数中的相对路径替换为绝对路径
|
||||
''' </summary>
|
||||
''' <param name="srcPath"></param>
|
||||
''' <returns></returns>
|
||||
Friend Shared Function ReplacePath(srcPath As String) As String
|
||||
If String.IsNullOrWhiteSpace(srcPath) Then Return srcPath
|
||||
If srcPath.StartsWith("/"c) = False AndAlso srcPath.StartsWith("\"c) = False Then Return srcPath
|
||||
|
||||
Return $"{UtsPath.StationPacketResourceDirPath}{srcPath}"
|
||||
End Function
|
||||
|
||||
|
||||
Public Enum DealTypes
|
||||
''' <summary>字符串处理</summary>
|
||||
[String]
|
||||
|
||||
''' <summary>字符串处理,以回车换行结尾</summary>
|
||||
StringAndCrlf
|
||||
|
||||
''' <summary>字符串处理,包含关系</summary>
|
||||
StringContain
|
||||
|
||||
''' <summary>十六进制字符串处理</summary>
|
||||
ByteString
|
||||
|
||||
''' <summary>整形字符串处理</summary>
|
||||
IntegerString
|
||||
|
||||
''' <summary>小数型字符串处理</summary>
|
||||
DoubleString
|
||||
|
||||
''' <summary>十六进制处理</summary>
|
||||
[Byte]
|
||||
End Enum
|
||||
End Class
|
||||
End Namespace
|
||||
63
UTS_Core/UTSModule/Test/Command/TestCommandReturn.vb
Normal file
63
UTS_Core/UTSModule/Test/Command/TestCommandReturn.vb
Normal file
@@ -0,0 +1,63 @@
|
||||
Namespace UTSModule.Test.Command
|
||||
Public Class TestCommandReturn
|
||||
Sub New()
|
||||
LowerLimit = String.Empty
|
||||
UpperLimit = String.Empty
|
||||
LowerLimit_2 = String.Empty
|
||||
UpperLimit_2 = String.Empty
|
||||
RecordValue = String.Empty
|
||||
ExecuteResultTipString = String.Empty
|
||||
ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 下限
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property LowerLimit() As String
|
||||
|
||||
''' <summary>
|
||||
''' 上限
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property UpperLimit() As String
|
||||
|
||||
''' <summary>
|
||||
''' 下限_2
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property LowerLimit_2() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 上限_2
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property UpperLimit_2() As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 执行结果
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ExecuteResult() As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 记录值
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property RecordValue() As String
|
||||
|
||||
''' <summary>
|
||||
''' 执行结果提示信息
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ExecuteResultTipString() As String
|
||||
|
||||
''' <summary>
|
||||
''' 执行耗时,包含重试耗时
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property StepTimeSpan() As TimeSpan
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,24 @@
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsComPortCommandManager
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "UTS_Write_Text"
|
||||
executor = New UtsWriteTextExecutor(command)
|
||||
' Case "UTS_Read_Text"
|
||||
|
||||
Case "UTS_WR_Text_String"
|
||||
executor = New UtsWrTextStringExecutor(command)
|
||||
Case "UTS_WR_Text_Integer"
|
||||
executor = New UtsWrTextIntegerExecutor(command)
|
||||
Case "UTS_WR_Text_Double"
|
||||
executor = New UtsWrTextDoubleExecutor(command)
|
||||
Case "UTS_WR_Text_Byte"
|
||||
executor = New UtsWrTextBytesExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"UtsComPort集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,45 @@
|
||||
Imports System.Text
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsComPortCommandManager
|
||||
Public Shared Function CreateExecutor(command As TestCommand) As TestCommandExecutor
|
||||
Dim executor As TestCommandExecutor
|
||||
Select Case command.Name
|
||||
Case "UTS_Write_Text"
|
||||
executor = New UtsWriteTextExecutor(command)
|
||||
' Case "UTS_Read_Text"
|
||||
|
||||
Case "UTS_WR_Text_String"
|
||||
executor = New UtsWrTextStringExecutor(command)
|
||||
Case "UTS_WR_Text_Integer"
|
||||
executor = New UtsWrTextIntegerExecutor(command)
|
||||
Case "UTS_WR_Text_Double"
|
||||
executor = New UtsWrTextDoubleExecutor(command)
|
||||
Case "UTS_WR_Text_Byte"
|
||||
executor = New UtsWrTextBytesExecutor(command)
|
||||
Case Else
|
||||
Throw New Exception($"UtsComPort集,未知命令 :{command.Name}")
|
||||
End Select
|
||||
Return executor
|
||||
End Function
|
||||
|
||||
Public Shared Function ReplaceWriteHexString(cmd As String, param As String) As String
|
||||
cmd = cmd.ToLower
|
||||
If cmd.EndsWith("hex") = False Then Return param
|
||||
|
||||
Dim sb As New StringBuilder
|
||||
param = param.Replace(" ", "")
|
||||
If param.Length Mod 2 <> 0 Then param = "0" & param
|
||||
|
||||
sb.Append(param.Chars(0))
|
||||
For i As Integer = 1 To param.Length - 1
|
||||
If i Mod 2 = 0 Then
|
||||
sb.Append(" ")
|
||||
End If
|
||||
sb.Append(param.Chars(i))
|
||||
Next
|
||||
|
||||
Return sb.ToString
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,137 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextBytesExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsExpression As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = TestCommand.Parameter(2)
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
_utsExpression = TestCommand.Parameter(4)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(5)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(6)
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
If UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData) = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
|
||||
If String.IsNullOrEmpty(_utsExpression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送正常,接受超时,无表达式默认通过"
|
||||
Else
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(_utsExpression) Then
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,无表达式默认通过"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'考虑多个表达式的结果用冒号分隔,填充到结果列表中
|
||||
Dim strExpression As New List(Of String)
|
||||
strExpression.AddRange(_utsExpression.Split(":"c))
|
||||
|
||||
Dim valueExpression As New List(Of String)
|
||||
|
||||
'转换接收,string转换为byte数组,byte通讯默认只会返回一个数组
|
||||
Dim tmp As String() = receiveData.Params(0).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
|
||||
Dim bytes(tmp.Length - 1) As Byte
|
||||
For j As Integer = 0 To tmp.Length - 1
|
||||
bytes(j) = CByte($"&H{tmp(j)}")
|
||||
Next
|
||||
|
||||
Dim recordBuild As New StringBuilder
|
||||
For i As Integer = 0 To strExpression.Count - 1
|
||||
Dim str As String = strExpression.Item(i)
|
||||
|
||||
If String.IsNullOrWhiteSpace(str) Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
str = str.Replace(" ", String.Empty)
|
||||
|
||||
str = Expression.StringExpression.ReplaceBytes(bytes, str)
|
||||
|
||||
'表达式为空或无效则默认不需要比较
|
||||
If String.IsNullOrWhiteSpace(str) Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim result As String
|
||||
|
||||
Try
|
||||
result = Expression.StringExpression.GetDoubleExpressionResult(str).ToString() '保留2位小数
|
||||
Catch ex As Exception
|
||||
result = String.Empty
|
||||
End Try
|
||||
|
||||
valueExpression.Add(result)
|
||||
|
||||
recordBuild.Append(result)
|
||||
If i < strExpression.Count - 1 Then recordBuild.Append(":"c)
|
||||
Next
|
||||
|
||||
'接收正常,处理表达式结果数据是否在期望范围内
|
||||
CommandReturn.RecordValue = recordBuild.ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamDoubleListCompare(valueExpression, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,156 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.DebugLog
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextBytesExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsExpression As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
_utsExpression = TestCommand.Parameter(4)
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(5)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(6)
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
Dim cmdStatus As TestCommandStatusMonitor.TestCommandStatusEnum = UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData)
|
||||
If cmdStatus = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
|
||||
If String.IsNullOrEmpty(_utsExpression) Then
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送正常,接受超时,无表达式默认通过"
|
||||
Else
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If receiveData Is Nothing Then
|
||||
ApplicationLog.WriteFatalLog($"测试器异常情况,串口返回状态:{cmdStatus}")
|
||||
CommandReturn.ExecuteResultTipString = "测试器异常情况,串口返回状态:{cmdStatus}"
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'2024-05-20 当返回数据参数为空时直接返回错误
|
||||
If receiveData.Params.Count = 0 Then
|
||||
ApplicationLog.WriteFatalLog($"测试器异常情况,串口返回正常,参数为空")
|
||||
CommandReturn.ExecuteResultTipString = "测试器异常情况,串口返回正常,参数为空"
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If String.IsNullOrEmpty(_utsExpression) Then
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,无表达式默认通过"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'考虑多个表达式的结果用冒号分隔,填充到结果列表中
|
||||
Dim strExpression As New List(Of String)
|
||||
strExpression.AddRange(_utsExpression.Split(":"c))
|
||||
|
||||
Dim valueExpression As New List(Of String)
|
||||
|
||||
'转换接收,string转换为byte数组,byte通讯默认只会返回一个数组
|
||||
Dim tmp As String() = receiveData.Params(0).Split(New Char() {" "c}, StringSplitOptions.RemoveEmptyEntries)
|
||||
Dim bytes(tmp.Length - 1) As Byte
|
||||
For j As Integer = 0 To tmp.Length - 1
|
||||
bytes(j) = CByte($"&H{tmp(j)}")
|
||||
Next
|
||||
|
||||
Dim recordBuild As New StringBuilder
|
||||
For i As Integer = 0 To strExpression.Count - 1
|
||||
Dim str As String = strExpression.Item(i)
|
||||
|
||||
If String.IsNullOrWhiteSpace(str) Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
str = str.Replace(" ", String.Empty)
|
||||
|
||||
str = Expression.StringExpression.ReplaceBytes(bytes, str)
|
||||
|
||||
'表达式为空或无效则默认不需要比较
|
||||
If String.IsNullOrWhiteSpace(str) Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If Expression.StringExpression.CheckExpressionString(str) = False Then
|
||||
valueExpression.Add(String.Empty)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
Dim result As String
|
||||
|
||||
Try
|
||||
result = Expression.StringExpression.GetDoubleExpressionResult(str).ToString() '保留2位小数
|
||||
Catch ex As Exception
|
||||
result = String.Empty
|
||||
End Try
|
||||
|
||||
valueExpression.Add(result)
|
||||
|
||||
recordBuild.Append(result)
|
||||
If i < strExpression.Count - 1 Then recordBuild.Append(":"c)
|
||||
Next
|
||||
|
||||
'接收正常,处理表达式结果数据是否在期望范围内
|
||||
CommandReturn.RecordValue = recordBuild.ToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamDoubleListCompare(valueExpression, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,69 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextDoubleExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = TestCommand.Parameter(2)
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
If UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData) = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
'接收数据失败,超时
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamDoubleListCompare(receiveData.Params, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,117 @@
|
||||
Imports UTS_Core.DebugLog
|
||||
Imports UTS_Core.Expression
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextDoubleExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
'Momo 2022-11-10 上下限支持表达式
|
||||
Dim tmpLowerLmt As String = TestCommand.Parameter(4)
|
||||
Dim tmpUpperLmt As String = TestCommand.Parameter(5)
|
||||
|
||||
Dim tmpStrVal_LowerLmt As String = ""
|
||||
Dim tmpStrVal_UpperLmt As String = ""
|
||||
|
||||
'Standard_1''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
If StringExpression.ExecuteLimit(tmpLowerLmt, tmpStrVal_LowerLmt) = True AndAlso
|
||||
StringExpression.ExecuteLimit(tmpUpperLmt, tmpStrVal_UpperLmt) = True Then
|
||||
CommandReturn.LowerLimit = tmpStrVal_LowerLmt
|
||||
CommandReturn.UpperLimit = tmpStrVal_UpperLmt
|
||||
Else
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
End If
|
||||
''''''''''''''''''''''''''''''''''''''''''''
|
||||
'Standard_2 如果参数个数大于7个'''''''''''''''''''''''''''''''''''''''''''''''''''''''
|
||||
If TestCommand.Parameter.Count >= 8 Then
|
||||
Dim tmpLowerLmt_2 As String = TestCommand.Parameter(6)
|
||||
Dim tmpUpperLmt_2 As String = TestCommand.Parameter(7)
|
||||
If StringExpression.ExecuteLimit(tmpLowerLmt_2, tmpStrVal_LowerLmt) = True AndAlso
|
||||
StringExpression.ExecuteLimit(tmpUpperLmt_2, tmpStrVal_UpperLmt) = True Then
|
||||
CommandReturn.LowerLimit_2 = tmpStrVal_LowerLmt
|
||||
CommandReturn.UpperLimit_2 = tmpStrVal_UpperLmt
|
||||
Else
|
||||
CommandReturn.LowerLimit_2 = TestCommand.Parameter(6)
|
||||
CommandReturn.UpperLimit_2 = TestCommand.Parameter(7)
|
||||
End If
|
||||
End If
|
||||
''''''''''''''''''''''''''''''''''''''''''''
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
Dim cmdStatus As TestCommandStatusMonitor.TestCommandStatusEnum = UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData)
|
||||
If cmdStatus = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
'接收数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If receiveData Is Nothing Then
|
||||
ApplicationLog.WriteFatalLog($"测试器异常情况,串口返回状态:{cmdStatus}")
|
||||
CommandReturn.ExecuteResultTipString = "测试器异常情况,串口返回状态:{cmdStatus}"
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
'标准判定 ' Momo 2023-12-15 增加标准2的判定
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamDoubleListCompare(receiveData.Params,
|
||||
CommandReturn.LowerLimit,
|
||||
CommandReturn.UpperLimit,
|
||||
CommandReturn.LowerLimit_2,
|
||||
CommandReturn.UpperLimit_2)
|
||||
|
||||
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,70 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextIntegerExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = TestCommand.Parameter(2)
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
If UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData) = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
'接收数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamIntegerListCompare(receiveData.Params, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End NameSpace
|
||||
@@ -0,0 +1,96 @@
|
||||
Imports UTS_Core.DebugLog
|
||||
Imports UTS_Core.Expression
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextIntegerExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
'Momo 2022-11-10 上下限支持表达式
|
||||
Dim tmpLowerLmt As String = TestCommand.Parameter(4)
|
||||
Dim tmpUpperLmt As String = TestCommand.Parameter(5)
|
||||
Dim tmpStrVal_LowerLmt As String = ""
|
||||
Dim tmpStrVal_UpperLmt As String = ""
|
||||
If StringExpression.ExecuteLimit(tmpLowerLmt, tmpStrVal_LowerLmt) = True AndAlso
|
||||
StringExpression.ExecuteLimit(tmpUpperLmt, tmpStrVal_UpperLmt) = True Then
|
||||
CommandReturn.LowerLimit = tmpStrVal_LowerLmt
|
||||
CommandReturn.UpperLimit = tmpStrVal_UpperLmt
|
||||
Else
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
End If
|
||||
''''''''''''''''''''''''''''''''''''''''''''
|
||||
|
||||
'CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
'CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
Dim cmdStatus As TestCommandStatusMonitor.TestCommandStatusEnum = UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData)
|
||||
If cmdStatus = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
'接收数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If receiveData Is Nothing Then
|
||||
ApplicationLog.WriteFatalLog($"测试器异常情况,串口返回状态:{cmdStatus}")
|
||||
CommandReturn.ExecuteResultTipString = "测试器异常情况,串口返回状态:{cmdStatus}"
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamIntegerListCompare(receiveData.Params, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,72 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextStringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = TestCommand.Parameter(2)
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
If UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData) =
|
||||
TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then '接收数据超时
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
|
||||
'接收正常,处理数据是否在期望范围内
|
||||
CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
CommandReturn.ExecuteResult = CompareFunction.ParamStringListCompare(receiveData.Params, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
If CommandReturn.ExecuteResult Then
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
Else
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,145 @@
|
||||
Imports UTS_Core.DebugLog
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWrTextStringExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
Private ReadOnly _timeout As Integer
|
||||
Private stringLen_Limit As String = ""
|
||||
Private Char_VerfiyMode As String = ""
|
||||
Private ReturnString_Tobe_Processed As String = ""
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))
|
||||
_timeout = CInt(TestCommand.Parameter(3))
|
||||
|
||||
CommandReturn.LowerLimit = TestCommand.Parameter(4)
|
||||
CommandReturn.UpperLimit = TestCommand.Parameter(5)
|
||||
|
||||
If TestCommand.Parameter.Count > 6 Then '判断参数数量,以便新版本软件与旧版本testplan兼容
|
||||
stringLen_Limit = Trim(TestCommand.Parameter(6))
|
||||
Char_VerfiyMode = Trim(TestCommand.Parameter(7))
|
||||
End If
|
||||
|
||||
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 执行串口通讯命令,接收返回值,并比较返回数据是否在期望上下范围中
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
'调用测试串口等待接收完成接口
|
||||
Dim receiveData As UtsComPortData = Nothing
|
||||
Dim cmdStatus As TestCommandStatusMonitor.TestCommandStatusEnum = UtsComportTask.ReceivedTestCommandReturn(_timeout, receiveData)
|
||||
If cmdStatus = TestCommandStatusMonitor.TestCommandStatusEnum.ReceiveTimeout Then
|
||||
'接收数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯接收异常"
|
||||
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
If receiveData Is Nothing Then
|
||||
ApplicationLog.WriteFatalLog($"测试器异常情况,串口返回状态:{cmdStatus}")
|
||||
CommandReturn.ExecuteResultTipString = "测试器异常情况,串口返回状态:{cmdStatus}"
|
||||
CommandReturn.RecordValue = ""
|
||||
CommandReturn.ExecuteResult = False
|
||||
Return CommandReturn
|
||||
End If
|
||||
|
||||
|
||||
|
||||
''接收正常,处理数据是否在期望范围内
|
||||
'CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
'CommandReturn.ExecuteResult = CompareFunction.ParamStringListCompare(receiveData.Params, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
'If CommandReturn.ExecuteResult Then
|
||||
' CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
'Else
|
||||
' CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
'End If
|
||||
|
||||
''接收正常,处理数据是否在期望范围内
|
||||
''Momo 2022-11-14 对于UTS_WR_Text_String 命令,判断标准改为包含关系,即:返回字符串包含目标字符串即算pass
|
||||
''接收正常,处理数据是否在期望范围内
|
||||
'CommandReturn.RecordValue = receiveData.ParamListToString()
|
||||
'CommandReturn.ExecuteResult = CompareFunction.StringContain_Momo(CommandReturn.RecordValue, CommandReturn.LowerLimit, CommandReturn.UpperLimit)
|
||||
|
||||
'If CommandReturn.ExecuteResult Then
|
||||
' CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围内"
|
||||
'Else
|
||||
' CommandReturn.ExecuteResultTipString = "执行串口通讯收发正常,数据在有效范围外"
|
||||
'End If
|
||||
'‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’‘’’
|
||||
'Momo 2023-03-07 增加格式判断
|
||||
ReturnString_Tobe_Processed = receiveData.ParamListToString()
|
||||
'最长只取255个字节
|
||||
If ReturnString_Tobe_Processed.Length >= 255 Then ReturnString_Tobe_Processed = Left(ReturnString_Tobe_Processed, 255)
|
||||
|
||||
'上下限包含判断
|
||||
If CompareFunction.StringContain_Momo(ReturnString_Tobe_Processed, CommandReturn.LowerLimit, CommandReturn.UpperLimit) = True Then
|
||||
Dim tmpLenLowerlimit As String = ""
|
||||
Dim tmpLenUpperlimit As String = ""
|
||||
Dim tmpLimt() As String = Split(stringLen_Limit, ",")
|
||||
If tmpLimt.Count >= 2 Then
|
||||
tmpLenLowerlimit = Trim(tmpLimt(0))
|
||||
tmpLenUpperlimit = Trim(tmpLimt(1))
|
||||
End If
|
||||
'’If String.IsNullOrEmpty(tmpLenLowerlimit) AndAlso String.IsNullOrEmpty(tmpLenUpperlimit) Then '上下限都是合法数据
|
||||
'对比字符串长度(长度符合上下限范围返回 TRUE,长度上下限为空白返回 TRUE)
|
||||
If CompareFunction.StringLengthCheck(ReturnString_Tobe_Processed, tmpLenLowerlimit, tmpLenUpperlimit) = True Then
|
||||
'逐个字符格式比对
|
||||
If CompareFunction.StringEachCharCheck(ReturnString_Tobe_Processed, Char_VerfiyMode) = True Then
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.RecordValue = ReturnString_Tobe_Processed
|
||||
CommandReturn.ExecuteResultTipString = "输入框显示成功"
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ReturnString_Tobe_Processed
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {ReturnString_Tobe_Processed},长度:{ReturnString_Tobe_Processed.Length}, 逐字符格式匹配失败,匹配模式: {Char_VerfiyMode} "
|
||||
End If
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ReturnString_Tobe_Processed
|
||||
CommandReturn.ExecuteResultTipString = $"返回值 {ReturnString_Tobe_Processed},长度:{ReturnString_Tobe_Processed.Length}, 不在 {tmpLenLowerlimit} ~ {tmpLenUpperlimit} 之间"
|
||||
End If
|
||||
'End If
|
||||
Else
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.RecordValue = ReturnString_Tobe_Processed
|
||||
CommandReturn.ExecuteResultTipString = $"执行串口通讯收发正常,返回值 {ReturnString_Tobe_Processed},长度:{ReturnString_Tobe_Processed.Length }, 未包含: {CommandReturn.LowerLimit} 或 { CommandReturn.UpperLimit} "
|
||||
End If
|
||||
|
||||
|
||||
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,47 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWriteTextExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = TestCommand.Parameter(2)
|
||||
|
||||
CommandReturn.LowerLimit = String.Empty
|
||||
CommandReturn.UpperLimit = String.Empty
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData, True) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
Else
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送完成"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,47 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
|
||||
Namespace UTSModule.Test.Command.UtsComPortCommand
|
||||
Public Class UtsWriteTextExecutor
|
||||
Inherits TestCommandExecutor
|
||||
|
||||
Private ReadOnly _receiverAddress As String
|
||||
Private ReadOnly _utsCommand As String
|
||||
Private ReadOnly _utsParamString As String
|
||||
|
||||
Sub New(command As TestCommand)
|
||||
MyBase.New(command)
|
||||
|
||||
_receiverAddress = TestCommand.Parameter(0)
|
||||
_utsCommand = TestCommand.Parameter(1)
|
||||
_utsParamString = UtsComPortCommandManager.ReplaceWriteHexString(_utsCommand, TestCommand.Parameter(2))
|
||||
|
||||
CommandReturn.LowerLimit = String.Empty
|
||||
CommandReturn.UpperLimit = String.Empty
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResultTipString = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
End Sub
|
||||
|
||||
|
||||
Public Overrides Function Execute() As TestCommandReturn
|
||||
'组包
|
||||
Dim sendData As New UtsComPortData(_receiverAddress, _utsCommand, _utsParamString)
|
||||
|
||||
'调用测试串口发送接口
|
||||
If UtsComportTask.SendTestCommand(sendData, True) = TestCommandStatusMonitor.TestCommandStatusEnum.SendingFailure Then
|
||||
'发送数据失败
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = False
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送异常"
|
||||
Return CommandReturn
|
||||
Else
|
||||
CommandReturn.RecordValue = String.Empty
|
||||
CommandReturn.ExecuteResult = True
|
||||
CommandReturn.ExecuteResultTipString = "执行串口通讯发送完成"
|
||||
End If
|
||||
|
||||
Return CommandReturn
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
689
UTS_Core/UTSModule/Test/ControllerComPortTask.vb
Normal file
689
UTS_Core/UTSModule/Test/ControllerComPortTask.vb
Normal file
@@ -0,0 +1,689 @@
|
||||
Imports System.IO.Ports
|
||||
Imports System.Text
|
||||
Imports System.Threading
|
||||
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.TestCommandStatusMonitor
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class ControllerComPortTask
|
||||
Private _stateMachineTaskStatus As StateMachineStatus
|
||||
|
||||
''' <summary>
|
||||
''' 当前串口对象
|
||||
''' </summary>
|
||||
Public ReadOnly Conn As ControllerComPort
|
||||
|
||||
''' <summary>
|
||||
''' UTS串口波特率,默认115200
|
||||
''' </summary>
|
||||
Public Property ComportBaudRate As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 接收等待最长毫秒数,默认100ms
|
||||
''' </summary>
|
||||
Public Property NormalWaitReplyMaxTime As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口通讯写入失败计数,通讯成功置零,通讯失败则加1
|
||||
''' </summary>
|
||||
Public Property ComportWriteFailCount As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口通讯写入失败最大上限,默认5次
|
||||
''' </summary>
|
||||
Public Property ComportWriteMaxFailCount As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 状态机执行间隔,默认10ms
|
||||
''' </summary>
|
||||
Public Property StateMachineInterval As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 发送同步命令的间隔,默认1000ms
|
||||
''' </summary>
|
||||
Public SendSyncInterval As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 测试状态是否发生变化
|
||||
''' </summary>
|
||||
Public TestStatusChanged As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 是否收到按键主动数据,需要回复ACK
|
||||
''' </summary>
|
||||
Public WaitReplyKeyStatusAck As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 发送同步命令的时间
|
||||
''' </summary>
|
||||
Public SendSyncTime As DateTime
|
||||
|
||||
''' <summary>
|
||||
''' 已发送通讯数据,等待回复的时间
|
||||
''' </summary>
|
||||
Public WaitReplyStartTime As DateTime
|
||||
|
||||
''' <summary>
|
||||
''' 当前可以访问的串口名集合
|
||||
''' </summary>
|
||||
Private Shared ReadOnly ComportNames As New Queue(Of String)
|
||||
|
||||
''' <summary>按键串口控制器句柄,全局唯一</summary>
|
||||
Private Shared _controller As ControllerComPortTask
|
||||
|
||||
''' <summary>初始化测试器线程锁</summary>
|
||||
Private Shared ReadOnly InitLock As New Object()
|
||||
|
||||
''' <summary>
|
||||
''' 创建按键串口控制器,若按键串口控制器已经创建则返回句柄
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function CreateControllerPortTask() As ControllerComPortTask
|
||||
If _controller Is Nothing Then
|
||||
SyncLock InitLock
|
||||
Thread.MemoryBarrier()
|
||||
If _controller Is Nothing Then
|
||||
_controller = New ControllerComPortTask
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
Return _controller
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub New()
|
||||
Conn = New ControllerComPort()
|
||||
|
||||
ComportBaudRate = 115200
|
||||
NormalWaitReplyMaxTime = 100
|
||||
ComportWriteFailCount = 0
|
||||
ComportWriteMaxFailCount = 5
|
||||
|
||||
StateMachineInterval = 10
|
||||
|
||||
SendSyncInterval = 1000
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 开启任务
|
||||
''' </summary>
|
||||
Public Sub StartTask()
|
||||
'todo:当前版本无控制器,取消开启控制器状态机
|
||||
Return
|
||||
|
||||
'避免重复开启状态机
|
||||
If _stateMachineTaskStatus <> StateMachineStatus.Quit Then Return
|
||||
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
|
||||
'状态机执行
|
||||
While _stateMachineTaskStatus <> StateMachineStatus.Quit
|
||||
StateMachine()
|
||||
Thread.Sleep(StateMachineInterval)
|
||||
End While
|
||||
|
||||
'状态机退出
|
||||
Conn.CloseSerialPort()
|
||||
End Sub
|
||||
|
||||
Public Sub EndTask()
|
||||
_stateMachineTaskStatus = StateMachineStatus.Quit
|
||||
End Sub
|
||||
|
||||
#Region "控制模块"
|
||||
|
||||
''' <summary>
|
||||
''' 期望回复的测试命令。发送测试命令后,判断串口接收是否为指定命令的回复数据
|
||||
''' </summary>
|
||||
Public ExpectReplyTestCommand As String = ""
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 需要发送的测试命令
|
||||
''' </summary>
|
||||
Public TestSendData As ControllerComPortData
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 接收测试命令
|
||||
''' </summary>
|
||||
Public TestReceiveData As ControllerComPortData
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令接收等待最长时间
|
||||
''' </summary>
|
||||
Public TestWaitReplyMaxTime As Integer = 100
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
#Region "状态机执行细节"
|
||||
''' <summary>
|
||||
''' J_Controller状态机
|
||||
''' </summary>
|
||||
Private Sub StateMachine()
|
||||
Pretreatment()
|
||||
|
||||
Select Case _stateMachineTaskStatus
|
||||
Case StateMachineStatus.Quit
|
||||
'退出状态机
|
||||
Case StateMachineStatus.Idle
|
||||
IdleFunction()
|
||||
Case StateMachineStatus.GetComport
|
||||
Thread.Sleep(500) '避免串口打开操作过于频繁
|
||||
GetComPortFunction()
|
||||
Case StateMachineStatus.SendHearBeat
|
||||
SendHearBeat()
|
||||
Case StateMachineStatus.WaitReply
|
||||
WaitReply()
|
||||
Case StateMachineStatus.SendCommand
|
||||
SendCommand()
|
||||
Case StateMachineStatus.ReplyKeyStatusAck
|
||||
ReplyKeyStatusAck()
|
||||
Case StateMachineStatus.ComportConnected
|
||||
ComportConnected()
|
||||
Case StateMachineStatus.ComportDisconnected
|
||||
ComportDisconnected()
|
||||
Case Else
|
||||
Throw New Exception($"Unknown ControllerStatus {_stateMachineTaskStatus}")
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Sub Pretreatment()
|
||||
'自动上报的命令处理
|
||||
If Conn.CacheData.Count = 0 Then Return
|
||||
|
||||
For i As Integer = 0 To Conn.CacheData.Count - 1
|
||||
Dim receivedData As ControllerComPortData = Conn.CacheData.Peek()
|
||||
|
||||
'处理自发上报通讯数据
|
||||
If String.Compare(receivedData.Command, "KEY_EVENT", True) = 0 Then '按键按下
|
||||
'避免状态机卡顿
|
||||
ThreadPool.QueueUserWorkItem(AddressOf UpdateKeyValue, receivedData.Params(0))
|
||||
WaitReplyKeyStatusAck = True '需要回复键值包ACK
|
||||
Conn.CacheData.Dequeue() '移除头部
|
||||
ElseIf String.Compare(receivedData.Command, "INPUT_CHANGE_CH", True) = 0 Then '电平变化按下
|
||||
'todo:具体处理通道
|
||||
Else
|
||||
If _stateMachineTaskStatus = UtsComportTask.ComportStatusEnum.WaitReply Then
|
||||
Continue For
|
||||
Else
|
||||
Conn.CacheData.Dequeue() '移除头部
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub UpdateKeyValue(obj As Object)
|
||||
Dim key As String = obj.ToString()
|
||||
Dim tmp As UtsKeyValueMonitor.UtsKeyValueEnum = UtsKeyValueMonitor.UtsKeyValueEnum.None
|
||||
If [Enum].TryParse(key, tmp) Then
|
||||
UtsKeyValueMonitor.UtsKeyValue = tmp
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub IdleFunction()
|
||||
If ControllerComPortStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.Connected Then
|
||||
'有测试命令需要下发
|
||||
If ControllerCommandStatus = TestCommandStatusEnum.WaitingToSend Then
|
||||
_stateMachineTaskStatus = StateMachineStatus.SendCommand
|
||||
Return
|
||||
End If
|
||||
|
||||
'收到按键状态命令,需要回复ACK
|
||||
If WaitReplyKeyStatusAck = True Then
|
||||
WaitReplyKeyStatusAck = False
|
||||
_stateMachineTaskStatus = StateMachineStatus.ReplyKeyStatusAck
|
||||
Return
|
||||
End If
|
||||
|
||||
'测试状态变化,需要发送状态变化指令
|
||||
If TestStatusChanged = True Then
|
||||
TestStatusChanged = False
|
||||
_stateMachineTaskStatus = StateMachineStatus.SendHearBeat
|
||||
Return
|
||||
End If
|
||||
|
||||
'定期发送Sync命令
|
||||
Static span As TimeSpan
|
||||
span = Now - SendSyncTime
|
||||
If span.TotalMilliseconds >= SendSyncInterval Then
|
||||
_stateMachineTaskStatus = StateMachineStatus.SendHearBeat '发送同步命令
|
||||
Return
|
||||
End If
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.GetComport '获取设备
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub GetComPortFunction()
|
||||
ControllerComPortStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.Connecting
|
||||
|
||||
If ComportNames.Count > 0 Then
|
||||
Dim comportName As String = ComportNames.Dequeue()
|
||||
|
||||
'避免重复打开测试设备的串口号
|
||||
If ComportStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.Connected Then
|
||||
If String.Compare(UtsComportTask.Conn.ComportName, comportName) = 0 Then
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
Return
|
||||
End If
|
||||
End If
|
||||
|
||||
If Conn.OpenSerialPort(comportName, ComportBaudRate) = False Then
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
Return
|
||||
End If
|
||||
|
||||
'发送询问包
|
||||
Dim sendData As New ControllerComPortData("*IDN?")
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
ComportWriteFailCount = 0
|
||||
WaitReplyStartTime = Now
|
||||
_stateMachineTaskStatus = StateMachineStatus.WaitReply
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
Else
|
||||
For Each comportName As String In UtsComPort.GetPortNames()
|
||||
ComportNames.Enqueue(comportName) '添加可用串口列表
|
||||
Next
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub SendHearBeat()
|
||||
Dim str As String = Choose(TestStatusMonitor.TestStatus + 1, "IDEL", "TESTING", "PASS", "FAIL").ToString()
|
||||
Dim sendData As New ControllerComPortData("TEST_STATUS", str)
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
ComportWriteFailCount = 0
|
||||
SendSyncTime = Now '有数据通讯,发送同步命令时间更新
|
||||
|
||||
WaitReplyStartTime = Now
|
||||
_stateMachineTaskStatus = StateMachineStatus.WaitReply
|
||||
Else
|
||||
ComportWriteFailCount += 1
|
||||
If ComportWriteFailCount >= ComportWriteMaxFailCount Then
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.ComportDisconnected
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub WaitReply()
|
||||
Dim timeout As Integer
|
||||
If ControllerCommandStatus = TestCommandStatusEnum.WaitingToReceive Then
|
||||
timeout = TestWaitReplyMaxTime
|
||||
Else
|
||||
timeout = NormalWaitReplyMaxTime
|
||||
End If
|
||||
|
||||
Dim span As TimeSpan = Now - WaitReplyStartTime
|
||||
If span.TotalMilliseconds > timeout Then '超时
|
||||
If ControllerCommandStatus = TestCommandStatusEnum.WaitingToReceive Then
|
||||
ControllerCommandStatus = TestCommandStatusEnum.ReceiveTimeout '测试命令接收超时
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
Else
|
||||
If ControllerComPortStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.Connected Then
|
||||
ComportWriteFailCount += 1
|
||||
If ComportWriteFailCount >= ComportWriteMaxFailCount Then '超过写入失败上限
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.ComportDisconnected
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
If Conn.CacheData.Count > 0 Then
|
||||
'等待回复的期望值检测
|
||||
Dim receivedData As ControllerComPortData = Conn.CacheData.Dequeue() '接收数据
|
||||
|
||||
Select Case receivedData.Command
|
||||
Case "AUTS J_Controller V1.0" '回复查询串口包
|
||||
_stateMachineTaskStatus = StateMachineStatus.ComportConnected
|
||||
Case "TRUE" '回复心跳包或其他命令
|
||||
ControllerCommandStatus = TestCommandStatusEnum.ReceiveCompleted
|
||||
TestReceiveData = receivedData
|
||||
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End Select
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub SendCommand()
|
||||
Dim sendData As ControllerComPortData = TestSendData
|
||||
If sendData Is Nothing Then
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
Return
|
||||
End If
|
||||
|
||||
'todo:发送命令仍有问题,还需添加重发机制
|
||||
ExpectReplyTestCommand = sendData.Command '期望回复的命令
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
ComportWriteFailCount = 0
|
||||
WaitReplyStartTime = Now '更新等待接收的起始时间
|
||||
TestCommandStatus = TestCommandStatusEnum.WaitingToReceive '等待接收
|
||||
_stateMachineTaskStatus = StateMachineStatus.WaitReply
|
||||
Else
|
||||
TestCommandStatus = TestCommandStatusEnum.SendingFailure '发送失败
|
||||
|
||||
ComportWriteFailCount += 1
|
||||
If ComportWriteFailCount >= ComportWriteMaxFailCount Then
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.ComportDisconnected
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub ReplyKeyStatusAck()
|
||||
Dim sendData As New ControllerComPortData("TRUE")
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
Else
|
||||
ComportWriteFailCount += 1
|
||||
If ComportWriteFailCount >= ComportWriteMaxFailCount Then
|
||||
ComportWriteFailCount = 0
|
||||
_stateMachineTaskStatus = StateMachineStatus.ComportDisconnected
|
||||
Else
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Sub ComportConnected()
|
||||
ControllerComPortStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.Connected
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End Sub
|
||||
|
||||
Public Sub ComportDisconnected()
|
||||
ControllerComPortStatusMonitor.ComportStatus = ComportStatusMonitor.ComPortConnectStatusEnum.UnConnected
|
||||
_stateMachineTaskStatus = StateMachineStatus.Idle
|
||||
End Sub
|
||||
|
||||
|
||||
Enum StateMachineStatus
|
||||
''' <summary>
|
||||
''' 退出状态机
|
||||
''' </summary>
|
||||
Quit
|
||||
|
||||
''' <summary>
|
||||
''' 入口
|
||||
''' </summary>
|
||||
Idle
|
||||
|
||||
''' <summary>
|
||||
''' 获取串口设备
|
||||
''' </summary>
|
||||
GetComport
|
||||
|
||||
''' <summary>
|
||||
''' 发送心跳包
|
||||
''' </summary>
|
||||
SendHearBeat
|
||||
|
||||
''' <summary>
|
||||
''' 等待回复
|
||||
''' </summary>
|
||||
WaitReply
|
||||
|
||||
''' <summary>
|
||||
''' 发送控制通道命令
|
||||
''' </summary>
|
||||
SendCommand
|
||||
|
||||
''' <summary>
|
||||
''' 键值回复
|
||||
''' </summary>
|
||||
ReplyKeyStatusAck
|
||||
|
||||
''' <summary>
|
||||
''' 连接成功
|
||||
''' </summary>
|
||||
ComportConnected
|
||||
|
||||
''' <summary>
|
||||
''' 连接失败
|
||||
''' </summary>
|
||||
ComportDisconnected
|
||||
End Enum
|
||||
#End Region
|
||||
|
||||
|
||||
|
||||
Public Class ControllerComPort
|
||||
''' <summary>通讯串口</summary>
|
||||
Private ReadOnly Property Comport As SerialPort
|
||||
|
||||
''' <summary>接收到的字符串</summary>
|
||||
Private ReadOnly _receiveString As New StringBuilder
|
||||
|
||||
''' <summary>接收到的经过处理后的合法数据队列</summary>
|
||||
Public CacheData As New Queue(Of ControllerComPortData)
|
||||
|
||||
''' <summary>接收起始时间</summary>
|
||||
Private _receiveStartTime As DateTime
|
||||
|
||||
Sub New()
|
||||
Comport = New SerialPort()
|
||||
|
||||
AddHandler Comport.DataReceived, AddressOf ComPort_DataReceived
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 打开串口
|
||||
''' </summary>
|
||||
''' <param name="portName"></param>
|
||||
''' <param name="baudRate"></param>
|
||||
Public Function OpenSerialPort(portName As String, baudRate As Integer) As Boolean
|
||||
|
||||
Try
|
||||
If Comport.IsOpen Then Comport.Close()
|
||||
With Comport
|
||||
.PortName = portName '串口名
|
||||
.BaudRate = baudRate '波特率
|
||||
.DataBits = 8 '数据位
|
||||
.StopBits = StopBits.One '停止位
|
||||
.Parity = Parity.None '偶校验
|
||||
.RtsEnable = True
|
||||
.Open()
|
||||
End With
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"打开控制串口失败!原因:{ex.Message}。")
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function CloseSerialPort() As Boolean
|
||||
If Comport Is Nothing Then Return True
|
||||
Try
|
||||
Comport.Close()
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
Private Function DealReceivedData(receiveBuffer() As Byte) As Boolean
|
||||
If receiveBuffer.Length <= 0 Then Return True
|
||||
If receiveBuffer(receiveBuffer.Length - 1) = 10 Then '接收到换行符,接收完成
|
||||
|
||||
_receiveString.Append(Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length))
|
||||
|
||||
Dim tmpString() As String = _receiveString.ToString().Replace(ControlChars.Cr, String.Empty).Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
|
||||
|
||||
For Each str As String In tmpString
|
||||
Try
|
||||
CacheData.Enqueue(ControllerComPortData.ConvertFromString(str))
|
||||
|
||||
If CacheData.Count > 64 Then CacheData.Dequeue() '缓存数据队列过多,移除头部缓存
|
||||
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"ControllerPort ConvertString Error,String:{str} Error:{ex.Message}")
|
||||
End Try
|
||||
Next
|
||||
|
||||
_receiveString.Clear() '处理完成清空缓存
|
||||
Else
|
||||
If _receiveString.Length = 0 Then '单包未接收完全,记录起始时间
|
||||
_receiveStartTime = Now
|
||||
End If
|
||||
|
||||
_receiveString.Append(Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length))
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Function ReceiveData() As Byte()
|
||||
Static bytes As Integer = 0
|
||||
Try
|
||||
bytes = Comport.BytesToRead
|
||||
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"Controler BytesToRead Error:{ex.Message}")
|
||||
Return New Byte() {}
|
||||
End Try
|
||||
|
||||
Dim receiveBuffer(bytes - 1) As Byte
|
||||
Try
|
||||
Comport.Read(receiveBuffer, 0, bytes)
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"Controler ReceiveData Error:{ex.Message}")
|
||||
Return New Byte() {}
|
||||
End Try
|
||||
|
||||
Return receiveBuffer
|
||||
End Function
|
||||
|
||||
Private Sub ComPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
|
||||
Dim receiveBuffer() As Byte = ReceiveData()
|
||||
|
||||
DealReceivedData(receiveBuffer)
|
||||
End Sub
|
||||
|
||||
|
||||
Public Function SendText(sendString As String) As Boolean
|
||||
Try
|
||||
Comport.Write(sendString)
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"Controller SendString Error,原因:{ex.Message}")
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendTextAppendCrLf(sendData As ControllerComPortData) As Boolean
|
||||
If sendData Is Nothing Then Throw New Exception($"Controller SendTest:SendData Is Nothing")
|
||||
|
||||
Return SendText($"{sendData}{vbCrLf}")
|
||||
End Function
|
||||
|
||||
Public Function SendTextAppendCrLf(command As String, params As List(Of String)) As Boolean
|
||||
Return SendText($"{ControllerComPortData.ConvertToString(command, params)}{vbCrLf}")
|
||||
End Function
|
||||
End Class
|
||||
|
||||
|
||||
Public Class ControllerComPortData
|
||||
''' <summary>通讯字符串的分隔符</summary>
|
||||
Private Shared _separator As Char = ":"c
|
||||
|
||||
''' <summary>
|
||||
''' UTS通讯命令
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property Command() As String
|
||||
''' <summary>
|
||||
''' UTS命令参数
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property Params() As List(Of String)
|
||||
|
||||
|
||||
Sub New()
|
||||
Command = String.Empty
|
||||
Params = New List(Of String)
|
||||
End Sub
|
||||
|
||||
Sub New(cmd As String)
|
||||
Command = cmd
|
||||
Params = New List(Of String)
|
||||
End Sub
|
||||
|
||||
Sub New(cmd As String, param As String)
|
||||
Command = cmd
|
||||
Params = New List(Of String) From {param}
|
||||
End Sub
|
||||
|
||||
Public Shared Function ConvertToString(cmd As String, params As List(Of String)) As String
|
||||
Dim strTemp As New StringBuilder
|
||||
strTemp.Append(cmd)
|
||||
|
||||
For Each param As String In params
|
||||
strTemp.Append(_separator)
|
||||
strTemp.Append(param)
|
||||
Next
|
||||
|
||||
Return strTemp.ToString()
|
||||
End Function
|
||||
|
||||
Public Shared Function ConvertFromString(str As String) As ControllerComPortData
|
||||
If String.IsNullOrWhiteSpace(str) Then Throw New Exception($"ControllerComPort ConvertFromString Invalid String!")
|
||||
|
||||
Dim strings() As String = str.Split(_separator)
|
||||
Dim result As New ControllerComPortData
|
||||
result.Command = strings(0)
|
||||
|
||||
result.Params.Clear()
|
||||
For i As Integer = 1 To strings.Length - 1
|
||||
result.Params.Add(strings(i))
|
||||
Next
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 将参数字符串处理成参数列表
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringToParamList(paramString As String) As List(Of String)
|
||||
Dim strings() As String = paramString.Split(_separator)
|
||||
Return New List(Of String)(strings)
|
||||
End Function
|
||||
|
||||
Public Overrides Function ToString() As String
|
||||
Return ConvertToString(Command, Params)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
119
UTS_Core/UTSModule/Test/Controls/UtsInputBox.Designer.vb
generated
Normal file
119
UTS_Core/UTSModule/Test/Controls/UtsInputBox.Designer.vb
generated
Normal file
@@ -0,0 +1,119 @@
|
||||
|
||||
Namespace UTSModule.Test.Controls
|
||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||
Partial Class UtsInputBox
|
||||
Inherits System.Windows.Forms.Form
|
||||
|
||||
'Form 重写 Dispose,以清理组件列表。
|
||||
<System.Diagnostics.DebuggerNonUserCode()>
|
||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||
Try
|
||||
If disposing AndAlso components IsNot Nothing Then
|
||||
components.Dispose()
|
||||
End If
|
||||
Finally
|
||||
MyBase.Dispose(disposing)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'Windows 窗体设计器所必需的
|
||||
Private components As System.ComponentModel.IContainer
|
||||
|
||||
'注意: 以下过程是 Windows 窗体设计器所必需的
|
||||
'可以使用 Windows 窗体设计器修改它。
|
||||
'不要使用代码编辑器修改它。
|
||||
<System.Diagnostics.DebuggerStepThrough()>
|
||||
Private Sub InitializeComponent()
|
||||
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
|
||||
Me.BtnOk = New System.Windows.Forms.Button()
|
||||
Me.BtnCencle = New System.Windows.Forms.Button()
|
||||
Me.TxtInputText = New System.Windows.Forms.TextBox()
|
||||
Me.LblTip = New System.Windows.Forms.Label()
|
||||
Me.TableLayoutPanel1.SuspendLayout
|
||||
Me.SuspendLayout
|
||||
'
|
||||
'TableLayoutPanel1
|
||||
'
|
||||
Me.TableLayoutPanel1.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Right),System.Windows.Forms.AnchorStyles)
|
||||
Me.TableLayoutPanel1.ColumnCount = 2
|
||||
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50!))
|
||||
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50!))
|
||||
Me.TableLayoutPanel1.Controls.Add(Me.BtnOk, 0, 0)
|
||||
Me.TableLayoutPanel1.Controls.Add(Me.BtnCencle, 1, 0)
|
||||
Me.TableLayoutPanel1.Location = New System.Drawing.Point(277, 122)
|
||||
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
|
||||
Me.TableLayoutPanel1.RowCount = 1
|
||||
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50!))
|
||||
Me.TableLayoutPanel1.Size = New System.Drawing.Size(146, 27)
|
||||
Me.TableLayoutPanel1.TabIndex = 0
|
||||
'
|
||||
'BtnOk
|
||||
'
|
||||
Me.BtnOk.Anchor = System.Windows.Forms.AnchorStyles.None
|
||||
Me.BtnOk.Location = New System.Drawing.Point(3, 3)
|
||||
Me.BtnOk.Name = "BtnOk"
|
||||
Me.BtnOk.Size = New System.Drawing.Size(67, 21)
|
||||
Me.BtnOk.TabIndex = 0
|
||||
Me.BtnOk.Text = "确定"
|
||||
'
|
||||
'BtnCencle
|
||||
'
|
||||
Me.BtnCencle.Anchor = System.Windows.Forms.AnchorStyles.None
|
||||
Me.BtnCencle.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.BtnCencle.Location = New System.Drawing.Point(76, 3)
|
||||
Me.BtnCencle.Name = "BtnCencle"
|
||||
Me.BtnCencle.Size = New System.Drawing.Size(67, 21)
|
||||
Me.BtnCencle.TabIndex = 1
|
||||
Me.BtnCencle.Text = "取消"
|
||||
'
|
||||
'TxtInputText
|
||||
'
|
||||
Me.TxtInputText.CharacterCasing = System.Windows.Forms.CharacterCasing.Upper
|
||||
Me.TxtInputText.Font = New System.Drawing.Font("宋体", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
|
||||
Me.TxtInputText.ImeMode = System.Windows.Forms.ImeMode.Disable
|
||||
Me.TxtInputText.Location = New System.Drawing.Point(12, 90)
|
||||
Me.TxtInputText.Name = "TxtInputText"
|
||||
Me.TxtInputText.Size = New System.Drawing.Size(411, 26)
|
||||
Me.TxtInputText.TabIndex = 1
|
||||
'
|
||||
'LblTip
|
||||
'
|
||||
Me.LblTip.AutoEllipsis = true
|
||||
Me.LblTip.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134,Byte))
|
||||
Me.LblTip.Location = New System.Drawing.Point(12, 9)
|
||||
Me.LblTip.Name = "LblTip"
|
||||
Me.LblTip.Size = New System.Drawing.Size(408, 78)
|
||||
Me.LblTip.TabIndex = 2
|
||||
Me.LblTip.Text = "Label1"
|
||||
Me.LblTip.TextAlign = System.Drawing.ContentAlignment.BottomLeft
|
||||
'
|
||||
'UtsInputBox
|
||||
'
|
||||
Me.AcceptButton = Me.BtnOk
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 12!)
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.CancelButton = Me.BtnCencle
|
||||
Me.ClientSize = New System.Drawing.Size(435, 160)
|
||||
Me.Controls.Add(Me.LblTip)
|
||||
Me.Controls.Add(Me.TxtInputText)
|
||||
Me.Controls.Add(Me.TableLayoutPanel1)
|
||||
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
|
||||
Me.MaximizeBox = false
|
||||
Me.MinimizeBox = false
|
||||
Me.Name = "UtsInputBox"
|
||||
Me.ShowInTaskbar = false
|
||||
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
|
||||
Me.Text = "UtsInputBox"
|
||||
Me.TopMost = true
|
||||
Me.TableLayoutPanel1.ResumeLayout(false)
|
||||
Me.ResumeLayout(false)
|
||||
Me.PerformLayout
|
||||
|
||||
End Sub
|
||||
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
|
||||
Friend WithEvents BtnOk As System.Windows.Forms.Button
|
||||
Friend WithEvents BtnCencle As System.Windows.Forms.Button
|
||||
Friend WithEvents TxtInputText As Windows.Forms.TextBox
|
||||
Friend WithEvents LblTip As Windows.Forms.Label
|
||||
End Class
|
||||
End Namespace
|
||||
120
UTS_Core/UTSModule/Test/Controls/UtsInputBox.resx
Normal file
120
UTS_Core/UTSModule/Test/Controls/UtsInputBox.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
121
UTS_Core/UTSModule/Test/Controls/UtsInputBox.vb
Normal file
121
UTS_Core/UTSModule/Test/Controls/UtsInputBox.vb
Normal file
@@ -0,0 +1,121 @@
|
||||
Imports System.Threading
|
||||
Imports System.Windows.Forms
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.UtsKeyValueMonitor
|
||||
|
||||
Namespace UTSModule.Test.Controls
|
||||
Public Class UtsInputBox
|
||||
|
||||
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOk.Click
|
||||
InputText = TxtInputText.Text
|
||||
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCencle.Click
|
||||
InputText = Nothing
|
||||
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
Private _isPwd As Boolean = False
|
||||
|
||||
Public Property TipText As String
|
||||
Public Property Title As String
|
||||
Public Property DefaultText As String
|
||||
|
||||
''' <summary>
|
||||
''' 输入框值
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property InputText() As String
|
||||
|
||||
''' <summary>
|
||||
''' 密码模式
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property IsPassWord As Boolean
|
||||
Get
|
||||
Return _isPwd
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
_isPwd = value
|
||||
If _isPwd Then
|
||||
TxtInputText.PasswordChar = "*"c
|
||||
Else
|
||||
TxtInputText.PasswordChar = ControlChars.NullChar
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Overloads Shared Function ShowDialog(tip As String, Optional title As String = "", Optional text As String = "", Optional isPwd As Boolean = False) As String
|
||||
|
||||
Using box As New UtsInputBox
|
||||
box.TopLevel = True
|
||||
box.TipText = tip
|
||||
box.Title = title
|
||||
box.DefaultText = text
|
||||
box.IsPassWord = isPwd
|
||||
box.ShowDialog()
|
||||
Return box.InputText
|
||||
End Using
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub UpdateKey(key As UtsKeyValueEnum)
|
||||
Try
|
||||
If BtnOk.InvokeRequired Then
|
||||
BtnOk.Invoke(New Action(Of UtsKeyValueEnum)(AddressOf UpdateKey), New Object() {key})
|
||||
Return
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Return
|
||||
End Try
|
||||
|
||||
If key = UtsKeyValueEnum.Yes Then
|
||||
InputText = TxtInputText.Text
|
||||
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
||||
Me.Close()
|
||||
ElseIf key = UtsKeyValueEnum.No Then
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.Close()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub UtsInputBox_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
||||
Text = Title
|
||||
LblTip.Text = TipText
|
||||
If _isPwd Then
|
||||
TxtInputText.PasswordChar = "*"c
|
||||
Else
|
||||
TxtInputText.PasswordChar = ControlChars.NullChar
|
||||
End If
|
||||
TxtInputText.Text = DefaultText
|
||||
TxtInputText.Focus()
|
||||
TxtInputText.SelectAll()
|
||||
|
||||
AcceptButton = BtnOk
|
||||
CancelButton = BtnCencle
|
||||
|
||||
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf CheckKeyValue))
|
||||
End Sub
|
||||
|
||||
Sub CheckKeyValue(obj As Object)
|
||||
While DialogResult = DialogResult.None
|
||||
UpdateKey(UtsKeyValue)
|
||||
System.Windows.Forms.Application.DoEvents()
|
||||
Thread.Sleep(50)
|
||||
End While
|
||||
End Sub
|
||||
|
||||
Private Sub UtsInputBox_KeyDown(sender As Object, e As Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
|
||||
If e.KeyCode = Keys.Enter Then
|
||||
BtnOk.PerformClick()
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
86
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.Designer.vb
generated
Normal file
86
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.Designer.vb
generated
Normal file
@@ -0,0 +1,86 @@
|
||||
|
||||
Namespace UTSModule.Test.Controls
|
||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||
Partial Class UtsMsgBox
|
||||
Inherits System.Windows.Forms.Form
|
||||
|
||||
'Form 重写 Dispose,以清理组件列表。
|
||||
<System.Diagnostics.DebuggerNonUserCode()>
|
||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||
Try
|
||||
If disposing AndAlso components IsNot Nothing Then
|
||||
components.Dispose()
|
||||
End If
|
||||
Finally
|
||||
MyBase.Dispose(disposing)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'Windows 窗体设计器所必需的
|
||||
Private components As System.ComponentModel.IContainer
|
||||
|
||||
'注意: 以下过程是 Windows 窗体设计器所必需的
|
||||
'可以使用 Windows 窗体设计器修改它。
|
||||
'不要使用代码编辑器修改它。
|
||||
<System.Diagnostics.DebuggerStepThrough()>
|
||||
Private Sub InitializeComponent()
|
||||
Me.BtnYes = New System.Windows.Forms.Button()
|
||||
Me.BtnNo = New System.Windows.Forms.Button()
|
||||
Me.LblTipText = New System.Windows.Forms.Label()
|
||||
Me.SuspendLayout
|
||||
'
|
||||
'BtnYes
|
||||
'
|
||||
Me.BtnYes.Anchor = System.Windows.Forms.AnchorStyles.None
|
||||
Me.BtnYes.Location = New System.Drawing.Point(252, 120)
|
||||
Me.BtnYes.Name = "BtnYes"
|
||||
Me.BtnYes.Size = New System.Drawing.Size(67, 21)
|
||||
Me.BtnYes.TabIndex = 0
|
||||
Me.BtnYes.Text = "确定"
|
||||
'
|
||||
'BtnNo
|
||||
'
|
||||
Me.BtnNo.Anchor = System.Windows.Forms.AnchorStyles.None
|
||||
Me.BtnNo.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.BtnNo.Location = New System.Drawing.Point(325, 120)
|
||||
Me.BtnNo.Name = "BtnNo"
|
||||
Me.BtnNo.Size = New System.Drawing.Size(67, 21)
|
||||
Me.BtnNo.TabIndex = 1
|
||||
Me.BtnNo.Text = "取消"
|
||||
'
|
||||
'LblTipText
|
||||
'
|
||||
Me.LblTipText.AutoEllipsis = true
|
||||
Me.LblTipText.Font = New System.Drawing.Font("宋体", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(134,Byte))
|
||||
Me.LblTipText.Location = New System.Drawing.Point(31, 22)
|
||||
Me.LblTipText.Name = "LblTipText"
|
||||
Me.LblTipText.Size = New System.Drawing.Size(361, 82)
|
||||
Me.LblTipText.TabIndex = 1
|
||||
Me.LblTipText.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
|
||||
'
|
||||
'UtsMsgBox
|
||||
'
|
||||
Me.AcceptButton = Me.BtnYes
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 12!)
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.CancelButton = Me.BtnNo
|
||||
Me.ClientSize = New System.Drawing.Size(426, 153)
|
||||
Me.Controls.Add(Me.BtnNo)
|
||||
Me.Controls.Add(Me.BtnYes)
|
||||
Me.Controls.Add(Me.LblTipText)
|
||||
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
|
||||
Me.MaximizeBox = false
|
||||
Me.MinimizeBox = false
|
||||
Me.Name = "UtsMsgBox"
|
||||
Me.ShowInTaskbar = false
|
||||
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent
|
||||
Me.Text = "UtsMsgBox"
|
||||
Me.TopMost = true
|
||||
Me.ResumeLayout(false)
|
||||
|
||||
End Sub
|
||||
Friend WithEvents BtnYes As System.Windows.Forms.Button
|
||||
Friend WithEvents BtnNo As System.Windows.Forms.Button
|
||||
Friend WithEvents LblTipText As Windows.Forms.Label
|
||||
End Class
|
||||
End Namespace
|
||||
120
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.resx
Normal file
120
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
92
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.vb
Normal file
92
UTS_Core/UTSModule/Test/Controls/UtsMsgBox.vb
Normal file
@@ -0,0 +1,92 @@
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.UtsKeyValueMonitor
|
||||
|
||||
Namespace UTSModule.Test.Controls
|
||||
Public Class UtsMsgBox
|
||||
Enum UtsMsgBoxTypeEnum
|
||||
OkOnly = 0
|
||||
YesNo = 4
|
||||
End Enum
|
||||
|
||||
|
||||
Public Property MsgType() As UtsMsgBoxTypeEnum
|
||||
Public Property MsgText() As String
|
||||
Public Property MsgTitle() As String
|
||||
|
||||
|
||||
Public Overloads Shared Function ShowDialog(text As String, Optional type As UtsMsgBoxTypeEnum = UtsMsgBoxTypeEnum.OkOnly, Optional title As String = "") As System.Windows.Forms.DialogResult
|
||||
|
||||
Using msg As New UtsMsgBox
|
||||
msg.TopLevel = True
|
||||
msg.MsgText = text
|
||||
msg.MsgType = type
|
||||
msg.MsgTitle = title
|
||||
|
||||
Return msg.ShowDialog()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnYes.Click
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNo.Click
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.Close()
|
||||
End Sub
|
||||
|
||||
Private Sub UtsMsgBox_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
||||
Text = MsgTitle
|
||||
LblTipText.Text = MsgText
|
||||
|
||||
|
||||
|
||||
If MsgType = UtsMsgBoxTypeEnum.OkOnly Then
|
||||
AcceptButton = BtnYes
|
||||
BtnNo.Visible = False
|
||||
BtnYes.Text = $"确定"
|
||||
BtnYes.Width += BtnNo.Width
|
||||
|
||||
ElseIf MsgType = UtsMsgBoxTypeEnum.YesNo Then
|
||||
AcceptButton = BtnYes
|
||||
CancelButton = BtnNo
|
||||
|
||||
BtnYes.Text = $"是"
|
||||
BtnNo.Text = $"否"
|
||||
End If
|
||||
|
||||
AddHandler StatusMonitor.UtsKeyValueMonitor.UtsKeyDown, AddressOf UtsKeyDownCallback
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub UtsKeyDownCallback(sender As Object, e As StatusMonitor.UtsKeyDownEventArgs)
|
||||
If BtnYes.InvokeRequired Then
|
||||
BtnYes.Invoke(New Action(Of StatusMonitor.UtsKeyValueMonitor.UtsKeyValueEnum)(AddressOf UpdateKey), New Object() {e.KeyValue})
|
||||
Else
|
||||
UpdateKey(e.KeyValue)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub UpdateKey(key As UtsKeyValueEnum)
|
||||
Try
|
||||
If BtnYes.InvokeRequired Then
|
||||
BtnYes.Invoke(New Action(Of UtsKeyValueEnum)(AddressOf UpdateKey), New Object() {key})
|
||||
Return
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
Return
|
||||
End Try
|
||||
|
||||
If key = UtsKeyValueEnum.Yes Then
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.OK
|
||||
Me.Close()
|
||||
ElseIf key = UtsKeyValueEnum.No Then
|
||||
If MsgType = UtsMsgBoxTypeEnum.YesNo Then
|
||||
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
|
||||
Me.Close()
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
255
UTS_Core/UTSModule/Test/Controls/utsLabel.Designer.vb
generated
Normal file
255
UTS_Core/UTSModule/Test/Controls/utsLabel.Designer.vb
generated
Normal file
@@ -0,0 +1,255 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Threading
|
||||
Imports System.Runtime.InteropServices
|
||||
Imports System.Windows.Forms
|
||||
|
||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||
Public Class utsLabel
|
||||
'Inherits System.Windows.Forms.UserControl
|
||||
Inherits System.Windows.Forms.Label
|
||||
|
||||
'UserControl 重写释放以清理组件列表。
|
||||
<System.Diagnostics.DebuggerNonUserCode()>
|
||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||
Try
|
||||
If disposing AndAlso components IsNot Nothing Then
|
||||
components.Dispose()
|
||||
End If
|
||||
|
||||
Finally
|
||||
MyBase.Dispose(disposing)
|
||||
End Try
|
||||
|
||||
If myThread IsNot Nothing AndAlso myThread.IsAlive Then
|
||||
'关闭线程
|
||||
myThread.Abort()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
'Windows 窗体设计器所必需的
|
||||
Private components As System.ComponentModel.IContainer
|
||||
|
||||
Dim myThread As Thread = Nothing '定义一个全局变量存储线程对象
|
||||
|
||||
'注意: 以下过程是 Windows 窗体设计器所必需的
|
||||
'可以使用 Windows 窗体设计器修改它。
|
||||
'不要使用代码编辑器修改它。
|
||||
<System.Diagnostics.DebuggerStepThrough()>
|
||||
Private Sub InitializeComponent()
|
||||
System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = False 'Momo 2023-12-23 禁用跨线程检查,危险,少用
|
||||
|
||||
Me.Label1 = New System.Windows.Forms.Label()
|
||||
Me.SuspendLayout()
|
||||
'
|
||||
'Label1
|
||||
'
|
||||
Me.Label1.AutoSize = True
|
||||
Me.Label1.Location = New System.Drawing.Point(0, 0)
|
||||
Me.Label1.Name = "Label1"
|
||||
Me.Label1.Size = New System.Drawing.Size(100, 23)
|
||||
Me.Label1.TabIndex = 0
|
||||
Me.Label1.Text = "Label1"
|
||||
Me.Label1.TextAlign = ContentAlignment.MiddleLeft
|
||||
Me.ResumeLayout(False)
|
||||
|
||||
If myThread IsNot Nothing AndAlso myThread.IsAlive Then
|
||||
'如果已经有线程正在运行,则先关闭该线程
|
||||
myThread.Abort()
|
||||
End If
|
||||
|
||||
'创建新的线程并开始运行
|
||||
myThread = New Thread(AddressOf dispModeExe)
|
||||
myThread.Start()
|
||||
|
||||
End Sub
|
||||
|
||||
Friend WithEvents Label1 As Windows.Forms.Label
|
||||
|
||||
|
||||
#Region "控件属性"
|
||||
|
||||
Private _dispMode As Integer '显示模式 1-普通,2-闪烁,3-滚动,4-自动增加字符
|
||||
Private _visible As Boolean '是否显示’
|
||||
Private _text As String '显示文本内容’
|
||||
Private _dispFlag As Boolean '闪烁flag’
|
||||
Private _modePara As String '模式参数’
|
||||
|
||||
Private modePara_Timeout_mS As Integer = 0 '闪烁超时’
|
||||
Private color_1 As Color = Color.Red '闪烁颜色1’
|
||||
Private color_2 As Color = Color.White '闪烁颜色2’
|
||||
Private AddCharacter As String = "." '自增字母’
|
||||
Private AddCharMaxLen As Integer = 32 '自增最大长度’
|
||||
Private modeParaArry() As String '参数数组’
|
||||
Private AddCharCnt As Integer = 0 '自增计数’
|
||||
|
||||
|
||||
Public Property modePara As String
|
||||
Get
|
||||
Return _modePara
|
||||
End Get
|
||||
Set(value As String)
|
||||
_modePara = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Public Property dispMode As Integer
|
||||
Get
|
||||
Return _dispMode
|
||||
End Get
|
||||
Set(value As Integer)
|
||||
_dispMode = value
|
||||
RunMode()
|
||||
End Set
|
||||
End Property
|
||||
#End Region
|
||||
|
||||
#Region "控件属性实现"
|
||||
''' <summary>
|
||||
''' 解析模式,并且确定有关参数
|
||||
''' </summary>
|
||||
Private Sub RunMode()
|
||||
If IsNumeric(_dispMode) = False Then Return
|
||||
|
||||
If String.IsNullOrEmpty(_modePara) = True Then
|
||||
Return
|
||||
Else
|
||||
modeParaArry = _modePara.Split(CType(":", Char()))
|
||||
End If
|
||||
|
||||
Dim paraArryCnt As Integer = modeParaArry.Count
|
||||
|
||||
|
||||
Select Case _dispMode
|
||||
Case 1 '默认
|
||||
|
||||
Case 2 '闪烁
|
||||
If paraArryCnt = 3 Then
|
||||
modePara_Timeout_mS = CInt(modeParaArry(0))
|
||||
color_1 = HexStringToColor(modeParaArry(1).Trim)
|
||||
color_2 = HexStringToColor(modeParaArry(2).Trim)
|
||||
Else
|
||||
Return
|
||||
End If
|
||||
|
||||
Case 3 '滚动
|
||||
|
||||
|
||||
Case 4 '自动增加字符
|
||||
If paraArryCnt = 3 Then
|
||||
modePara_Timeout_mS = CInt(modeParaArry(0))
|
||||
AddCharacter = modeParaArry(1).Trim
|
||||
AddCharMaxLen = CInt(modeParaArry(2).Trim)
|
||||
AddCharCnt = 0
|
||||
Else
|
||||
Return
|
||||
End If
|
||||
|
||||
|
||||
Case Else
|
||||
|
||||
End Select
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 常驻线程,执行各种Mode
|
||||
''' </summary>
|
||||
Private Async Sub dispModeExe()
|
||||
While True
|
||||
Await Task.Delay(modePara_Timeout_mS)
|
||||
_dispFlag = Not _dispFlag
|
||||
ModeProcessing()
|
||||
End While
|
||||
End Sub
|
||||
|
||||
Private Sub ModeProcessing()
|
||||
If IsNumeric(_dispMode) = False Then Return
|
||||
|
||||
Select Case _dispMode
|
||||
Case 1 '默认
|
||||
|
||||
Case 2 '闪烁
|
||||
If _dispFlag Then
|
||||
ForeColor = color_1
|
||||
Else
|
||||
ForeColor = color_2
|
||||
End If
|
||||
Case 3 '滚动
|
||||
|
||||
Case 4 '自动增加字符
|
||||
If AddCharCnt < AddCharMaxLen Then
|
||||
AddCharCnt += 1
|
||||
_text = _text & AddCharacter
|
||||
|
||||
MyBase.Text = _text '调用基类的Text属性的setter方法,将处理后的值赋值给基类的Text属性
|
||||
Me.Refresh() ' 在修改Text后调用Refresh方法刷新控件
|
||||
|
||||
'If _dispFlag Then
|
||||
' ForeColor = color_1
|
||||
'Else
|
||||
' ForeColor = color_2
|
||||
'End If
|
||||
End If
|
||||
|
||||
Case Else
|
||||
|
||||
End Select
|
||||
|
||||
End Sub
|
||||
|
||||
Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
|
||||
' 重写OnPaint事件处理程序,这里不需要进行任何操作
|
||||
MyBase.OnPaint(e)
|
||||
End Sub
|
||||
|
||||
Protected Overloads Sub show()
|
||||
MyBase.Show()
|
||||
End Sub
|
||||
|
||||
Public Overrides Property Text As String
|
||||
Get
|
||||
'Return MyBase.Text '返回基类的Text属性值
|
||||
Return _text
|
||||
End Get
|
||||
|
||||
Set(value As String)
|
||||
_text = value
|
||||
MyBase.Text = _text '调用基类的Text属性的setter方法,将处理后的值赋值给基类的Text属性
|
||||
Me.Refresh() ' 在修改Text后调用Refresh方法刷新控件
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
Private Function HexStringToColor(hexString As String) As Color
|
||||
Dim val As Integer = Convert.ToInt32(hexString, 16)
|
||||
Return Color.FromArgb(val >> 16 And &HFF, val >> 8 And &HFF, val And &HFF)
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
|
||||
Public Class TickCounter
|
||||
<DllImport("kernel32.dll")>
|
||||
Private Shared Function GetTickCount() As Integer
|
||||
End Function
|
||||
|
||||
Public Shared _msLast As Long
|
||||
Public Shared ReadOnly Property ElapsedMilliseconds As Long
|
||||
Get
|
||||
Return CLng(GetTickCount())
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Shared Property msLast As Long
|
||||
Get
|
||||
Return _msLast
|
||||
End Get
|
||||
Set(value As Long)
|
||||
_msLast = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
End Class
|
||||
126
UTS_Core/UTSModule/Test/Controls/utsLabel.resx
Normal file
126
UTS_Core/UTSModule/Test/Controls/utsLabel.resx
Normal file
@@ -0,0 +1,126 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="Label1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>False</value>
|
||||
</metadata>
|
||||
</root>
|
||||
13
UTS_Core/UTSModule/Test/Controls/utsLabel.vb
Normal file
13
UTS_Core/UTSModule/Test/Controls/utsLabel.vb
Normal file
@@ -0,0 +1,13 @@
|
||||
Imports System.Threading
|
||||
Imports System.Windows.Forms
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.UtsKeyValueMonitor
|
||||
|
||||
Namespace UTSModule.Test.Controls
|
||||
Public Class utsLabel
|
||||
Inherits Label
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
End Namespace
|
||||
|
||||
21
UTS_Core/UTSModule/Test/DeviceAddress.vb
Normal file
21
UTS_Core/UTSModule/Test/DeviceAddress.vb
Normal file
@@ -0,0 +1,21 @@
|
||||
Namespace UTSModule.Test
|
||||
Public Class DeviceAddress
|
||||
''' <summary>
|
||||
''' PC机地址
|
||||
''' </summary>
|
||||
Public Shared ReadOnly WindowAddress As String = "00"
|
||||
|
||||
''' <summary>
|
||||
''' UtsHW03设备地址
|
||||
''' </summary>
|
||||
Public Shared ReadOnly UtsHw03Address As String = "01"
|
||||
|
||||
''' <summary>
|
||||
''' UTS通讯中,本机地址
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function LocalAddress() As String
|
||||
Return WindowAddress
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
1051
UTS_Core/UTSModule/Test/FrmStationTest.Designer.vb
generated
Normal file
1051
UTS_Core/UTSModule/Test/FrmStationTest.Designer.vb
generated
Normal file
File diff suppressed because it is too large
Load Diff
159
UTS_Core/UTSModule/Test/FrmStationTest.resx
Normal file
159
UTS_Core/UTSModule/Test/FrmStationTest.resx
Normal file
@@ -0,0 +1,159 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="TcPie.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>606, 18</value>
|
||||
</metadata>
|
||||
<data name="resource.CustomPointPos" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0
|
||||
dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh
|
||||
d2luZy5Qb2ludEYCAAAAAXgBeQAACwsCAAAAAAAAAAAAAAAL
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="StuState.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>19, 18</value>
|
||||
</metadata>
|
||||
<metadata name="CmsRecordGrid.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>120, 18</value>
|
||||
</metadata>
|
||||
<metadata name="TcBarPass.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>376, 18</value>
|
||||
</metadata>
|
||||
<data name="resource.CustomPointPos1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0
|
||||
dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh
|
||||
d2luZy5Qb2ludEYCAAAAAXgBeQAACwsCAAAAAAAAAAAAAAAL
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="TcBarFail.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>494, 18</value>
|
||||
</metadata>
|
||||
<data name="resource.CustomPointPos2" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>
|
||||
AAEAAAD/////AQAAAAAAAAAMAgAAAFFTeXN0ZW0uRHJhd2luZywgVmVyc2lvbj00LjAuMC4wLCBDdWx0
|
||||
dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWIwM2Y1ZjdmMTFkNTBhM2EFAQAAABVTeXN0ZW0uRHJh
|
||||
d2luZy5Qb2ludEYCAAAAAXgBeQAACwsCAAAAAAAAAAAAAAAL
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>56</value>
|
||||
</metadata>
|
||||
</root>
|
||||
1114
UTS_Core/UTSModule/Test/FrmStationTest.vb
Normal file
1114
UTS_Core/UTSModule/Test/FrmStationTest.vb
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,72 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
|
||||
Public Class ComportStatusChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Public Property Status As ComportStatusMonitor.ComPortConnectStatusEnum
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
Public Class ComportStatusMonitor
|
||||
Enum ComPortConnectStatusEnum
|
||||
Connected
|
||||
Connecting
|
||||
UnConnected
|
||||
End Enum
|
||||
|
||||
Public Delegate Sub ComportStatusChangedEventHandler(sender As Object, e As ComportStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在测试状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event ComportStatusChanged As ComportStatusChangedEventHandler
|
||||
|
||||
|
||||
Private Shared _comportStatus As ComPortConnectStatusEnum = ComPortConnectStatusEnum.UnConnected
|
||||
|
||||
''' <summary>
|
||||
''' 串口连接状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property ComportStatus() As ComPortConnectStatusEnum
|
||||
Get
|
||||
Return _comportStatus
|
||||
End Get
|
||||
Set(value As ComPortConnectStatusEnum)
|
||||
If _comportStatus = value Then Return
|
||||
_comportStatus = value
|
||||
RaiseEvent ComportStatusChanged(Nothing, New ComportStatusChangedEventArgs() With {.Status = _comportStatus})
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
|
||||
Public Class ControllerComPortStatusMonitor
|
||||
|
||||
Public Delegate Sub ComportStatusChangedEventHandler(sender As Object, e As ComportStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在测试状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event ComportStatusChanged As ComportStatusChangedEventHandler
|
||||
|
||||
|
||||
Private Shared _comportStatus As ComportStatusMonitor.ComPortConnectStatusEnum = ComportStatusMonitor.ComPortConnectStatusEnum.UnConnected
|
||||
|
||||
''' <summary>
|
||||
''' 串口连接状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property ComportStatus() As ComportStatusMonitor.ComPortConnectStatusEnum
|
||||
Get
|
||||
Return _comportStatus
|
||||
End Get
|
||||
Set(value As ComportStatusMonitor.ComPortConnectStatusEnum)
|
||||
If _comportStatus = value Then Return
|
||||
_comportStatus = value
|
||||
RaiseEvent ComportStatusChanged(Nothing, New ComportStatusChangedEventArgs() With {.Status = _comportStatus})
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,49 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
|
||||
Public Class DatabaseStatusChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Sub New(dbStatus As DatabaseStatusMonitor.DatabaseSyncStatusEnum)
|
||||
Status = dbStatus
|
||||
End Sub
|
||||
|
||||
Public Property Status As DatabaseStatusMonitor.DatabaseSyncStatusEnum
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
Public Class DatabaseStatusMonitor
|
||||
|
||||
Enum DatabaseSyncStatusEnum
|
||||
Completed
|
||||
Completing
|
||||
UnCompleted
|
||||
End Enum
|
||||
|
||||
|
||||
Public Delegate Sub DatabaseSyncStatusChangedEventHandler(sender As Object, e As DatabaseStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在数据库同步状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event DatabaseSyncStatusChanged As DatabaseSyncStatusChangedEventHandler
|
||||
|
||||
Private Shared _dbSyncStatus As DatabaseSyncStatusEnum = DatabaseSyncStatusEnum.Completed
|
||||
|
||||
''' <summary>
|
||||
''' 数据库同步状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property DatabaseSyncStatus() As DatabaseSyncStatusEnum
|
||||
Get
|
||||
Return _dbSyncStatus
|
||||
End Get
|
||||
Set(value As DatabaseSyncStatusEnum)
|
||||
If _dbSyncStatus = value Then Return
|
||||
_dbSyncStatus = value
|
||||
RaiseEvent DatabaseSyncStatusChanged(Nothing, New DatabaseStatusChangedEventArgs(_dbSyncStatus))
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,49 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
|
||||
Public Class DatabaseStatusChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Sub New(dbStatus As DatabaseStatusMonitor.DatabaseSyncStatusEnum)
|
||||
Status = dbStatus
|
||||
End Sub
|
||||
|
||||
Public Property Status As DatabaseStatusMonitor.DatabaseSyncStatusEnum
|
||||
|
||||
End Class
|
||||
|
||||
|
||||
Public Class DatabaseStatusMonitor
|
||||
|
||||
Enum DatabaseSyncStatusEnum
|
||||
Unknown
|
||||
UnCompleted
|
||||
Completed
|
||||
End Enum
|
||||
|
||||
|
||||
Public Delegate Sub DatabaseSyncStatusChangedEventHandler(sender As Object, e As DatabaseStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在数据库同步状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event DatabaseSyncStatusChanged As DatabaseSyncStatusChangedEventHandler
|
||||
|
||||
Private Shared _dbSyncStatus As DatabaseSyncStatusEnum = DatabaseSyncStatusEnum.Completed
|
||||
|
||||
''' <summary>
|
||||
''' 数据库同步状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property DatabaseSyncStatus() As DatabaseSyncStatusEnum
|
||||
Get
|
||||
Return _dbSyncStatus
|
||||
End Get
|
||||
Set(value As DatabaseSyncStatusEnum)
|
||||
If _dbSyncStatus = value Then Return
|
||||
_dbSyncStatus = value
|
||||
RaiseEvent DatabaseSyncStatusChanged(Nothing, New DatabaseStatusChangedEventArgs(_dbSyncStatus))
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
@@ -0,0 +1,52 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
|
||||
Public Class StationEditStatusChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Public Property Status As StationEditStatusMonitor.StationEditStatusEnum
|
||||
End Class
|
||||
|
||||
|
||||
Public Class StationEditStatusMonitor
|
||||
Enum StationEditStatusEnum
|
||||
''' <summary>
|
||||
''' 项目站未修改
|
||||
''' </summary>
|
||||
None
|
||||
''' <summary>
|
||||
''' 项目站信息已修改
|
||||
''' </summary>
|
||||
Changed
|
||||
''' <summary>
|
||||
''' 项目站信息修改已保存
|
||||
''' </summary>
|
||||
Saved
|
||||
End Enum
|
||||
|
||||
|
||||
Public Delegate Sub StationEditStatusChangedEventHandler(sender As Object, e As StationEditStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在测试状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event StationEditStatusChanged As StationEditStatusChangedEventHandler
|
||||
|
||||
|
||||
Private Shared _stationEditStatus As StationEditStatusEnum = StationEditStatusEnum.None
|
||||
|
||||
''' <summary>
|
||||
''' 测试站编辑状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property StationEditStatus() As StationEditStatusEnum
|
||||
Get
|
||||
Return _stationEditStatus
|
||||
End Get
|
||||
Set(value As StationEditStatusEnum)
|
||||
If _stationEditStatus = value Then Return
|
||||
_stationEditStatus = value
|
||||
RaiseEvent StationEditStatusChanged(Nothing, New StationEditStatusChangedEventArgs() With {.Status = _stationEditStatus})
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -0,0 +1,47 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
Public Class TestCommandStatusMonitor
|
||||
Enum TestCommandStatusEnum
|
||||
''' <summary>
|
||||
''' 无需发送
|
||||
''' </summary>
|
||||
None
|
||||
|
||||
''' <summary>
|
||||
''' 等待发送
|
||||
''' </summary>
|
||||
WaitingToSend
|
||||
|
||||
''' <summary>
|
||||
''' 发送失败
|
||||
''' </summary>
|
||||
SendingFailure
|
||||
|
||||
''' <summary>
|
||||
''' 发送成功后,等待接收
|
||||
''' </summary>
|
||||
WaitingToReceive
|
||||
|
||||
''' <summary>
|
||||
''' 接收超时
|
||||
''' </summary>
|
||||
ReceiveTimeout
|
||||
|
||||
''' <summary>
|
||||
''' 接收完成
|
||||
''' </summary>
|
||||
ReceiveCompleted
|
||||
End Enum
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property TestCommandStatus() As TestCommandStatusEnum
|
||||
|
||||
''' <summary>
|
||||
''' 控制命令状态
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property ControllerCommandStatus() As TestCommandStatusEnum
|
||||
End Class
|
||||
End Namespace
|
||||
62
UTS_Core/UTSModule/Test/StatusMonitor/TestStatusMonitor.vb
Normal file
62
UTS_Core/UTSModule/Test/StatusMonitor/TestStatusMonitor.vb
Normal file
@@ -0,0 +1,62 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
Public Class TestStatusChangedEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Sub New(status As TestStatusMonitor.TestStatusEnum)
|
||||
Me.Status = status
|
||||
End Sub
|
||||
|
||||
Public Property Status As TestStatusMonitor.TestStatusEnum
|
||||
End Class
|
||||
|
||||
|
||||
Public Class TestStatusMonitor
|
||||
Enum TestStatusEnum
|
||||
''' <summary>
|
||||
''' 待机测试
|
||||
''' </summary>
|
||||
WaitForTest
|
||||
''' <summary>
|
||||
''' 正在测试中
|
||||
''' </summary>
|
||||
Testing
|
||||
''' <summary>
|
||||
''' 测试通过
|
||||
''' </summary>
|
||||
TestPass
|
||||
''' <summary>
|
||||
''' 测试失败
|
||||
''' </summary>
|
||||
TestFail
|
||||
''' <summary>
|
||||
''' 设备异常
|
||||
''' </summary>
|
||||
DeviceError
|
||||
End Enum
|
||||
|
||||
Public Delegate Sub TestStatusChangedEventHandler(sender As Object, e As TestStatusChangedEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' 在测试状态更改时发生
|
||||
''' </summary>
|
||||
Public Shared Event TestStatusChanged As TestStatusChangedEventHandler
|
||||
|
||||
|
||||
Private Shared _testStatus As TestStatusEnum = TestStatusEnum.WaitForTest
|
||||
|
||||
''' <summary>
|
||||
''' 测试状态
|
||||
''' </summary>
|
||||
''' <returns>测试状态</returns>
|
||||
Public Shared Property TestStatus() As TestStatusEnum
|
||||
Get
|
||||
Return _testStatus
|
||||
End Get
|
||||
Set(value As TestStatusEnum)
|
||||
If _testStatus = value Then Return
|
||||
_testStatus = value
|
||||
RaiseEvent TestStatusChanged(Nothing, New TestStatusChangedEventArgs(_testStatus))
|
||||
End Set
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
90
UTS_Core/UTSModule/Test/StatusMonitor/UtsKeyDownMonitor.vb
Normal file
90
UTS_Core/UTSModule/Test/StatusMonitor/UtsKeyDownMonitor.vb
Normal file
@@ -0,0 +1,90 @@
|
||||
Namespace UTSModule.Test.StatusMonitor
|
||||
Public Class UtsKeyDownEventArgs
|
||||
Inherits EventArgs
|
||||
|
||||
Public Property KeyValue As UtsKeyValueMonitor.UtsKeyValueEnum
|
||||
End Class
|
||||
|
||||
|
||||
Public Class UtsKeyValueMonitor
|
||||
''' <summary>
|
||||
''' 按键按下枚举值
|
||||
''' </summary>
|
||||
Enum UtsKeyValueEnum
|
||||
''' <summary>
|
||||
''' 没有按键按下
|
||||
''' </summary>
|
||||
None = 1
|
||||
''' <summary>
|
||||
''' 开始键按下
|
||||
''' </summary>
|
||||
Start
|
||||
''' <summary>
|
||||
''' YES 键按下
|
||||
''' </summary>
|
||||
Yes
|
||||
''' <summary>
|
||||
''' NO 键按下
|
||||
''' </summary>
|
||||
No
|
||||
|
||||
''' <summary>
|
||||
''' 开始键长按
|
||||
''' </summary>
|
||||
StartLongPress
|
||||
|
||||
''' <summary>
|
||||
''' YES 键长按
|
||||
''' </summary>
|
||||
YesLongPress
|
||||
|
||||
''' <summary>
|
||||
''' NO 键长按
|
||||
''' </summary>
|
||||
NoLongPress
|
||||
|
||||
''' <summary>
|
||||
''' 开始键松开
|
||||
''' </summary>
|
||||
StartReleased
|
||||
|
||||
''' <summary>
|
||||
''' Yes 键松开
|
||||
''' </summary>
|
||||
YesReleased
|
||||
|
||||
''' <summary>
|
||||
''' NO 键松开
|
||||
''' </summary>
|
||||
NoReleased
|
||||
End Enum
|
||||
|
||||
Public Delegate Sub UtsKeyDownEventHandler(sender As Object, e As UtsKeyDownEventArgs)
|
||||
|
||||
''' <summary>
|
||||
''' UTS测试架按键按下
|
||||
''' </summary>
|
||||
Public Shared Event UtsKeyDown As UtsKeyDownEventHandler
|
||||
|
||||
|
||||
Private Shared _utsKeyValue As UtsKeyValueEnum = UtsKeyValueEnum.None
|
||||
|
||||
''' <summary>
|
||||
''' UTS测试架按键键值
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Property UtsKeyValue() As UtsKeyValueEnum
|
||||
Get
|
||||
Return _utsKeyValue
|
||||
End Get
|
||||
Set(value As UtsKeyValueEnum)
|
||||
_utsKeyValue = value
|
||||
|
||||
If value <> UtsKeyValueEnum.None Then '有按键按下
|
||||
RaiseEvent UtsKeyDown(Nothing, New UtsKeyDownEventArgs() With {.KeyValue = _utsKeyValue})
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
525
UTS_Core/UTSModule/Test/TestRecordGrid.vb
Normal file
525
UTS_Core/UTSModule/Test/TestRecordGrid.vb
Normal file
@@ -0,0 +1,525 @@
|
||||
Imports System.Drawing
|
||||
Imports System.Text
|
||||
Imports FlexCell
|
||||
Imports UTS_Core.UTSModule.Station
|
||||
Imports UTS_Core.UTSModule.Station.StationTestPlan
|
||||
Imports UTS_Core.UTSModule.Test.Command
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class TestRecordGrid
|
||||
'表格各列名称对应下表
|
||||
Enum ColNames
|
||||
No
|
||||
Description
|
||||
Record
|
||||
Elapsed
|
||||
Lower
|
||||
Upper
|
||||
Result
|
||||
Max
|
||||
End Enum
|
||||
|
||||
'Private ReadOnly _colWidth() As Short = {30,
|
||||
' 140,
|
||||
' 70,
|
||||
' 50,
|
||||
' 60,
|
||||
' 60,
|
||||
' 60,
|
||||
' 60
|
||||
' }
|
||||
|
||||
'Momo2023-11-10 调整宽度,适应pad竖屏
|
||||
Private ReadOnly _colWidth() As Short = {30,
|
||||
120,
|
||||
70,
|
||||
50,
|
||||
50,
|
||||
50,
|
||||
50,
|
||||
50
|
||||
}
|
||||
|
||||
Private ReadOnly _colType() As CellTypeEnum = {CellTypeEnum.DefaultType,
|
||||
CellTypeEnum.DefaultType,
|
||||
CellTypeEnum.DefaultType,
|
||||
CellTypeEnum.TextBox,
|
||||
CellTypeEnum.TextBox,
|
||||
CellTypeEnum.TextBox,
|
||||
CellTypeEnum.TextBox,
|
||||
CellTypeEnum.TextBox}
|
||||
|
||||
Private _grd As Grid
|
||||
|
||||
Private _plan As StationTestPlan
|
||||
|
||||
''' <summary>内置模块入口集合</summary>
|
||||
Private ReadOnly _testModules As New Dictionary(Of String, RowNode)
|
||||
|
||||
''' <summary>自定义模块下函数入口集合</summary>
|
||||
Private ReadOnly _customModules As New Dictionary(Of String, RowNode)
|
||||
|
||||
Private ReadOnly _rowList As Dictionary(Of Integer, RowNode)
|
||||
Private ReadOnly _nodeList As Dictionary(Of RowNode, Integer)
|
||||
|
||||
Private _callNodeList As New Dictionary(Of RowNode, List(Of Integer))
|
||||
Private _callNodeUpdateCount As New Dictionary(Of RowNode, Integer)
|
||||
|
||||
Private ReadOnly _recodeRow As List(Of Integer)
|
||||
|
||||
Sub New()
|
||||
_rowList = New Dictionary(Of Integer, RowNode)()
|
||||
_nodeList = New Dictionary(Of RowNode, Integer)()
|
||||
_recodeRow = New List(Of Integer)()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 测试记录所关联的控件
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property Grid As Grid
|
||||
Get
|
||||
Return _grd
|
||||
End Get
|
||||
|
||||
Set(value As FlexCell.Grid)
|
||||
_grd = value
|
||||
UpdateStepTestRecord()
|
||||
|
||||
RemoveHandler _grd.SelChange, AddressOf Grid_SelChange
|
||||
|
||||
AddHandler _grd.SelChange, AddressOf Grid_SelChange
|
||||
|
||||
'点击返回选中节点
|
||||
End Set
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 测试记录所关联的测试流程
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property StationPlan() As StationTestPlan
|
||||
Get
|
||||
Return _plan
|
||||
End Get
|
||||
Set(value As StationTestPlan)
|
||||
_plan = value
|
||||
If _grd IsNot Nothing Then
|
||||
UpdateStepTestRecord(_plan)
|
||||
ShowRecordRows() ' Momo 2023-11-14 默认只显示记录行
|
||||
End If
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Property ActiveNode() As RowNode
|
||||
|
||||
|
||||
Private Sub Grid_SelChange(sender As Object, e As Grid.SelChangeEventArgs)
|
||||
If _grd.ActiveCell Is Nothing Then Return
|
||||
If _grd.ActiveCell.Row <= 0 Then Return
|
||||
If _grd.ActiveCell.Row >= _grd.Rows Then Return
|
||||
ActiveNode = _rowList(_grd.ActiveCell.Row)
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 获取指定变量名的变量值
|
||||
''' </summary>
|
||||
''' <param name="varName">变量名</param>
|
||||
''' <param name="localVariable">调用模块时传入的局部变量</param>
|
||||
''' <returns></returns>
|
||||
Private Function ReplaceVar(varName As String, Optional localVariable As Dictionary(Of String, String) = Nothing) As String
|
||||
'替换变量的逻辑顺序
|
||||
'优先替换局部变量,也就是传进模块的变量
|
||||
'其次使用用户变量,也就是记录入库的变量
|
||||
'最后匹配系统变量,也就是预设带有特殊意义的字符串
|
||||
If localVariable IsNot Nothing AndAlso localVariable.ContainsKey(varName) Then
|
||||
Return localVariable(varName)
|
||||
Else
|
||||
Return varName
|
||||
End If
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 替换字符串中使用的变量,返回替换后的字符串
|
||||
''' </summary>
|
||||
''' <param name="sourceString">原字符串</param>
|
||||
''' <param name="localVariable">调用模块时传入的局部变量</param>
|
||||
''' <returns>替换后的字符串</returns>
|
||||
Private Function ReplaceString(sourceString As String, Optional localVariable As Dictionary(Of String, String) = Nothing) As String
|
||||
Dim strBuilder As New StringBuilder
|
||||
Dim varName As New StringBuilder
|
||||
Dim findVar As Boolean
|
||||
|
||||
For Each c As Char In sourceString
|
||||
If c = "{"c Then
|
||||
If findVar Then
|
||||
findVar = False
|
||||
strBuilder.Append("{")
|
||||
Else
|
||||
findVar = True
|
||||
End If
|
||||
ElseIf c = "}"c Then
|
||||
If findVar Then
|
||||
strBuilder.Append(ReplaceVar(varName.ToString(), localVariable))
|
||||
varName.Clear()
|
||||
findVar = False
|
||||
Else
|
||||
strBuilder.Append("}")
|
||||
End If
|
||||
Else
|
||||
If findVar Then
|
||||
varName.Append(c)
|
||||
Else
|
||||
strBuilder.Append(c)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
|
||||
Return strBuilder.ToString
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub SearchRecordName(nodes As RowNodeCollection, Optional isCallNode As Boolean = False, Optional localVariable As Dictionary(Of String, String) = Nothing)
|
||||
For Each node As RowNode In nodes
|
||||
If node.Action = False Then Continue For
|
||||
|
||||
_grd.AddItem("")
|
||||
|
||||
Dim row As Integer = _grd.Rows - 1
|
||||
_grd.Cell(row, ColNames.Record).Text = ReplaceString(node.RecordName, localVariable) '替换记录名称中变量
|
||||
_grd.Cell(row, ColNames.Description).Text = ReplaceString(node.Description, localVariable)
|
||||
|
||||
If isCallNode Then
|
||||
If _callNodeList.ContainsKey(node) Then
|
||||
_callNodeList(node).Add(row)
|
||||
Else
|
||||
_callNodeList.Add(node, New List(Of Integer) From {row})
|
||||
End If
|
||||
Else
|
||||
_nodeList.Add(node, row)
|
||||
End If
|
||||
_rowList.Add(row, node)
|
||||
|
||||
If node.SaveToDb Then
|
||||
_recodeRow.Add(row)
|
||||
|
||||
_grd.Range(row, 1, _grd.Rows - 1, _grd.Cols - 1).ForeColor = Color.Black
|
||||
Else
|
||||
_grd.Range(row, 1, _grd.Rows - 1, _grd.Cols - 1).ForeColor = Color.Gray
|
||||
End If
|
||||
|
||||
If node.RowNodes.Count > 0 Then
|
||||
SearchRecordName(node.RowNodes, isCallNode, localVariable) '2024-05-20 阿标 被调函数有多级节点时,将子级CallNode属性带入函数
|
||||
End If
|
||||
|
||||
'如果为Call命令则添加被调用模块下内容
|
||||
If node.RowType = RowNode.RowTypeEnum.Flow AndAlso node.Command = "Call" Then
|
||||
Dim moduleName As String = node.Parameters(0).Value
|
||||
Dim varNames() As String = node.Parameters(1).Value.Split(":"c)
|
||||
Dim varValues() As String = node.Parameters(2).Value.Split(":"c)
|
||||
|
||||
Dim variable As New Dictionary(Of String, String)
|
||||
For i As Integer = 0 To varNames.Count - 1
|
||||
variable.Add(varNames(i), varValues(i))
|
||||
Next
|
||||
|
||||
Dim moduleNode As RowNode = GetModule(moduleName)
|
||||
If moduleNode Is Nothing Then
|
||||
MsgBox($"行号:{node.RowListIndex} 未找到可调用模块:{moduleName}")
|
||||
Continue For
|
||||
End If
|
||||
SearchRecordName(moduleNode.RowNodes, True, variable)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 更新测试模块入库
|
||||
''' </summary>
|
||||
Private Sub UpdateTestModule(rowNodes As RowNodeCollection)
|
||||
_testModules.Clear()
|
||||
|
||||
GetTestModule(_testModules, rowNodes)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 获取执行行节点集合中测试模块入口,并存储至内部模块入口集合
|
||||
''' </summary>
|
||||
''' <param name="modules">存储测试模块入口集合</param>
|
||||
''' <param name="nodes">行节点集合</param>
|
||||
Private Sub GetTestModule(modules As Dictionary(Of String, RowNode), nodes As RowNodeCollection)
|
||||
For Each node As RowNode In nodes
|
||||
If node.RowType = RowNode.RowTypeEnum.FixedModule OrElse node.RowType = RowNode.RowTypeEnum.Module Then
|
||||
If String.IsNullOrWhiteSpace(node.Label) Then Continue For
|
||||
If modules.ContainsKey(node.Label) Then Continue For
|
||||
modules.Add(node.Label, node)
|
||||
End If
|
||||
|
||||
If node.Label = $"{FixedModuleEnum.Custom}" Then
|
||||
_customModules.Clear()
|
||||
GetTestModule(_customModules, node.RowNodes)
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 获取固定模块节点
|
||||
''' </summary>
|
||||
''' <param name="name">固定模块名</param>
|
||||
''' <returns></returns>
|
||||
Public Function GetFixedModule(name As FixedModuleEnum) As RowNode
|
||||
If _testModules.ContainsKey($"{name}") = False Then Return Nothing
|
||||
Return _testModules($"{name}")
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 获取模块节点
|
||||
''' </summary>
|
||||
''' <param name="name">模块名</param>
|
||||
''' <returns></returns>
|
||||
Public Function GetModule(name As String) As RowNode
|
||||
If _customModules.ContainsKey(name) Then
|
||||
Return _customModules(name)
|
||||
ElseIf _testModules.ContainsKey(name) Then
|
||||
Return _testModules(name)
|
||||
Else
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
'If _testModules.ContainsKey(name) = False Then Return Nothing
|
||||
|
||||
'Return _testModules(name)
|
||||
End Function
|
||||
|
||||
Public Sub UpdateStepTestRecord()
|
||||
With _grd
|
||||
.AutoRedraw = False
|
||||
.AutoSize = True
|
||||
.Cols = ColNames.Max
|
||||
.Rows = 1
|
||||
.ExtendLastCol = True '最后一列自动扩充
|
||||
.DisplayRowNumber = True '首列显示数字
|
||||
|
||||
For col As Integer = 0 To ColNames.Max - 1
|
||||
.Cell(0, col).Text = [Enum].GetName(GetType(ColNames), col) '设置列名
|
||||
.Column(col).CellType = _colType(col) '设置列型
|
||||
.Column(col).Width = _colWidth(col) '设置列宽
|
||||
If col = 3 Then 'Momo 2023-11-14 第三行文字居中
|
||||
.Column(col).Alignment = AlignmentEnum.CenterCenter
|
||||
End If
|
||||
Next
|
||||
|
||||
|
||||
.ForeColorComment = Color.Blue
|
||||
|
||||
.FrozenCols = ColNames.Description '冻结列
|
||||
|
||||
.Column(ColNames.Elapsed).Alignment = AlignmentEnum.RightCenter '设置对齐位置
|
||||
|
||||
_nodeList.Clear()
|
||||
_rowList.Clear()
|
||||
_recodeRow.Clear()
|
||||
_callNodeList.Clear()
|
||||
If StationPlan IsNot Nothing Then
|
||||
UpdateTestModule(StationPlan.RowNodes) '记录所有模块名
|
||||
|
||||
Dim mainNode As RowNode = GetFixedModule(FixedModuleEnum.Main)
|
||||
SearchRecordName(mainNode.RowNodes) '添加Main模块下节点,遇见Call命令则展开被调用的模块
|
||||
End If
|
||||
|
||||
.AutoRedraw = True
|
||||
.Refresh()
|
||||
End With
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 初始化记录表格
|
||||
''' </summary>
|
||||
''' <param name="plan">测试流程</param>
|
||||
Private Sub UpdateStepTestRecord(plan As StationTestPlan)
|
||||
With _grd
|
||||
.AutoRedraw = False
|
||||
.AutoSize = True
|
||||
.Cols = ColNames.Max
|
||||
.Rows = 1
|
||||
.ExtendLastCol = True '最后一列自动扩充
|
||||
.DisplayRowNumber = True '首列显示数字
|
||||
|
||||
For col As Integer = 0 To ColNames.Max - 1
|
||||
.Cell(0, col).Text = [Enum].GetName(GetType(ColNames), col) '设置列名
|
||||
.Column(col).CellType = _colType(col) '设置列型
|
||||
.Column(col).Width = _colWidth(col) '设置列宽
|
||||
Next
|
||||
.ForeColorComment = Color.Blue
|
||||
|
||||
.FrozenCols = ColNames.Description '冻结列
|
||||
|
||||
.Column(ColNames.Elapsed).Alignment = AlignmentEnum.RightCenter '设置对齐位置
|
||||
|
||||
_nodeList.Clear()
|
||||
_rowList.Clear()
|
||||
_recodeRow.Clear()
|
||||
_callNodeList.Clear()
|
||||
If StationPlan IsNot Nothing Then
|
||||
UpdateTestModule(StationPlan.RowNodes) '记录所有模块名
|
||||
|
||||
Dim mainNode As RowNode = GetFixedModule(FixedModuleEnum.Main)
|
||||
SearchRecordName(mainNode.RowNodes) '添加Main模块下节点,遇见Call命令则展开被调用的模块
|
||||
End If
|
||||
|
||||
.AutoRedraw = True
|
||||
.Refresh()
|
||||
End With
|
||||
End Sub
|
||||
|
||||
Private _lastNode As RowNode
|
||||
|
||||
''' <summary>
|
||||
''' 获取当前节点所在的记录行,0代表未找到对应节点
|
||||
''' </summary>
|
||||
''' <param name="node">当前测试节点</param>
|
||||
''' <returns></returns>
|
||||
Public Function GetRowByNode(node As RowNode) As Integer
|
||||
Dim row As Integer = 0
|
||||
If _nodeList.ContainsKey(node) Then
|
||||
row = _nodeList(node)
|
||||
ElseIf _callNodeList.ContainsKey(node) Then
|
||||
If _callNodeUpdateCount.ContainsKey(node) Then
|
||||
If _lastNode IsNot Nothing AndAlso _lastNode.RowListIndex <> node.RowListIndex AndAlso node.IsRetry = False Then
|
||||
_callNodeUpdateCount(node) += 1
|
||||
Console.WriteLine($"Node:{node.Description} Count:{_callNodeUpdateCount(node)}")
|
||||
End If
|
||||
Else
|
||||
_callNodeUpdateCount.Add(node, 0)
|
||||
Console.WriteLine($"Node:{node.Description} Count:{_callNodeUpdateCount(node)}")
|
||||
End If
|
||||
|
||||
row = _callNodeList(node)(_callNodeUpdateCount(node))
|
||||
End If
|
||||
|
||||
_lastNode = node
|
||||
Return row
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 反显当前测试节点所在的记录行
|
||||
''' </summary>
|
||||
''' <param name="node">当前测试节点</param>
|
||||
Public Sub UpdateTestRow(node As RowNode)
|
||||
Dim row As Integer = GetRowByNode(node)
|
||||
If row <= 0 Then Return
|
||||
|
||||
If _grd.InvokeRequired Then '判断是否需要开委托
|
||||
_grd.Invoke(New Action(Of Integer)(Sub()
|
||||
_grd.Range(row, 1, row, _grd.Cols - 1).SelectCells()
|
||||
End Sub), New Object() {row})
|
||||
Else
|
||||
_grd.Range(row, 1, row, _grd.Cols - 1).SelectCells()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 更新测试记录表格指定记录名的记录结果列内容
|
||||
''' </summary>
|
||||
''' <param name="node"></param>
|
||||
''' <param name="recordValue"></param>
|
||||
Public Sub UpdateTestRecord(node As RowNode, recordValue As TestCommandReturn)
|
||||
If _grd.InvokeRequired Then '判断是否需要开委托
|
||||
_grd.Invoke(New Action(Of RowNode, TestCommandReturn)(AddressOf UpdateTestRecord), New Object() {node, recordValue})
|
||||
Return
|
||||
End If
|
||||
|
||||
Dim row As Integer = GetRowByNode(node)
|
||||
If row <= 0 Then Return
|
||||
|
||||
If recordValue.ExecuteResult Then
|
||||
_grd.Cell(row, ColNames.Result).ForeColor = Color.Green
|
||||
Else
|
||||
_grd.Cell(row, ColNames.Result).ForeColor = Color.Red
|
||||
End If
|
||||
|
||||
_grd.Cell(row, ColNames.Elapsed).Text = recordValue.StepTimeSpan.TotalMilliseconds.ToString("N0")
|
||||
_grd.Cell(row, ColNames.Lower).Text = recordValue.LowerLimit
|
||||
_grd.Cell(row, ColNames.Upper).Text = recordValue.UpperLimit
|
||||
_grd.Cell(row, ColNames.Result).Text = recordValue.RecordValue
|
||||
|
||||
' _grd.Range(row, 1, row, _grd.Cols - 1).SelectCells()
|
||||
'_grd.Cell(row, ColNames.Description).EnsureVisible()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 更新测试记录表格指定记录名的记录结果列内容
|
||||
''' </summary>
|
||||
''' <param name="recordName"></param>
|
||||
''' <param name="recordValue"></param>
|
||||
Public Sub UpdateTestRecord(recordName As String, recordValue As TestCommandReturn)
|
||||
If _grd Is Nothing Then Return
|
||||
|
||||
For row As Integer = 1 To _grd.Rows - 1
|
||||
If String.Compare(recordName, _grd.Cell(row, ColNames.Record).Text, True) <> 0 Then
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If _grd.InvokeRequired Then '判断是否需要开委托
|
||||
_grd.Invoke(New Action(Of String, TestCommandReturn)(AddressOf UpdateTestRecord), New Object() {recordName, recordValue})
|
||||
Return
|
||||
End If
|
||||
|
||||
If recordValue.ExecuteResult Then
|
||||
_grd.Cell(row, ColNames.Result).ForeColor = Color.Green
|
||||
Else
|
||||
_grd.Cell(row, ColNames.Result).ForeColor = Color.Red
|
||||
End If
|
||||
|
||||
_grd.Cell(row, ColNames.Lower).Text = recordValue.LowerLimit
|
||||
_grd.Cell(row, ColNames.Upper).Text = recordValue.UpperLimit
|
||||
_grd.Cell(row, ColNames.Result).Text = recordValue.RecordValue
|
||||
_grd.Range(row, 1, row, _grd.Cols - 1).SelectCells()
|
||||
' _grd.Cell(row, ColNames.Result).SetFocus()
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Public Sub ClearRecode()
|
||||
If _grd Is Nothing Then Return
|
||||
|
||||
_lastNode = Nothing
|
||||
_callNodeUpdateCount.Clear()
|
||||
For row As Integer = 1 To _grd.Rows - 1
|
||||
_grd.Cell(row, ColNames.Elapsed).Text = ""
|
||||
|
||||
_grd.Cell(row, ColNames.Result).Text = ""
|
||||
_grd.Cell(row, ColNames.Result).ForeColor = Color.Black
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 显示所有行
|
||||
''' </summary>
|
||||
Public Sub ShowAllRows()
|
||||
'把隐藏的行显示
|
||||
For i As Integer = 1 To _grd.Rows - 1
|
||||
_grd.Row(i).Visible = True
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 屏蔽非记录行
|
||||
''' </summary>
|
||||
Public Sub ShowRecordRows()
|
||||
'折叠所有的非记录的行
|
||||
For i As Integer = 1 To _grd.Rows - 1
|
||||
_grd.Row(i).Visible = _recodeRow.Contains(i)
|
||||
Next
|
||||
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
220
UTS_Core/UTSModule/Test/TestResult.vb
Normal file
220
UTS_Core/UTSModule/Test/TestResult.vb
Normal file
@@ -0,0 +1,220 @@
|
||||
Imports System.Text
|
||||
Imports UTS_Core.UTSModule.DbTableModel.Customer
|
||||
Imports UTS_Core.UTSModule.Station
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class TestResult
|
||||
''' <summary>
|
||||
''' 测试结果枚举集合
|
||||
''' </summary>
|
||||
Enum TestResultEnum
|
||||
Fail
|
||||
Pass
|
||||
End Enum
|
||||
|
||||
Sub New()
|
||||
UserID = -1
|
||||
ServiceID = -1
|
||||
ProductionLineID = -1
|
||||
OrderID = -1
|
||||
|
||||
AppName = String.Empty
|
||||
TestPlan = String.Empty
|
||||
_dutSn = String.Empty
|
||||
|
||||
TestResult = TestResultEnum.Fail
|
||||
|
||||
ErrCode = String.Empty
|
||||
|
||||
FailSteps = New List(Of RowNode)()
|
||||
CustomRecord = New Dictionary(Of String, String)()
|
||||
End Sub
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 当前用户索引,登陆后填充
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property UserID As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 当前服务索引,登陆后获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ServiceID As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 所属产线索引,用户选择后获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ProductionLineID As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 所属订单索引,用户提供条码,系统自动填充
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property OrderID() As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 测试程序的名称,登陆后填充
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property AppName As String
|
||||
|
||||
''' <summary>
|
||||
''' 测试流程名,切换项目流程站后获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property TestPlan As String
|
||||
|
||||
Private _dutSn As String
|
||||
|
||||
''' <summary>
|
||||
''' 测试产品的索引序号,测试时获取,(使用大写,8字符)
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property DUT_SN As String
|
||||
Get
|
||||
Return _dutSn
|
||||
End Get
|
||||
Set(value As String)
|
||||
_dutSn = value.ToUpper
|
||||
End Set
|
||||
End Property
|
||||
|
||||
''' <summary>
|
||||
''' 测试开始日期与时间,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property StartTime As DateTime
|
||||
|
||||
''' <summary>
|
||||
''' 测试耗时,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property UsedTime As TimeSpan
|
||||
|
||||
''' <summary>
|
||||
''' 测试结果,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property TestResult As TestResultEnum
|
||||
|
||||
''' <summary>
|
||||
''' 错误代码,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property ErrCode As String
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 失败步骤集合,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property FailSteps As List(Of RowNode)
|
||||
|
||||
''' <summary>
|
||||
''' 自定义记录数据,测试时获取
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Property CustomRecord() As Dictionary(Of String, String)
|
||||
|
||||
''' <summary>
|
||||
''' 切换测试站后,初始话测试结果信息
|
||||
''' </summary>
|
||||
Public Sub InitTestResult(user As Integer)
|
||||
UserID = user
|
||||
|
||||
TestResult = TestResultEnum.Fail
|
||||
|
||||
FailSteps = New List(Of RowNode)()
|
||||
CustomRecord = New Dictionary(Of String, String)()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 开启新一轮测试时,重置测试结果信息
|
||||
''' </summary>
|
||||
Public Sub ResetTestResult()
|
||||
ErrCode = String.Empty
|
||||
|
||||
_dutSn = String.Empty
|
||||
TestResult = TestResultEnum.Fail
|
||||
|
||||
StartTime = Now
|
||||
UsedTime = New TimeSpan()
|
||||
|
||||
OrderID = -1
|
||||
|
||||
FailSteps.Clear()
|
||||
CustomRecord.Clear()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 添加自定义需要记录的测试信息
|
||||
''' </summary>
|
||||
''' <param name="name">记录列名</param>
|
||||
''' <param name="value">记录值</param>
|
||||
Public Function AddCustomRecord(name As String, value As String) As Boolean
|
||||
If String.Compare(name, $"{TestLogTable.ColNames.DUT_SN}") = 0 Then
|
||||
_dutSn = value
|
||||
Else
|
||||
If CustomRecord.ContainsKey(name) Then
|
||||
CustomRecord(name) = value '已有字段则覆盖原值
|
||||
Else
|
||||
CustomRecord.Add(name, value)
|
||||
End If
|
||||
End If
|
||||
Return True
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 将当前测试信息转换为字符键值对
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function ToStringDictionary() As Dictionary(Of String, String)
|
||||
Dim dic As New Dictionary(Of String, String) From {
|
||||
{$"{TestLogTable.ColNames.UserID}", UserID.ToString()},
|
||||
{$"{TestLogTable.ColNames.ServiceID}", ServiceID.ToString()},
|
||||
{$"{TestLogTable.ColNames.DUT_SN}", _dutSn},
|
||||
{$"{TestLogTable.ColNames.AppName}", AppName},
|
||||
{$"{TestLogTable.ColNames.TestPlan}", TestPlan},
|
||||
{$"{TestLogTable.ColNames.StartTime}", StartTime.ToString("yyyy-MM-dd HH:mm:ss")},
|
||||
{$"{TestLogTable.ColNames.UsedTime}", UsedTime.TotalSeconds.ToString("F2")},
|
||||
{$"{TestLogTable.ColNames.TestResult}", IIf(TestResult = TestResultEnum.Fail, 0, 1).ToString()},
|
||||
{$"{TestLogTable.ColNames.ErrCode}", ErrCode},
|
||||
{$"{TestLogTable.ColNames.ProductionLineID}", ProductionLineID.ToString()},
|
||||
{$"{TestLogTable.ColNames.OrderID}", OrderID.ToString()}
|
||||
}
|
||||
|
||||
'填充失败步骤信息(此处需要一个信息定位失败步骤)
|
||||
Dim steps As New StringBuilder
|
||||
Dim msg As New StringBuilder
|
||||
For Each node As RowNode In FailSteps
|
||||
If steps.Length > 0 Then
|
||||
steps.Append(","c)
|
||||
msg.Append(","c)
|
||||
End If
|
||||
|
||||
steps.Append(node.RowListIndex)
|
||||
msg.Append(node.Desc4Record)
|
||||
msg.Append($" {node.TestReturn.RecordValue} ({node.TestReturn.LowerLimit},{node.TestReturn.UpperLimit})")
|
||||
Next
|
||||
dic.Add($"{TestLogTable.ColNames.FailSteps}", steps.ToString())
|
||||
dic.Add($"{TestLogTable.ColNames.FailMsg}", msg.ToString())
|
||||
|
||||
'填充自定义记录数据字段信息
|
||||
For Each keyValue As KeyValuePair(Of String, String) In CustomRecord
|
||||
If dic.ContainsKey(keyValue.Key) Then
|
||||
dic(keyValue.Key) = keyValue.Value
|
||||
Else
|
||||
dic.Add(keyValue.Key, keyValue.Value)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return dic
|
||||
End Function
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
183
UTS_Core/UTSModule/Test/UtsComPort.vb
Normal file
183
UTS_Core/UTSModule/Test/UtsComPort.vb
Normal file
@@ -0,0 +1,183 @@
|
||||
Imports System.IO.Ports
|
||||
Imports System.Text
|
||||
Imports UTS_Core.DebugLog
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class UtsComPort
|
||||
''' <summary>通讯串口</summary>
|
||||
Private ReadOnly Property Comport As SerialPort
|
||||
|
||||
''' <summary>接收起始时间</summary>
|
||||
Private _receiveStartTime As DateTime
|
||||
|
||||
''' <summary>接收到的字符串</summary>
|
||||
Private ReadOnly _receiveString As New StringBuilder
|
||||
|
||||
''' <summary>接收到的经过处理后的合法数据队列</summary>
|
||||
Public CacheData As New Queue(Of UtsComPortData)
|
||||
|
||||
Sub New()
|
||||
Comport = New SerialPort()
|
||||
AddHandler Comport.DataReceived, AddressOf ComPort_DataReceived
|
||||
|
||||
ReceivedData = New UtsComPortData()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 获取所有串口名
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Shared Function GetPortNames() As String()
|
||||
Return SerialPort.GetPortNames()
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 打开串口
|
||||
''' </summary>
|
||||
''' <param name="portName"></param>
|
||||
''' <param name="baudRate"></param>
|
||||
Public Function OpenSerialPort(portName As String, baudRate As Integer) As Boolean
|
||||
Try
|
||||
If Comport.IsOpen Then Comport.Close()
|
||||
With Comport
|
||||
.PortName = portName '串口名
|
||||
.BaudRate = baudRate '波特率
|
||||
.DataBits = 8 '数据位
|
||||
.StopBits = StopBits.One '停止位
|
||||
.Parity = Parity.None '偶校验
|
||||
.RtsEnable = True
|
||||
.Open()
|
||||
End With
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"打开测试串口失败!原因:{ex.Message}。")
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function CloseSerialPort() As Boolean
|
||||
If Comport Is Nothing Then Return True
|
||||
Try
|
||||
Comport.Close()
|
||||
Catch ex As Exception
|
||||
Return False
|
||||
End Try
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendText(sendString As String) As Boolean
|
||||
Try
|
||||
Comport.Write(sendString)
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"Send Error,原因:{ex.Message}")
|
||||
Return False
|
||||
End Try
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Function SendText(sendData As UtsComPortData) As Boolean
|
||||
If sendData Is Nothing Then Throw New Exception($"SendTest:SendData Is Nothing")
|
||||
|
||||
Return SendText(sendData.ToString())
|
||||
End Function
|
||||
|
||||
Public Function SendText(fromAddress As String, toAddress As String, command As String, params As List(Of String)) As Boolean
|
||||
Return SendText(UtsComPortData.ConvertToString(fromAddress, toAddress, command, params))
|
||||
End Function
|
||||
|
||||
Public Function SendTextAppendCrLf(sendData As UtsComPortData) As Boolean
|
||||
If sendData Is Nothing Then Throw New Exception($"SendTest:SendData Is Nothing")
|
||||
|
||||
Return SendText($"{sendData}{vbCrLf}")
|
||||
End Function
|
||||
|
||||
Public Function SendTextAppendCrLf(fromAddress As String, toAddress As String, command As String, params As List(Of String)) As Boolean
|
||||
Return SendText($"{UtsComPortData.ConvertToString(fromAddress, toAddress, command, params)}{vbCrLf}")
|
||||
End Function
|
||||
|
||||
|
||||
Private Function ReceiveData() As Byte()
|
||||
Static bytes As Integer = 0
|
||||
Try
|
||||
bytes = Comport.BytesToRead
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"UtsComport BytesToRead Error:{ex.Message}")
|
||||
Return New Byte() {}
|
||||
End Try
|
||||
|
||||
Dim receiveBuffer(bytes - 1) As Byte
|
||||
Try
|
||||
Comport.Read(receiveBuffer, 0, bytes)
|
||||
Catch ex As Exception
|
||||
Console.WriteLine($"UtsComport ReceiveData Error:{ex.Message}")
|
||||
Return New Byte() {}
|
||||
End Try
|
||||
|
||||
Return receiveBuffer
|
||||
End Function
|
||||
|
||||
Private Function DealReceivedData(receiveBuffer() As Byte) As Boolean
|
||||
If receiveBuffer.Length <= 0 Then Return True
|
||||
If receiveBuffer(receiveBuffer.Length - 1) = 10 Then '接收到换行符,接收完成
|
||||
|
||||
_receiveString.Append(Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length))
|
||||
|
||||
Dim tmpString() As String = _receiveString.ToString().Replace(ControlChars.Cr, String.Empty).Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
|
||||
|
||||
For Each str As String In tmpString
|
||||
Try
|
||||
CacheData.Enqueue(UtsComPortData.ConvertFromString(str))
|
||||
|
||||
If CacheData.Count > 64 Then CacheData.Dequeue() '缓存数据队列过多,移除头部缓存
|
||||
Catch ex As Exception
|
||||
ApplicationLog.WriteWarningLog($"ComportData ConvertString Error,String:{str} Error:{ex.Message}")
|
||||
Console.WriteLine($"ComportData ConvertString Error,String:{str} Error:{ex.Message}")
|
||||
End Try
|
||||
Next
|
||||
|
||||
_receiveString.Clear() '处理完成清空缓存
|
||||
_receiveStartTime = Now
|
||||
|
||||
Else
|
||||
If _receiveString.Length = 0 Then '单包未接收完全,记录起始时间
|
||||
_receiveStartTime = Now
|
||||
End If
|
||||
|
||||
_receiveString.Append(Encoding.UTF8.GetString(receiveBuffer, 0, receiveBuffer.Length))
|
||||
|
||||
'_receiveStatus = ReceiveStatusEnum.Receiving
|
||||
|
||||
'超过最大缓冲长度,则先处理
|
||||
'超时仍旧未接收完全,则先处理
|
||||
End If
|
||||
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Private Sub ComPort_DataReceived(sender As Object, e As SerialDataReceivedEventArgs)
|
||||
Dim receiveBuffer() As Byte = ReceiveData()
|
||||
|
||||
DealReceivedData(receiveBuffer)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 接收分析后的数据
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public ReadOnly Property ReceivedData As UtsComPortData
|
||||
|
||||
|
||||
Public Function ComportName() As String
|
||||
Return Comport.PortName
|
||||
End Function
|
||||
|
||||
Public Function ComportBaudRate() As Integer
|
||||
Return Comport.BaudRate
|
||||
End Function
|
||||
|
||||
Public Function StartReceiveTime() As DateTime
|
||||
Return _receiveStartTime
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
195
UTS_Core/UTSModule/Test/UtsComPortData.vb
Normal file
195
UTS_Core/UTSModule/Test/UtsComPortData.vb
Normal file
@@ -0,0 +1,195 @@
|
||||
Imports System.Text
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class UtsComPortData
|
||||
Private Shared _separator As Char = ":"c
|
||||
|
||||
''' <summary>
|
||||
''' 发送方地址
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property SenderAddress() As String
|
||||
|
||||
''' <summary>
|
||||
''' 接收方地址
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property ReceiverAddress() As String
|
||||
|
||||
''' <summary>
|
||||
''' UTS通讯命令
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property Command() As String
|
||||
|
||||
''' <summary>
|
||||
''' UTS命令参数
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Property Params() As List(Of String)
|
||||
|
||||
|
||||
Sub New()
|
||||
Params = New List(Of String)
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令常用初始化方式
|
||||
''' </summary>
|
||||
''' <param name="utsAddress"></param>
|
||||
''' <param name="utsCmd"></param>
|
||||
''' <param name="utsParamString"></param>
|
||||
Sub New(utsAddress As String, utsCmd As String, utsParamString As String)
|
||||
SenderAddress = DeviceAddress.LocalAddress()
|
||||
ReceiverAddress = utsAddress
|
||||
Command = utsCmd
|
||||
Params = StringToParamList(utsParamString)
|
||||
End Sub
|
||||
|
||||
|
||||
Sub New(utsAddress As String, utsCmd As String)
|
||||
SenderAddress = DeviceAddress.LocalAddress()
|
||||
ReceiverAddress = utsAddress
|
||||
Command = utsCmd
|
||||
Params = New List(Of String)
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 发送后台通讯命令常用初始化方式
|
||||
''' </summary>
|
||||
''' <param name="utsAddress"></param>
|
||||
''' <param name="utsCmd"></param>
|
||||
''' <param name="utsParam"></param>
|
||||
Sub New(utsAddress As String, utsCmd As String, utsParam As List(Of String))
|
||||
SenderAddress = DeviceAddress.LocalAddress()
|
||||
ReceiverAddress = utsAddress
|
||||
Command = utsCmd
|
||||
Params = utsParam
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 重置当前对象的信息
|
||||
''' </summary>
|
||||
Public Sub Reset()
|
||||
SenderAddress = String.Empty
|
||||
ReceiverAddress = String.Empty
|
||||
Command = String.Empty
|
||||
Params.Clear()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 深度拷贝数据, 创建当前对象的克隆
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Function Clone() As UtsComPortData
|
||||
Dim uc As New UtsComPortData
|
||||
uc.Command = Command
|
||||
uc.SenderAddress = SenderAddress
|
||||
uc.ReceiverAddress = ReceiverAddress
|
||||
uc.Params.AddRange(Params.ToArray())
|
||||
Return uc
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 将参数字符串处理成参数列表
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Shared Function StringToParamList(paramString As String) As List(Of String)
|
||||
Dim strings() As String = paramString.Split(New Char() {_separator}, StringSplitOptions.RemoveEmptyEntries)
|
||||
Return New List(Of String)(strings)
|
||||
End Function
|
||||
|
||||
|
||||
Public Function ParamListToString() As String
|
||||
If Params.Count = 0 Then Return String.Empty
|
||||
Dim str As New StringBuilder
|
||||
str.Append(Params.Item(0))
|
||||
For i As Integer = 1 To Params.Count - 1
|
||||
str.Append(_separator)
|
||||
str.Append(Params.Item(i))
|
||||
Next
|
||||
|
||||
Return str.ToString()
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 将必须通讯参数转换为uts通讯字符串
|
||||
''' </summary>
|
||||
''' <param name="fromAddress">发送方地址</param>
|
||||
''' <param name="toAddress">接收发地址</param>
|
||||
''' <param name="command">命令字</param>
|
||||
''' <param name="params">命令参数</param>
|
||||
''' <param name="separator">组合命令分隔符</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ConvertToString(fromAddress As String, toAddress As String, command As String, params As List(Of String), Optional separator As Char = ":"c) As String
|
||||
Dim strTemp As New StringBuilder
|
||||
strTemp.Append(fromAddress)
|
||||
strTemp.Append(separator)
|
||||
strTemp.Append(toAddress)
|
||||
strTemp.Append(separator)
|
||||
strTemp.Append(command)
|
||||
|
||||
For Each param As String In params
|
||||
strTemp.Append(separator)
|
||||
strTemp.Append(param)
|
||||
Next
|
||||
|
||||
Return strTemp.ToString()
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 将字符串按格式转换为通讯格式数据对象
|
||||
''' </summary>
|
||||
''' <param name="dataParamString">uts通讯字符串</param>
|
||||
''' <param name="separator">组合命令分隔符</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ConvertFromString(dataParamString As String, Optional separator As Char = ":"c) As UtsComPortData
|
||||
Dim strings() As String
|
||||
strings = dataParamString.ToUpper().Split(separator)
|
||||
If strings.Length < 3 Then Throw New Exception($"FromString:非法字符串,{dataParamString}")
|
||||
|
||||
Dim dataParam As New UtsComPortData
|
||||
dataParam.SenderAddress = strings(0)
|
||||
dataParam.ReceiverAddress = strings(1)
|
||||
dataParam.Command = strings(2)
|
||||
|
||||
For idx As Integer = 3 To strings.Length - 1
|
||||
dataParam.Params.Add(strings(idx))
|
||||
Next
|
||||
|
||||
Return dataParam
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' 解析uts通讯字符串,初始化内部数据
|
||||
''' </summary>
|
||||
''' <param name="dataParamString"></param>
|
||||
Public Sub FromString(dataParamString As String)
|
||||
Dim strings() As String
|
||||
strings = dataParamString.ToUpper().Split(_separator)
|
||||
If strings.Length < 3 Then Throw New Exception($"FromString:非法字符串,{dataParamString}")
|
||||
|
||||
SenderAddress = strings(0)
|
||||
ReceiverAddress = strings(1)
|
||||
Command = strings(2)
|
||||
|
||||
Params.Clear()
|
||||
For idx As Integer = 3 To strings.Length - 1
|
||||
Params.Add(strings(idx))
|
||||
Next
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' 将本地数据内容,转换为uts通讯字符串
|
||||
''' </summary>
|
||||
''' <returns></returns>
|
||||
Public Overrides Function ToString() As String
|
||||
Return ConvertToString(SenderAddress, ReceiverAddress, Command, Params, _separator)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
541
UTS_Core/UTSModule/Test/UtsComportTask.vb
Normal file
541
UTS_Core/UTSModule/Test/UtsComportTask.vb
Normal file
@@ -0,0 +1,541 @@
|
||||
Imports System.Threading
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.TestStatusMonitor
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.ComportStatusMonitor
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.UtsKeyValueMonitor
|
||||
Imports UTS_Core.UTSModule.Test.StatusMonitor.TestCommandStatusMonitor
|
||||
Imports UTS_Core.DebugLog
|
||||
|
||||
Namespace UTSModule.Test
|
||||
Public Class UtsComportTask
|
||||
|
||||
#Region "测试命令交互模块"
|
||||
Private Shared _sendErrorCount As Integer
|
||||
|
||||
Public Shared SendErrorMaxCount As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令接收等待最长时间
|
||||
''' </summary>
|
||||
Public Shared TestWaitReplyMaxTime As Integer = 300
|
||||
|
||||
''' <summary>
|
||||
''' 期望回复的测试命令。发送测试命令后,判断串口接收是否为指定命令的回复数据
|
||||
''' </summary>
|
||||
Public Shared ExpectReplyTestCommand As String = ""
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 需要发送的测试命令
|
||||
''' </summary>
|
||||
Public Shared TestSendData As UtsComPortData
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 接收测试命令
|
||||
''' </summary>
|
||||
Public Shared TestReceiveData As UtsComPortData
|
||||
|
||||
''' <summary>
|
||||
''' 测试命令仅发送,不需要接受
|
||||
''' </summary>
|
||||
Private Shared TestOnlySend As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 提供发送测试命令统一接口
|
||||
''' </summary>
|
||||
Public Shared Function SendTestCommand(sendData As UtsComPortData, Optional onlySend As Boolean = False) As TestCommandStatusEnum
|
||||
'多线程,等待上一个线程完成收发
|
||||
|
||||
If ComportStatus <> ComPortConnectStatusEnum.Connected Then '串口未连接
|
||||
TestCommandStatus = TestCommandStatusEnum.SendingFailure
|
||||
Return TestCommandStatus
|
||||
End If
|
||||
|
||||
TestOnlySend = onlySend
|
||||
TestSendData = sendData
|
||||
TestReceiveData = Nothing '清空接收数据
|
||||
TestCommandStatus = TestCommandStatusEnum.WaitingToSend
|
||||
|
||||
While TestCommandStatus = TestCommandStatusEnum.WaitingToSend
|
||||
|
||||
If ComportStatus <> ComPortConnectStatusEnum.Connected Then
|
||||
TestCommandStatus = TestCommandStatusEnum.SendingFailure
|
||||
Exit While
|
||||
End If
|
||||
|
||||
Thread.Sleep(5)
|
||||
End While
|
||||
|
||||
Return TestCommandStatus
|
||||
End Function
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 提供测试命令接收完成统一接口
|
||||
''' </summary>
|
||||
''' <param name="timeout">超时接收时间</param>
|
||||
''' <param name="receiveData">接收到的数据</param>
|
||||
''' <returns></returns>
|
||||
Public Shared Function ReceivedTestCommandReturn(timeout As Integer, ByRef receiveData As UtsComPortData) As TestCommandStatusEnum
|
||||
Dim watch As New Stopwatch
|
||||
watch.Start()
|
||||
|
||||
TestWaitReplyMaxTime = timeout '更新回复超时时间
|
||||
timeout += 500 '由于测试执行与任务执行有差异,超时时间增加一定时间等待串口任务返回结果
|
||||
Dim result As TestCommandStatusEnum
|
||||
While TestCommandStatus = TestCommandStatusEnum.WaitingToReceive AndAlso watch.ElapsedMilliseconds <= timeout
|
||||
Thread.Sleep(5)
|
||||
End While
|
||||
watch.Stop()
|
||||
result = TestCommandStatus
|
||||
receiveData = TestReceiveData
|
||||
TestCommandStatus = TestCommandStatusEnum.None
|
||||
|
||||
Return result
|
||||
End Function
|
||||
|
||||
#End Region
|
||||
|
||||
|
||||
#Region "任务内部状态机模块"
|
||||
''' <summary>
|
||||
''' 串口状态枚举
|
||||
''' </summary>
|
||||
Enum ComportStatusEnum
|
||||
''' <summary>
|
||||
''' 未开启或已退出
|
||||
''' </summary>
|
||||
Quit
|
||||
|
||||
''' <summary>
|
||||
''' 入口
|
||||
''' </summary>
|
||||
Idle
|
||||
|
||||
''' <summary>
|
||||
''' 获取串口设备
|
||||
''' </summary>
|
||||
GetComport
|
||||
|
||||
''' <summary>
|
||||
''' 发送同步命令
|
||||
''' </summary>
|
||||
SendHeartBeat
|
||||
|
||||
''' <summary>
|
||||
''' 等待回复
|
||||
''' </summary>
|
||||
WaitReply
|
||||
|
||||
''' <summary>
|
||||
''' 键值回复
|
||||
''' </summary>
|
||||
ReplyKeyStatusAck
|
||||
|
||||
''' <summary>
|
||||
''' 发送测试命令
|
||||
''' </summary>
|
||||
SendCommand
|
||||
|
||||
''' <summary>
|
||||
''' 连接成功
|
||||
''' </summary>
|
||||
ComportConnected
|
||||
|
||||
''' <summary>
|
||||
''' 连接失败
|
||||
''' </summary>
|
||||
ComportDisconnected
|
||||
End Enum
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口任务状态,根据状态不同进行不同的串口操作
|
||||
''' </summary>
|
||||
Public Shared ComportTaskStatus As ComportStatusEnum
|
||||
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 发送同步命令的时间
|
||||
''' </summary>
|
||||
Public Shared SendSyncTime As DateTime
|
||||
|
||||
''' <summary>
|
||||
''' 已发送通讯数据,等待回复的时间
|
||||
''' </summary>
|
||||
Public Shared WaitReplyStartTime As DateTime
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 发送同步命令的间隔时间(ms)
|
||||
''' </summary>
|
||||
Public Shared SendSyncInterval As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 测试状态是否发生变化
|
||||
''' </summary>
|
||||
Public Shared TestStatusChanged As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 是否收到按键主动数据,需要回复ACK
|
||||
''' </summary>
|
||||
Public Shared WaitReplyKeyStatusAck As Boolean
|
||||
|
||||
''' <summary>
|
||||
''' 状态机执行间隔,默认10ms
|
||||
''' </summary>
|
||||
Public Shared StateMachineInterval As Integer
|
||||
|
||||
''' <summary>
|
||||
''' 当前可以访问的串口名集合
|
||||
''' </summary>
|
||||
Private Shared ReadOnly ComportNames As New Queue(Of String)
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 当前串口对象
|
||||
''' </summary>
|
||||
Public Shared Conn As New UtsComPort
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' UTS串口波特率
|
||||
''' </summary>
|
||||
Public Shared ComportBaudRate As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 接收等待最长时间
|
||||
''' </summary>
|
||||
Public Shared NormalWaitReplyMaxTime As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口通讯写入失败计数
|
||||
''' </summary>
|
||||
Public Shared ComportWriteFailCount As Integer
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口通讯写入失败最大上限
|
||||
''' </summary>
|
||||
Public Shared ComportWriteMaxFailCount As Integer
|
||||
|
||||
Public Sub New()
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 处理高优先级接收数据
|
||||
''' 当前包含按键键值与测试状态回复包等数据
|
||||
''' </summary>
|
||||
Private Shared Sub DealPriorityData()
|
||||
If Conn.CacheData.Count = 0 Then Return
|
||||
|
||||
For i As Integer = 0 To Conn.CacheData.Count - 1
|
||||
Dim receivedData As UtsComPortData = Conn.CacheData.Peek()
|
||||
|
||||
If String.Compare(receivedData.ReceiverAddress, DeviceAddress.LocalAddress(), True) <> 0 Then
|
||||
Conn.CacheData.Dequeue() '移除头部
|
||||
Continue For
|
||||
End If
|
||||
|
||||
'处理自发上报通讯数据
|
||||
If String.Compare(receivedData.Command, "KEY_EVENT", True) = 0 Then '按键按下
|
||||
Dim tmp As UtsKeyValueEnum = UtsKeyValueEnum.None
|
||||
If [Enum].TryParse(receivedData.Params(0), tmp) Then
|
||||
UtsKeyValue = tmp
|
||||
WaitReplyKeyStatusAck = True '需要回复键值包ACK
|
||||
End If
|
||||
Conn.CacheData.Dequeue() '移除头部
|
||||
Else
|
||||
If ComportTaskStatus = ComportStatusEnum.WaitReply Then
|
||||
Continue For
|
||||
Else
|
||||
Conn.CacheData.Dequeue() '移除头部
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' UTS串口任务状态机
|
||||
''' </summary>
|
||||
Private Shared Sub UtsComportTask()
|
||||
DealPriorityData() '处理非测试命令数据
|
||||
|
||||
Select Case ComportTaskStatus
|
||||
Case ComportStatusEnum.Idle '空闲状态
|
||||
Idle()
|
||||
Case ComportStatusEnum.GetComport '获取串口
|
||||
Thread.Sleep(200) '避免串口打开操作过于频繁
|
||||
GetComport()
|
||||
Case ComportStatusEnum.ComportConnected '串口连接成功
|
||||
ComportConnected()
|
||||
Case ComportStatusEnum.ComportDisconnected '串口断开连接
|
||||
ComportDisconnected()
|
||||
Case ComportStatusEnum.SendHeartBeat '发送同步状态包
|
||||
SendHeartBeat()
|
||||
Case ComportStatusEnum.ReplyKeyStatusAck '回复按键状态
|
||||
ReplyKeyStatusAck()
|
||||
Case ComportStatusEnum.SendCommand '发送测试命令
|
||||
SendCommand()
|
||||
Case ComportStatusEnum.WaitReply '等待回复
|
||||
WaitReply()
|
||||
Case ComportStatusEnum.Quit '退出串口任务
|
||||
'todo:完善串口退出逻辑
|
||||
Case Else
|
||||
OtherComportStatus()
|
||||
End Select
|
||||
End Sub
|
||||
|
||||
Private Shared Sub Idle()
|
||||
If ComportStatus = ComPortConnectStatusEnum.Connected Then
|
||||
'有测试命令需要下发
|
||||
If TestCommandStatus = TestCommandStatusEnum.WaitingToSend Then
|
||||
ComportTaskStatus = ComportStatusEnum.SendCommand
|
||||
Return
|
||||
End If
|
||||
|
||||
'收到按键状态命令,需要回复ACK
|
||||
If WaitReplyKeyStatusAck Then
|
||||
WaitReplyKeyStatusAck = False
|
||||
ComportTaskStatus = ComportStatusEnum.ReplyKeyStatusAck
|
||||
Return
|
||||
End If
|
||||
|
||||
'测试状态变化,需要发送状态变化指令
|
||||
If TestStatusChanged Then
|
||||
TestStatusChanged = False
|
||||
ComportTaskStatus = ComportStatusEnum.SendHeartBeat
|
||||
Return
|
||||
End If
|
||||
|
||||
'定期发送Sync命令
|
||||
Static span As TimeSpan
|
||||
span = Now - SendSyncTime
|
||||
If span.TotalMilliseconds >= SendSyncInterval Then
|
||||
ComportTaskStatus = ComportStatusEnum.SendHeartBeat '发送同步命令
|
||||
Return
|
||||
End If
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.GetComport '获取设备
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub GetComport()
|
||||
ComportStatus = ComPortConnectStatusEnum.Connecting
|
||||
|
||||
If ComportNames.Count > 0 Then
|
||||
Dim comportName As String = ComportNames.Dequeue()
|
||||
|
||||
If Conn.OpenSerialPort(comportName, ComportBaudRate) = False Then Return
|
||||
|
||||
'发送询问包
|
||||
Dim sendData As New UtsComPortData(DeviceAddress.UtsHw03Address, "*IDN?")
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
_sendErrorCount = 0
|
||||
WaitReplyStartTime = Now
|
||||
ComportTaskStatus = ComportStatusEnum.WaitReply
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
Else
|
||||
For Each comportName As String In UtsComPort.GetPortNames()
|
||||
ComportNames.Enqueue(comportName) '添加可用串口列表
|
||||
Next
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub ComportConnected()
|
||||
ComportStatus = ComPortConnectStatusEnum.Connected
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End Sub
|
||||
|
||||
Private Shared Sub ComportDisconnected()
|
||||
ComportStatus = ComPortConnectStatusEnum.UnConnected
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
UtsTester.CreateTester.RerunSetupModule()
|
||||
End Sub
|
||||
|
||||
Private Shared Sub SendHeartBeat()
|
||||
Dim str As String = Choose(TestStatus + 1, "IDEL", "TESTING", "PASS", "FAIL", "DevError").ToString()
|
||||
Dim sendData As New UtsComPortData(DeviceAddress.UtsHw03Address, "TEST_STATUS", str)
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
_sendErrorCount = 0
|
||||
SendSyncTime = Now '有数据通讯,发送同步命令时间更新
|
||||
|
||||
WaitReplyStartTime = Now
|
||||
ComportTaskStatus = ComportStatusEnum.WaitReply
|
||||
Else
|
||||
_sendErrorCount += 1
|
||||
If _sendErrorCount >= SendErrorMaxCount Then
|
||||
_sendErrorCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.ComportDisconnected
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub ReplyKeyStatusAck()
|
||||
Dim sendData As New UtsComPortData(DeviceAddress.UtsHw03Address, "KEY_EVENT", "TRUE")
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
_sendErrorCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
Else
|
||||
_sendErrorCount += 1
|
||||
If _sendErrorCount >= SendErrorMaxCount Then
|
||||
_sendErrorCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.ComportDisconnected
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub SendCommand()
|
||||
Dim sendData As UtsComPortData = TestSendData
|
||||
If sendData Is Nothing Then
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
Return
|
||||
End If
|
||||
|
||||
ExpectReplyTestCommand = sendData.Command '期望回复的命令
|
||||
|
||||
If Conn.SendTextAppendCrLf(sendData) Then
|
||||
_sendErrorCount = 0
|
||||
|
||||
If TestOnlySend Then '仅发送数据,不接受回复信息
|
||||
WaitReplyStartTime = Now '更新等待接收的起始时间
|
||||
TestCommandStatus = TestCommandStatusEnum.ReceiveCompleted '接收完成
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
Else
|
||||
WaitReplyStartTime = Now '更新等待接收的起始时间
|
||||
TestCommandStatus = TestCommandStatusEnum.WaitingToReceive '等待接收
|
||||
ComportTaskStatus = ComportStatusEnum.WaitReply
|
||||
End If
|
||||
Else
|
||||
TestCommandStatus = TestCommandStatusEnum.SendingFailure '发送失败
|
||||
|
||||
_sendErrorCount += 1
|
||||
If _sendErrorCount >= SendErrorMaxCount Then
|
||||
_sendErrorCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.ComportDisconnected
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub WaitReply()
|
||||
Dim timeout As Integer
|
||||
If TestCommandStatus = TestCommandStatusEnum.WaitingToReceive Then
|
||||
timeout = TestWaitReplyMaxTime
|
||||
Else
|
||||
timeout = NormalWaitReplyMaxTime
|
||||
End If
|
||||
|
||||
Dim span As TimeSpan = Now - WaitReplyStartTime
|
||||
If span.TotalMilliseconds > timeout Then '超时
|
||||
If TestCommandStatus = TestCommandStatusEnum.WaitingToReceive Then
|
||||
TestCommandStatus = TestCommandStatusEnum.ReceiveTimeout '测试命令接收超时
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
Else
|
||||
If ComportTaskStatus = ComportStatusEnum.ComportConnected Then
|
||||
ComportWriteFailCount += 1
|
||||
If ComportWriteFailCount >= ComportWriteMaxFailCount Then '超过写入失败上限
|
||||
ComportWriteFailCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.ComportDisconnected
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
Else
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End If
|
||||
End If
|
||||
Else
|
||||
If Conn.CacheData.Count <= 0 Then Return
|
||||
Dim receivedData As UtsComPortData = Conn.CacheData.Dequeue() '接收数据
|
||||
|
||||
If receivedData Is Nothing Then
|
||||
ApplicationLog.WriteInfoLog("异常的接收信息进入缓存队列!")
|
||||
Return
|
||||
End If
|
||||
|
||||
If String.Compare(receivedData.Command, ExpectReplyTestCommand, True) = 0 Then
|
||||
TestCommandStatus = TestCommandStatusEnum.ReceiveCompleted
|
||||
TestReceiveData = receivedData
|
||||
|
||||
ComportWriteFailCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
ElseIf String.Compare(receivedData.Command, "TEST_STATUS", True) = 0 Then '测试结果变更回复
|
||||
ComportWriteFailCount = 0
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
|
||||
ElseIf String.Compare(receivedData.Command, "*IDN?", True) = 0 Then '测试结果变更回复
|
||||
If receivedData.Params.Count = 0 Then Return
|
||||
If String.Compare(receivedData.Params(0), "uts-hw03-rev10a", True) = 0 Then
|
||||
ComportTaskStatus = ComportStatusEnum.ComportConnected
|
||||
End If
|
||||
Else
|
||||
'其他系统命令
|
||||
End If
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Shared Sub OtherComportStatus()
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
End Sub
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' 串口任务,包含索引串口,发送数据,接收数据
|
||||
''' </summary>
|
||||
Public Shared Sub StartTask()
|
||||
If ComportTaskStatus <> ComportStatusEnum.Quit Then Return
|
||||
|
||||
'初始化
|
||||
SendSyncTime = Now
|
||||
SendSyncInterval = 1000
|
||||
ComportTaskStatus = ComportStatusEnum.Idle
|
||||
|
||||
ComportBaudRate = 115200
|
||||
NormalWaitReplyMaxTime = 300
|
||||
ComportWriteMaxFailCount = 2
|
||||
_sendErrorCount = 0
|
||||
SendErrorMaxCount = 3
|
||||
|
||||
StateMachineInterval = 10
|
||||
|
||||
Try
|
||||
'状态机执行
|
||||
While ComportTaskStatus <> ComportStatusEnum.Quit
|
||||
UtsComportTask()
|
||||
|
||||
Thread.Sleep(StateMachineInterval)
|
||||
End While
|
||||
Catch ex As Exception
|
||||
MsgBox($"测试器致命错误,{ex}")
|
||||
ApplicationLog.WriteFatalLog($"测试器致命错误,{ex}")
|
||||
End Try
|
||||
|
||||
|
||||
'状态机退出
|
||||
Conn.CloseSerialPort()
|
||||
End Sub
|
||||
|
||||
Public Shared Sub EndTask()
|
||||
ComportTaskStatus = ComportStatusEnum.Quit
|
||||
End Sub
|
||||
#End Region
|
||||
|
||||
End Class
|
||||
End Namespace
|
||||
1339
UTS_Core/UTSModule/Test/UtsTester.vb
Normal file
1339
UTS_Core/UTSModule/Test/UtsTester.vb
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user