Dim ck As String = args(0).ToUpper()
Dim btl As Integer
Dim dataBitsParam As Integer
Dim parityParam As Parity
Dim stopBitsParam As StopBits
Dim result As Integer = 0
' 尝试从args数组中获取对应参数,若获取失败或不符合要求则进行相应处理
If String.IsNullOrWhiteSpace(ck) OrElse Not Integer.TryParse(args(1), btl) OrElse btl <= 0 Then
' 参数无效,result 已设置为 0
Else
' 解析数据位参数,若解析失败则使用默认值8
If Not Integer.TryParse(args(2), dataBitsParam) Then
dataBitsParam = 8
End If
' 解析校验位参数,若解析失败则使用默认值Parity.None
If Not Enum.TryParse(args(3), parityParam) Then
parityParam = Parity.None
End If
' 解析停止位参数,若解析失败则使用默认值StopBits.One
If Not Enum.TryParse(args(4), stopBitsParam) Then
stopBitsParam = StopBits.One
End If
If Ports.ContainsKey(ck) Then
Ports(ck).Close()
Else
Ports.Add(ck)
End If
With Ports(ck)
.Parity = parityParam
.StopBits = stopBitsParam
.DataBits = dataBitsParam
.BaudRate = btl
.Handshake = Handshake.None
.ReadBufferSize = 2048
.WriteBufferSize = 1024
.Open()
End With
result = 1
End If
以上代码一直报错,请帮忙看一下!
If Not
[Enum
].TryParse(args(3), parityParam) Then