J
jingtao
Unregistered / Unconfirmed
GUEST, unregistred user!
Dim letters_num As Byte
Dim letters(250, 2) As Byte
Dim output_data(0) As Byte
Dim checksum As Byte
Dim instringx(7) As String
Dim form_fg As Boolean
Private Sub Command1_Click()
Dim a1, a2, m, n, i
letters_num = Len(Text1.Text)
If letters_num > 0 Then
For i = 1 To letters_num
a1 = Asc(Mid((Text1.Text), i, 1))
a2 = a1 + 24159 + 256
m = Int(a2 / 256)
n = a2 - m * 256 + 1
letters(i - 1, 0) = m
letters(i - 1, 1) = n
Next i
' End If
' 将 attention 命令送到调制解调器。
comm_start:
output_data(0) = &HAA
MSComm1.Output = output_data
' 等待数据返回到串行端口。
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1
instring = MSComm1.Input
' 关闭串行端口。
i = Asc(instring)
If i <> &H8 Then
GoTo comm_start
Else
output_data(0) = letters_num
MSComm1.Output = output_data
checksum = letters_num
For i = 1 To letters_num
checksum = checksum Xor letters(i - 1, 0)
output_data(0) = letters(i - 1, 0)
MSComm1.Output = output_data
checksum = checksum Xor letters(i - 1, 1)
output_data(0) = letters(i - 1, 1)
MSComm1.Output = output_data
Next i
output_data(0) = checksum
MSComm1.Output = output_data
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1
instring = MSComm1.Input
End If
' MSComm1.PortOpen = False
End If
Do
Do
DoEvents
If Not (form_fg) Then
Exit Do
End If
Loop Until MSComm1.InBufferCount >= 1
instringx(0) = MSComm1.Input
' 关闭串行端口。
Text2.Text = instringx(0)
If Not (form_fg) Then
Exit Do
End If
Loop
MSComm1.PortOpen = False
Form1.Cls
Unload Form1
End Sub
Private Sub Command2_Click()
' MSComm1.CommPort = 1
' 19200 波特,无奇偶校验,8 位数据,一个停止位。
' MSComm1.Settings = "9600,N,8,1"
' MSComm1.InputLen = 0
' 打开端口。
' If MSComm1.CommPort Then
' Else
' MSComm1.PortOpen = True
' End If
' 将 attention 命令送到调制解调器。
' 等待数据返回到串行端口。
' Do
' DoEvents
' Loop Until MSComm1.InBufferCount >= 1
' instringx(0) = MSComm1.Input
' 关闭串行端口。
' Text2.Text = instringx(0)
form_fg = False
End Sub
Private Sub Form_Load()
Text1.Text = "测试字符叠加器程序,请按测试键,字符滚动,按5位数字键后,按确认键,看有否输入"
form_fg = True
MSComm1.CommPort = 1
' 19200 波特,无奇偶校验,8 位数据,一个停止位。
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
' 打开端口。
' If Not (MSComm1.CommPort) Then
' Else
MSComm1.PortOpen = True
' End If
End Sub
Dim letters(250, 2) As Byte
Dim output_data(0) As Byte
Dim checksum As Byte
Dim instringx(7) As String
Dim form_fg As Boolean
Private Sub Command1_Click()
Dim a1, a2, m, n, i
letters_num = Len(Text1.Text)
If letters_num > 0 Then
For i = 1 To letters_num
a1 = Asc(Mid((Text1.Text), i, 1))
a2 = a1 + 24159 + 256
m = Int(a2 / 256)
n = a2 - m * 256 + 1
letters(i - 1, 0) = m
letters(i - 1, 1) = n
Next i
' End If
' 将 attention 命令送到调制解调器。
comm_start:
output_data(0) = &HAA
MSComm1.Output = output_data
' 等待数据返回到串行端口。
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1
instring = MSComm1.Input
' 关闭串行端口。
i = Asc(instring)
If i <> &H8 Then
GoTo comm_start
Else
output_data(0) = letters_num
MSComm1.Output = output_data
checksum = letters_num
For i = 1 To letters_num
checksum = checksum Xor letters(i - 1, 0)
output_data(0) = letters(i - 1, 0)
MSComm1.Output = output_data
checksum = checksum Xor letters(i - 1, 1)
output_data(0) = letters(i - 1, 1)
MSComm1.Output = output_data
Next i
output_data(0) = checksum
MSComm1.Output = output_data
Do
DoEvents
Loop Until MSComm1.InBufferCount >= 1
instring = MSComm1.Input
End If
' MSComm1.PortOpen = False
End If
Do
Do
DoEvents
If Not (form_fg) Then
Exit Do
End If
Loop Until MSComm1.InBufferCount >= 1
instringx(0) = MSComm1.Input
' 关闭串行端口。
Text2.Text = instringx(0)
If Not (form_fg) Then
Exit Do
End If
Loop
MSComm1.PortOpen = False
Form1.Cls
Unload Form1
End Sub
Private Sub Command2_Click()
' MSComm1.CommPort = 1
' 19200 波特,无奇偶校验,8 位数据,一个停止位。
' MSComm1.Settings = "9600,N,8,1"
' MSComm1.InputLen = 0
' 打开端口。
' If MSComm1.CommPort Then
' Else
' MSComm1.PortOpen = True
' End If
' 将 attention 命令送到调制解调器。
' 等待数据返回到串行端口。
' Do
' DoEvents
' Loop Until MSComm1.InBufferCount >= 1
' instringx(0) = MSComm1.Input
' 关闭串行端口。
' Text2.Text = instringx(0)
form_fg = False
End Sub
Private Sub Form_Load()
Text1.Text = "测试字符叠加器程序,请按测试键,字符滚动,按5位数字键后,按确认键,看有否输入"
form_fg = True
MSComm1.CommPort = 1
' 19200 波特,无奇偶校验,8 位数据,一个停止位。
MSComm1.Settings = "9600,N,8,1"
MSComm1.InputLen = 0
' 打开端口。
' If Not (MSComm1.CommPort) Then
' Else
MSComm1.PortOpen = True
' End If
End Sub