Private Declare Sub Sleep Lib "Kernel32" (ByVal NextRunProgramTimeAsMs As Long)
Private Sub Form_load()
With MSComm1
.CommPort = 3 '选择串口2
.Settings = "9600,n,8,1" '9.6kbit/s,无校验,8位数据位,1位停止位
.InputMode = comInputModeBinary '以二进制格式读取接收缓冲区
.RThreshold = 1 '接收字符数大于等于1就会产生接收中断
.InputLen = 0 '读出接收缓冲区中的所有内容
.OutBufferCount = 0 '清空发送缓冲区
.InBufferCount = 0 '清空接收缓冲区
.InputMode = comInputModeText
End With
End Sub
Private Sub Command1_Click()
MSComm1.PortOpen = True
End Sub
Private Sub Command2_Click()
MSComm1.Output = "SOUR:CURR:LEV 0.10000" & Chr(10)
Sleep (100)
MSComm1.Output = "SOUR:CURR:LEV?" & Chr(10)
Sleep (500)
MSComm1.Output = "SOUR:CURR:LEV 0.20000" & Chr(10)
Sleep (100)
MSComm1.Output = "SOUR:CURR:LEV?" & Chr(10)
Sleep (500)
MSComm1.Output = "SOUR:CURR:LEV 0.30000" & Chr(10)
Sleep (100)
MSComm1.Output = "SOUR:CURR:LEV?" & Chr(10)
Sleep (500)
MSComm1.Output = "SOUR:CURR:LEV 0.40000" & Chr(10)
Sleep (100)
MSComm1.Output = "SOUR:CURR:LEV?" & Chr(10)
Sleep (500)
MSComm1.Output = "SOUR:CURR:LEV 0.50000" & Chr(10)
Sleep (100)
MSComm1.Output = "SOUR:CURR:LEV?" & Chr(10)
End Sub
Private Sub MSComm1_OnComm() 'OnComm事件
Select Case MSComm1.CommEvent
Case comEvReceive '如果接收到字符
Sleep (50)
Text1.Text() = MSComm1.Input
Debug.Print Text1.Text()
Open "c:\1.txt" For Append As #1
Print #1, Text1.Text()
Close #1
End Select
End Sub