Dim zl As WinForm.TextBox = e.Form.Controls("TextBox1")
Dim zls2 As WinForm.TextBox = e.Form.Controls("TextBox2")
Dim zls3 As WinForm.TextBox = e.Form.Controls("TextBox3")
Dim zls As String = zl.value
zls = zls.replace(" ", "")
Dim zl1 As UInteger = CUInt( zls.substring(0, 2))
Dim zl2 As UInteger = CUInt( zls.substring(2, 2))
Dim zl3 As UInteger = CUInt( zls.substring(4, 2))
Dim zl4 As UInteger = CUInt( zls.substring(6, 2))
Dim zl5 As UInteger = CUInt( zls.substring(8, 2))
Dim zl6 As UInteger = CUInt( zls.substring(10, 2))
Dim aaff As UInteger() = { zl1, zl2, zl3, zl4, zl5, zl6}
Dim aa As Integer = CRC16(aaff, aaff.Length) ,这个是计算效验码的,计算没有问题是可以和串口助手对上了。
Dim bb As String = Convert.ToString(aa, 16).ToUpper()
Dim zl7 As Byte = CByte(bb.substring(0, 2))
Dim zl8 As Byte = CByte(bb.substring(2, 2))
Dim zl11 As Byte = CByte(zls.substring(0, 2))
Dim zl22 As Byte = CByte(zls.substring(2, 2))
Dim zl33 As Byte = CByte(zls.substring(4, 2))
Dim zl44 As Byte = CByte(zls.substring(6, 2))
Dim zl55 As Byte = CByte(zls.substring(8, 2))
Dim zl66 As Byte = CByte(zls.substring(10, 2))
Dim Val() As Byte = New Byte() {zl11, zl22, zl33, zl44, zl55, zl66, zl7, zl8}
Ports("COM6").Write(Val, 0, Val.Length)
zls2.value = zls & bb
Dim s2 As String
s2 = s2 & Ports("COM6").ReadExisting()
zls3.Value = s2