Dim i, j As Integer
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
With MSComm1
.InputMode = 1 '设置接受数据的类型是二进制类型数据
' .InputLen = 8 '一次性从接收缓冲区中读取所有数据(8个字节为一组!!)
.InBufferCount = 0 '清空接收缓冲区
.OutBufferCount = 0 '清空发送缓冲区
.SThreshold = 0 '不触发OnComm()事件
' .RThreshold = 2 '触发OnComm()事件
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
i = 0
j = 0
End Sub
Private Sub MSComm1_OnComm()
'Sleep (50)
If MSComm1.CommEvent = 2 Then
MSComm1.RThreshold = 0
Buffer = MSComm1.Input ' 接收一个二进制数据
'arr(0) = AscB(Buffer) '存入到二进制数组数组中
Receive_Count_Byte = Receive_Count_Byte + 1
Text1(i).Text = i
'Text1(i).Text = Hex(Buffer(0)) & " " & Hex(Buffer(1)) & " " & Hex(Buffer(2)) & " " & Hex(Buffer(3))
'Real_Receive = arr(0) '
'Text1.Text = Text1.Text & Real_Receive & " " '接收的数据显示到文本框中
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
'MSComm1.PortOpen = False
'MSComm1.PortOpen = True
Else
Text1(i).Text = 0
End If
MSComm1.RThreshold = 2
i = i + 1
If i = 1 Then
' Call delay(2)
Call send_data1
End If
If i = 2 Then
' Call delay(2)
Call send_data2
End If
If i = 3 Then
' Call delay(2)
Call send_data3
End If
If i = 4 Then
' Call delay(2)
Call send_data4
End If
If i = 5 Then
' Call delay(2)
Call send_data5
End If
If i = 6 Then
' Call delay(2)
Call send_data6
End If
If i = 7 Then
' Call delay(2)
Call send_data7
End If
If i = 8 Then
i = 0
MSComm1.RThreshold = 0
For j = 0 To 7
If a(j) <> 0 Then
m_flag = m_flag + 1
End If
Next j
If m_flag = 8 Then
'往数据库更新数据
End If
End If
End Sub
' 29 DF FD 00
' 29 DB FD 00
Private Sub Timer1_Timer()
MSComm1.RThreshold = 2
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H10
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data1()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H11
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data2()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H12
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data3()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H13
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data4()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H14
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data5()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H15
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data6()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H16
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data7()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H17
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub delay(d) '延迟过程
T = Timer + d
Do While Timer < T '利用空循环实现延迟
Loop
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
With MSComm1
.InputMode = 1 '设置接受数据的类型是二进制类型数据
' .InputLen = 8 '一次性从接收缓冲区中读取所有数据(8个字节为一组!!)
.InBufferCount = 0 '清空接收缓冲区
.OutBufferCount = 0 '清空发送缓冲区
.SThreshold = 0 '不触发OnComm()事件
' .RThreshold = 2 '触发OnComm()事件
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
i = 0
j = 0
End Sub
Private Sub MSComm1_OnComm()
'Sleep (50)
If MSComm1.CommEvent = 2 Then
MSComm1.RThreshold = 0
Buffer = MSComm1.Input ' 接收一个二进制数据
'arr(0) = AscB(Buffer) '存入到二进制数组数组中
Receive_Count_Byte = Receive_Count_Byte + 1
Text1(i).Text = i
'Text1(i).Text = Hex(Buffer(0)) & " " & Hex(Buffer(1)) & " " & Hex(Buffer(2)) & " " & Hex(Buffer(3))
'Real_Receive = arr(0) '
'Text1.Text = Text1.Text & Real_Receive & " " '接收的数据显示到文本框中
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0
'MSComm1.PortOpen = False
'MSComm1.PortOpen = True
Else
Text1(i).Text = 0
End If
MSComm1.RThreshold = 2
i = i + 1
If i = 1 Then
' Call delay(2)
Call send_data1
End If
If i = 2 Then
' Call delay(2)
Call send_data2
End If
If i = 3 Then
' Call delay(2)
Call send_data3
End If
If i = 4 Then
' Call delay(2)
Call send_data4
End If
If i = 5 Then
' Call delay(2)
Call send_data5
End If
If i = 6 Then
' Call delay(2)
Call send_data6
End If
If i = 7 Then
' Call delay(2)
Call send_data7
End If
If i = 8 Then
i = 0
MSComm1.RThreshold = 0
For j = 0 To 7
If a(j) <> 0 Then
m_flag = m_flag + 1
End If
Next j
If m_flag = 8 Then
'往数据库更新数据
End If
End If
End Sub
' 29 DF FD 00
' 29 DB FD 00
Private Sub Timer1_Timer()
MSComm1.RThreshold = 2
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H10
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data1()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H11
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data2()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H12
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data3()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H13
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data4()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H14
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data5()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H15
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data6()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H16
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data7()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H17
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub delay(d) '延迟过程
T = Timer + d
Do While Timer < T '利用空循环实现延迟
Loop
End Sub
解决方案 »
- 今天才明白,VB原来是弱类型语言,虽然它是静态语言,但却是弱类型的
- 没办办法判断一张BMP是不是空的,即整张图,全部都是白色,基本没有其它色。
- 类模块
- --------测试因特网是否连通,以下代码在网络连通时也是提示不通,请帮忙测试。----------
- 问一个手机号码检查问题
- 各位大哥,怎样可以获取vb中的当前行的行数字?
- 高分求购比较好的VB程序(企业管理软件)的主界面!
- 有哪位兄台知道 VB6.0 的 DataGrid怎么改变背景颜色?
- 高分!快来!我想用VB做一个类似于excel那样的表格,而且是可以点击表格就可以修改内容
- 怎样在一个程序中调用.reg文件,就是双击它啊~!
- 求思路:VB摄像头计数
- 计算器程序设计
Option ExplicitDim i, j As Integer
Private Sub Command2_Click()
Unload Me
End Sub
Private Sub Command3_Click()
Form2.Show
End Sub
Private Sub Form_Load()
With MSComm1
.InputMode = 1 'ÉèÖýÓÊÜÊý¾ÝµÄÀàÐÍÊǶþ½øÖÆÀàÐÍÊý¾Ý
.InputLen = 1
.InBufferCount = 0 'Çå¿Õ½ÓÊÕ»º³åÇø
.OutBufferCount = 0 'Çå¿Õ·¢ËÍ»º³åÇø
.SThreshold = 0 '²»´¥·¢OnComm()ʼþ
.RThreshold = 1 '´¥·¢OnComm()ʼþ
.Settings = "9600,n,8,1"
.CommPort = 1
.PortOpen = True
End With
i = 0
j = 0
End Sub
Private Sub MSComm1_OnComm()
Dim varP As Variant
If MSComm1.CommEvent = 2 Then
MSComm1.RThreshold = 0
sleep 20
Do
varP = Null
varP = MSComm1.Input ' ½ÓÊÕÒ»¸ö¶þ½øÖÆÊý¾Ý
If Not IsNull(varP) Then Buffer = Val("&H" & varP(0))
'arr(0) = AscB(Buffer) '´æÈëµ½¶þ½øÖÆÊý×éÊý×éÖÐ
Receive_Count_Byte = Receive_Count_Byte + 1
Text1(i).Text = i
'Text1(i).Text = Hex(Buffer(0)) & " " & Hex(Buffer(1)) & " " & Hex(Buffer(2)) & " " & Hex(Buffer(3))
'Real_Receive = arr(0) '
'Text1.Text = Text1.Text & Real_Receive & " " '½ÓÊÕµÄÊý¾ÝÏÔʾµ½Îı¾¿òÖÐ
Loop Until MSComm1.InBufferCount = 0
' MSComm1.InBufferCount = 0
' MSComm1.OutBufferCount = 0
'MSComm1.PortOpen = False
'MSComm1.PortOpen = True
Else
Text1(i).Text = 0
End If
MSComm1.RThreshold = 2
i = i + 1
If i = 1 Then
' Call delay(2)
Call send_data1
End If
If i = 2 Then
' Call delay(2)
Call send_data2
End If
If i = 3 Then
' Call delay(2)
Call send_data3
End If
If i = 4 Then
' Call delay(2)
Call send_data4
End If
If i = 5 Then
' Call delay(2)
Call send_data5
End If
If i = 6 Then
' Call delay(2)
Call send_data6
End If
If i = 7 Then
' Call delay(2)
Call send_data7
End If
If i = 8 Then
i = 0
MSComm1.RThreshold = 0
For j = 0 To 7
If a(j) <> 0 Then
m_flag = m_flag + 1
End If
Next j
If m_flag = 8 Then
'ÍùÊý¾Ý¿â¸üÐÂÊý¾Ý
End If
End If
End Sub
' 29 DF FD 00
' 29 DB FD 00
Private Sub Timer1_Timer()
MSComm1.RThreshold = 2
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H10
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data1()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H11
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data2()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H12
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data3()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H13
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data4()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H14
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data5()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H15
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data6()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H16
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub send_data7()
Dim Send_Chr(3) As Byte
Dim Send_Data As String
Send_Chr(0) = &HF0
Send_Chr(1) = &H3
Send_Chr(2) = &H17
Send_Chr(3) = &H24
MSComm1.Output = Send_Chr
End Sub
Private Sub delay(d) 'ÑÓ³Ù¹ý³Ì
T = Timer + d
Do While Timer < T 'ÀûÓÿÕÑ»·ÊµÏÖÑÓ³Ù
Loop
End Sub
用这个试一试通信,依据它改写你的代码
http://download.csdn.net/detail/veron_04/1262066