发表于:2006/6/17 8:58:00
#0楼
要求:用VB编写程序,采集电子数显千分表的数据,放入list1中,以备处理。
数显表的接口参数:波特率 4800,数据位8位,无奇偶校检,1位停止位,以ACSII 码传送数据,
可能要每隔几秒采集一次数据。数显表的专用接口线与计算机RS232(9针)连接。
问题:用下面这个程序运行没反应或者全是0,怎么延时?怎么放数据到list中?
由于刚接触VB,下面这个程序是拼凑起来的,可能很离谱,希望帮忙改正。
Dim receive_data(1 To 20) As Byte
Private Sub Command1_Click()
For i = 1 To 20
List1.AddItem Val(receive_data(i))
Next i
End Sub '把采集到的数据放入list1中
Private Sub Command2_Click()
MSComm1.PortOpen = flase
End
End Sub '结束
Private Sub MSComm1_OnComm()
Dim InBuffer As Valiant
Select Case MSComml.CommEvent
Case comEvReceive
Do Until MSComml.InBuffeiCount <> 0
Ret = DoEvents()
Loop
InBuffer = MSComml.Input
receive_data = InBuffer
End Select
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
MSComm1.CommPort = 1
MSComm1.Settings = "4800,n,8,1"
MSComm1.InBufferSize = 40
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 1
MSComm1.InBufferCount = 0
End Sub
数显表的接口参数:波特率 4800,数据位8位,无奇偶校检,1位停止位,以ACSII 码传送数据,
可能要每隔几秒采集一次数据。数显表的专用接口线与计算机RS232(9针)连接。
问题:用下面这个程序运行没反应或者全是0,怎么延时?怎么放数据到list中?
由于刚接触VB,下面这个程序是拼凑起来的,可能很离谱,希望帮忙改正。
Dim receive_data(1 To 20) As Byte
Private Sub Command1_Click()
For i = 1 To 20
List1.AddItem Val(receive_data(i))
Next i
End Sub '把采集到的数据放入list1中
Private Sub Command2_Click()
MSComm1.PortOpen = flase
End
End Sub '结束
Private Sub MSComm1_OnComm()
Dim InBuffer As Valiant
Select Case MSComml.CommEvent
Case comEvReceive
Do Until MSComml.InBuffeiCount <> 0
Ret = DoEvents()
Loop
InBuffer = MSComml.Input
receive_data = InBuffer
End Select
End Sub
Private Sub Form_Load()
MSComm1.PortOpen = True
MSComm1.CommPort = 1
MSComm1.Settings = "4800,n,8,1"
MSComm1.InBufferSize = 40
MSComm1.InputMode = comInputModeBinary
MSComm1.InputLen = 1
MSComm1.InBufferCount = 0
End Sub
www.robotain.com,机器与智能网做专业的机器人网站