Static V As Integer
If vars("kln") = 1 Then
Dim ck As String = Functions.Execute("GET","串口号","LLNJ","值")
Dim dll As String = Functions.Execute("GET","地址","拉力","值")
Dim dnj As String = Functions.Execute("GET","地址","扭矩","值")
Dim dzs As String = Functions.Execute("GET","地址","转速","值")
If ck > "" Then
If Ports.Contains(ck) Then
If Ports(ck).IsOpen Then
If Forms("主窗口").Opened Then
'解析接收数据
If vars("jsln") = 1 Or vars("jsln") = 2 Or vars("jsln") = 3 Then
Dim jssj As String
Select Case vars("jsln")
Case 1
jssj = vars("sj1")
Case 2
jssj = vars("sj2")
Case 3
jssj = vars("sj3")
End Select
If jssj > "" Then
If jssj.StartsWith(dll & "-3-4-") Then
Dim VL() As String = jssj.split("-")
If VL.Length = 9 Then
Dim s,str As String
Dim v1 As Integer
s = DecToBin(VL(3)).PadLeft(8,"0") & DecToBin(VL(4)).PadLeft(8,"0") & DecToBin(VL(5)).PadLeft(8,"0") & DecToBin(VL(6)).PadLeft(8,"0")
Dim bmlx As String = Functions.Execute("GET","编码类型","拉力","值")
v1 = Functions.Execute("SN",s,bmlx)
Dim bl As Double = Val(Functions.Execute("GET","分辨率","拉力","值"))
Dim vv As Double = v1 * bl
If math.Abs(vv) < Val(Functions.Execute("GET","极限值","拉力","值")) Then
Forms("主窗口").Controls("ll").text = vv
End If
End If
ElseIf jssj.StartsWith(dnj & "-3-4-") Then
Dim VL() As String = jssj.split("-")
If VL.Length = 9 Then
Dim s,str As String
Dim v1 As Integer
s = DecToBin(VL(3)).PadLeft(8,"0") & DecToBin(VL(4)).PadLeft(8,"0") & DecToBin(VL(5)).PadLeft(8,"0") & DecToBin(VL(6)).PadLeft(8,"0")
Dim bmlx As String = Functions.Execute("GET","编码类型","扭矩","值")
v1 = Functions.Execute("SN",s,bmlx)
Dim bl As Double = Val(Functions.Execute("GET","分辨率","扭矩","值"))
Dim vv As Double = v1 * bl
If math.Abs(vv) < Val(Functions.Execute("GET","极限值","扭矩","值")) Then
Forms("主窗口").Controls("nj").text = vv
End If
End If
ElseIf jssj.StartsWith(dzs & "-3-4-") Then
Dim VL() As String = jssj.split("-")
If VL.Length = 9 Then
Dim s,str As String
Dim v1 As Integer
s = DecToBin(VL(3)).PadLeft(8,"0") & DecToBin(VL(4)).PadLeft(8,"0")
v1 = BinToDec(s)
Dim bl As Double = Val(Functions.Execute("GET","分辨率","转速","值"))
Dim vv As Double = v1 * bl
If math.Abs(vv) < Val(Functions.Execute("GET","极限值","转速","值")) Then
Forms("主窗口").Controls("zs").text = vv
End If
End If
End If
End If
End If
'发送查询命令
If V < 1 Or V > 2 Then
V = 1
Else
V = V + 1
End If
vars("jsln") = V
vars("sj" & V) = Nothing
Dim ff As uInteger() = {&H0 & V,&H03,&H00,&H00,&H00,&H02}
Dim aa As Integer = CRC16(ff,ff.Length)
Dim crc As String = DecToHex(aa).ToUpper()
crc = crc.PadLeft(4,"0")
Dim crcl As Integer = HexToDec(crc.SubString(2,2))
Dim crch As Integer = HexToDec(crc.SubString(0,2))
Dim Vln() As Byte = New Byte() {V,3,0,0,0,2,crcl,crch}
Ports(ck).Write(Vln, 0, Vln.Length)
End If
End If
End If
End If
End If