Private Sub Form_Load()
Comm1.Setting="9600,n,8,1," 设置波特率和发送字符格式
Comm1.CommPort=1 设置通讯串口
Comm1.InputLen=0 设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
Comm1.InBuffersize=512
Comm1.InBufferCount=0
Comm1.OutBufferCount=0
Comm1.Rthreshold=1
Comm1.PortOpen=True
End Sub 打开串口
----------------------------给单片机发送'S',开始通信-----------------------
Private Sub Command1_C1ick()
Timer1.Enabled=True
End Sub
Private Sub Command2_C1ick()
Varbuffet="S"
Comm1.Ouput=varbuffe
Timer2.Enabled=True
End Sub
Private Sub Form_Unload(Cancel AS Integer)
Comm1.PortOpen=False
End Sub
--------------------------向单片机发送数据----------------------------
Private Sub Timer2_Timer()
Outputsignal=Str(Text2.text)
Temp(1)=Cbyte(outputsignal)
Varbuffer=temp
Comm1.Output=varbuffer
Time2.Enabled=False
End Sub
-------------------------接收单片机发送的数据,并显示------------------------
Private Sub Comm1_OnComm()
Select Case Comm1.CommEvent 设置oncomm事件,读取单片机内存的值
Case comEvReceive
Inputsignal=comm1.Input
Text1.Text=Asc(Inputsignal) 单片机内存的值用textbox显示出
Case Else
End select
End Sub
|