VB 控件MOSComm SBUF 显示的问题
单片机与PC机通信的,就是PC机显示的问题.现在程序如下:Private Sub Form_Load()
MSComm1.Settings = "9600,n,8,1" '设置波特率和发送字符格式
MSComm1.CommPort = 1 '设置通讯串口
MSComm1.InputLen = 0 '设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.OutBufferSize = 1024
MSComm1.OutBufferCount = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub Cmdsend_Click()
Timer1.Enabled = True
'Varbuffet = "S"
' MSComm1.Output = Varbuffet
End Sub
Private Sub Timer1_Timer()
Varbuffet = "S"
MSComm1.Output = Varbuffet
Timer1.Enabled = False
End Sub
'Private Sub Timer1_Timer()
'Outputsignal = Str(Textsend.Text) '向单片机发送数据
'Temp(1) = CByte(Outputsignal)
'Varbuffer = Temp
'MSComml.Output = Varbuffer
'MSComml.Output = Str(Textsend.Text)
'Timer1.Enabled = False
'End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent '设置oncomm事件,读取片机内存的值
Case comEvReceive
Inputsignal = MSComm1.Input
TextReceive.Text = Asc(Inputsignal) '单片机内存的值用textbox显示出
Case Else
End Select
End Sub
Private Sub Cmdquit_Click()
'MSComml.PortOpen = Fasle
Unload Me
End Sub
单片机发送 0 1 2 3 让PC机显示,怎样才能显示0123(一起显示),而不是 0 1 2 3覆盖着显示.现在是显示0,在显示1, 显示2,显示3 而不是0123一起显示.谢谢!
--------------------编程问答--------------------
Private Sub Form_Load()--------------------编程问答-------------------- 好象不行,显示的是乱码
MSComm1.Settings = "9600,n,8,1" '设置波特率和发送字符格式
MSComm1.CommPort = 1 '设置通讯串口
MSComm1.InputMode = comInputModeText
MSComm1.InputLen = 0 '设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.OutBufferSize = 1024
MSComm1.OutBufferCount = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub MsComm1_OnComm()
Dim Inputsignal As Variant
Select Case MSComm1.CommEvent '设置oncomm事件,读取片机内存的值
Case comEvReceive
Inputsignal = MSComm1.Input
TextReceive.Text = Inputsignal '单片机内存的值用textbox显示出
End Select
End Sub
Private Sub Cmdquit_Click()
End
End Sub
--------------------编程问答-------------------- 请说明你单片机发送的确实是ASCII字符吗?
如果不是,则需按2进制接收. --------------------编程问答-------------------- 单片机发送的是十进制字符,发送的是 0 1 2 3,原来程序接受的是0 1 2 3
能不能加你的QQ啊?谢谢
--------------------编程问答--------------------
Private Sub Form_Load()--------------------编程问答-------------------- 还是不行,显示的是00102030000010203000102030....一直显示下去,没有覆盖,只有换行 --------------------编程问答-------------------- LZ:
MSComm1.Settings = "9600,n,8,1" '设置波特率和发送字符格式
MSComm1.CommPort = 1 '设置通讯串口
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.InputLen = 0 '设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
MSComm1.InBufferSize = 1024
MSComm1.InBufferCount = 0
MSComm1.OutBufferSize = 1024
MSComm1.OutBufferCount = 0
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
TextReceive.Text = ""
If MSComm1.PortOpen = False Then
MSComm1.PortOpen = True
End If
End Sub
Private Sub MsComm1_OnComm()
Dim Inputsignal As Variant
Dim intByte() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent '设置oncomm事件,读取片机内存的值
Case comEvReceive
Inputsignal = MSComm1.Input
intByte() = Inputsignal
For i = 0 To UBound(intByte)
If Len(Hex(intByte(i))) = 1 Then
TextReceive.Text = TextReceive.Text & "0" & Hex(intByte(i)) '单片机内存的值用textbox显示出
Else
TextReceive.Text = TextReceive.Text & Hex(intByte(i)) '单片机内存的值用textbox显示出
End If
Next
End Select
End Sub
Private Sub Cmdquit_Click()
End
End Sub
你单片机的(波特率,奇偶校验,数据位,停止位)与PC机的MSCOMM控件不一致.
--------------------编程问答-------------------- MSComm1.Settings = "9600,n,8,1"
我单片机上没有停止位,只要串口中断打开,不停的发0123 0123
不知道怎么改
--------------------编程问答-------------------- 你单片机的
波特率?
奇偶校验?
数据位?
究竟是多少值? --------------------编程问答-------------------- 9600
奇偶无
数据位8
--------------------编程问答-------------------- 请检查下单片机的时基是否准确?
此外你可用通用串口调试软件,调试单片机。
补充:VB , 控件