PC机(上位机)VB程序如下:
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 8
End SubPrivate Sub MSComm1_OnComm() '接收
Dim indata
Dim arr() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
indata = MSComm1.Input
arr() = indata
Label1(0).Caption = arr(0) & arr(1) '用户号
Select Case arr(2)
Case 0 '正常
Label1(1).Caption = "正常"
Case 1 '异常
Label1(1).Caption = "异常"
End Select
Label1(2).Caption = arr(3) * 10 + arr(4) + arr(5) / 10 '温度
Select Case arr(6)
Case 0 '心率正常
Label1(3).Caption = "心率正常"
Case 1 '心动过快
Label1(3).Caption = "心动过快"
Case 2 '心动过缓
Label1(3).Caption = "心动过缓"
Case 4 '心律不齐
Label1(3).Caption = "心律不齐"
End Select
Label1(4).Caption = arr(7) '心搏频率值
End Select
For i = 0 To UBound(arr)
Text1 = Text1 & " " & Hex(arr(i))
Next
End Sub0、1两个字节来表示用户号。在销售时给每个用户设置一个专门的用户号,并将用户的信息存入相应数据库中。发送数据时连同用户号一起发送,接收方可凭此区分不同用户,并查看该用户的个人信息。(16进制)
字节2表示温度的状态,0000 0000表示温度值为正常,0000 0001表示异常。(二进制)
字节3,4,5分别表示温度值的十位、个位和小数位。(ascii码).
字节6表示脉搏的状态,0000 0000表示心率正常,0000 0001表示心动过快,0000 0010表示心动过缓,0000 0100表示心律不齐。(二进制)
字节7表示心搏频率值。(十六进制) 为什么调试的时候 label显示的不是汉字 心率正常之类的 却是数字 温度状态 脉搏状态没有显示出来
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 8
End SubPrivate Sub MSComm1_OnComm() '接收
Dim indata
Dim arr() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
indata = MSComm1.Input
arr() = indata
Label1(0).Caption = arr(0) & arr(1) '用户号
Select Case arr(2)
Case 0 '正常
Label1(1).Caption = "正常"
Case 1 '异常
Label1(1).Caption = "异常"
End Select
Label1(2).Caption = arr(3) * 10 + arr(4) + arr(5) / 10 '温度
Select Case arr(6)
Case 0 '心率正常
Label1(3).Caption = "心率正常"
Case 1 '心动过快
Label1(3).Caption = "心动过快"
Case 2 '心动过缓
Label1(3).Caption = "心动过缓"
Case 4 '心律不齐
Label1(3).Caption = "心律不齐"
End Select
Label1(4).Caption = arr(7) '心搏频率值
End Select
For i = 0 To UBound(arr)
Text1 = Text1 & " " & Hex(arr(i))
Next
End Sub0、1两个字节来表示用户号。在销售时给每个用户设置一个专门的用户号,并将用户的信息存入相应数据库中。发送数据时连同用户号一起发送,接收方可凭此区分不同用户,并查看该用户的个人信息。(16进制)
字节2表示温度的状态,0000 0000表示温度值为正常,0000 0001表示异常。(二进制)
字节3,4,5分别表示温度值的十位、个位和小数位。(ascii码).
字节6表示脉搏的状态,0000 0000表示心率正常,0000 0001表示心动过快,0000 0010表示心动过缓,0000 0100表示心律不齐。(二进制)
字节7表示心搏频率值。(十六进制) 为什么调试的时候 label显示的不是汉字 心率正常之类的 却是数字 温度状态 脉搏状态没有显示出来
解决方案 »
- 皮皮书屋犀利的注册验证码,想盗取过来,谁有兴趣?
- VB打包程序“路径不包含文件名”!!!!!!!!!!!!!!!!!!!!
- 网络打印机如何添加自定义纸张
- vb怎么接收一个储存过程返回的参数的值
- 求助:webbrowser中显示一个带applet的网页,怎么显示不出来.
- 请问能否用VB新建一个Access数据库文件(.mdb)?
- 如何将JPG格式图片设置为桌面背景?
- vb怎么做exe生成器(高手来帮忙 赠送7位QQ号码)
- 您还为做报表发愁吗?试试坏猫报表打印控件吧!
- 请问有谁知道VB6怎么用命令连接网络啊?
- 调用VB中mschart控件时连接SQL SERVER数据库的问题
- usb-rs232 串囗 监控
建立了五个label 分别显示 用户号 温度状态 温度值 脉搏状态 脉搏值
还有一个text 里面显示十六进制的数据 所有的8个字节的数据您说的通信协议不就是这个么?
9600,n,8,1。
Option Explicit
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 8
MSComm1.InputLen = 0
End SubPrivate Sub MSComm1_OnComm() '接收
Dim indata
Dim arr() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
indata = MSComm1.Input
arr() = indata
Label1(0).Caption = Chr(arr(0)) & Chr(arr(1)) '用户号
Select Case arr(2)
Case 0 '正常
Label1(1).Caption = "正常"
Case 1 '异常
Label1(1).Caption = "异常"
End Select
Label1(2).Caption = Val(Chr(arr(3))) * 10 + Val(Chr(arr(4))) + Val(Chr(arr(5))) / 10 '温度
Select Case arr(6)
Case 0 '心率正常
Label1(3).Caption = "心率正常"
Case 1 '心动过快
Label1(3).Caption = "心动过快"
Case 2 '心动过缓
Label1(3).Caption = "心动过缓"
Case 4 '心律不齐
Label1(3).Caption = "心律不齐"
End Select
Label1(4).Caption = arr(7) '心搏频率值
End Select
'For i = 0 To UBound(arr)
' Text1 = Text1 & " " & Hex(arr(i))
'Next
End Sub
Private Sub Form_Load()
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1" '设成与单片机相同
MSComm1.InputMode = comInputModeBinary '二进制接收
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.RThreshold = 8
MSComm1.InputLen = 0
End SubPrivate Sub MSComm1_OnComm() '接收
Dim indata
Dim arr() As Byte
Dim i As Integer
Select Case MSComm1.CommEvent
Case comEvReceive
MSComm1.RThreshold = 0
indata = MSComm1.Input
arr() = indata
Label1(0).Caption = Chr(arr(0)) & Chr(arr(1)) '用户号
Select Case arr(2)
Case 0 '正常
Label1(1).Caption = "正常"
Case 1 '异常
Label1(1).Caption = "异常"
End Select
Label1(2).Caption = Val(Chr(arr(3))) * 10 + Val(Chr(arr(4))) + Val(Chr(arr(5))) / 10 '温度
Select Case arr(6)
Case 0 '心率正常
Label1(3).Caption = "心率正常"
Case 1 '心动过快
Label1(3).Caption = "心动过快"
Case 2 '心动过缓
Label1(3).Caption = "心动过缓"
Case 4 '心律不齐
Label1(3).Caption = "心律不齐"
End Select
Label1(4).Caption = arr(7) '心搏频率值
MSComm1.RThreshold = 8
End Select
'For i = 0 To UBound(arr)
' Text1 = Text1 & " " & Hex(arr(i))
'Next
End Sub