我想用Viaual Basic软件做一个单片机与上位机通信的用户界面
想用VB做一单片机与上位机通信的界面。该界面包括温度,加速度,速度的显示模块等,还能够通过界面控制速度。哪位大神有这方面的经验。谢谢啦!另外,求解我用VB,VC++,La...
想用VB做一单片机与上位机通信的界面。该界面包括温度,加速度,速度的显示模块等,还能够通过界面控制速度。哪位大神有这方面的经验。谢谢啦!另外,求解 我用VB,VC++,Labview 哪个与上位机通信起来比较方便
展开
展开全部
VB用MScomm控件对单片机串口控制很容易,VC也是一样用的MScomm控件,不过VB上手更快一些另外C#也可以用于上位机编程
VB,VC++,Labview 相比较,Labview更简单也更快,但是Labview的程序不灵活而且只能在装Labview电脑上跑,个人不喜欢,但是Labview很简单好用界面做出来也很有感觉,比较人家就是做控制的
我个人用VB比较多,给你一点代码参考:
Dim ckh As Integer
Dim btl As Long
Dim bj As Integer
Dim ck As Boolean
Dim zz() As Byte
Dim js As String
Dim send(0) As Byte
Private Sub Command1_Click()
If ck = False Then
Command1.Caption = "关闭串口"
ck = True
Else
Command1.Caption = "打开串口"
ck = False
End If
If ck = True Then
ckh = Combo1.ListIndex
btl = Combo2.Text
MSComm1.CommPort = ckh + 1
Label4.Caption = "COM" & ckh + 1 & "串口打开,波特率:" & btl
Select Case btl
Case Is = 110
MSComm1.Settings = "110,N,8,1"
Case Is = 300
MSComm1.Settings = "110,N,8,1"
Case Is = 600
MSComm1.Settings = "600,N,8,1"
Case Is = 1200
MSComm1.Settings = "1200,N,8,1"
Case Is = 2400
MSComm1.Settings = "2400,N,8,1"
Case Is = 9600
MSComm1.Settings = "9600,N,8,1"
Case Is = 14400
MSComm1.Settings = "14400,N,8,1"
Case Is = 19200
MSComm1.Settings = "19200,N,8,1"
Case Is = 115200
MSComm1.Settings = "115200,N,8,1"
End Select
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
Else
Label1.Caption = "串口已经关闭"
MSComm1.PortOpen = False
End If
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
Label2.Caption = ""
End Sub
Private Sub Command3_Click()
If ck = True Then
send(0) = Text1.Text
MSComm1.OutBufferCount = 0
MSComm1.Output = send
Label2.Caption = Label2.Caption & Text1.Text
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 10
Combo1.List(i) = "COM" & i + 1
Next i
Combo2.List(0) = 110
Combo2.List(1) = 300
Combo2.List(2) = 600
Combo2.List(3) = 1200
Combo2.List(4) = 2400
Combo2.List(5) = 9600
Combo2.List(6) = 14400
Combo2.List(7) = 19200
Combo2.List(8) = 115200
Combo2.ListIndex = 0
Combo1.ListIndex = 0
Label1.Caption = ""
Label2.Caption = ""
End Sub
Private Sub MSComm1_OnComm()
Dim i As Byte
If MSComm1.CommEvent = comEvReceive Then
zz = MSComm1.Input
For i = 0 To UBound(zz) Step 1
js = (zz(i))
Next
Label1.Caption = Label1.Caption & js
MSComm1.InBufferCount = 0
End If
End Sub
VB,VC++,Labview 相比较,Labview更简单也更快,但是Labview的程序不灵活而且只能在装Labview电脑上跑,个人不喜欢,但是Labview很简单好用界面做出来也很有感觉,比较人家就是做控制的
我个人用VB比较多,给你一点代码参考:
Dim ckh As Integer
Dim btl As Long
Dim bj As Integer
Dim ck As Boolean
Dim zz() As Byte
Dim js As String
Dim send(0) As Byte
Private Sub Command1_Click()
If ck = False Then
Command1.Caption = "关闭串口"
ck = True
Else
Command1.Caption = "打开串口"
ck = False
End If
If ck = True Then
ckh = Combo1.ListIndex
btl = Combo2.Text
MSComm1.CommPort = ckh + 1
Label4.Caption = "COM" & ckh + 1 & "串口打开,波特率:" & btl
Select Case btl
Case Is = 110
MSComm1.Settings = "110,N,8,1"
Case Is = 300
MSComm1.Settings = "110,N,8,1"
Case Is = 600
MSComm1.Settings = "600,N,8,1"
Case Is = 1200
MSComm1.Settings = "1200,N,8,1"
Case Is = 2400
MSComm1.Settings = "2400,N,8,1"
Case Is = 9600
MSComm1.Settings = "9600,N,8,1"
Case Is = 14400
MSComm1.Settings = "14400,N,8,1"
Case Is = 19200
MSComm1.Settings = "19200,N,8,1"
Case Is = 115200
MSComm1.Settings = "115200,N,8,1"
End Select
MSComm1.OutBufferSize = 1024
MSComm1.InBufferSize = 1024
MSComm1.RThreshold = 1
MSComm1.PortOpen = True
MSComm1.InputMode = comInputModeBinary
Else
Label1.Caption = "串口已经关闭"
MSComm1.PortOpen = False
End If
End Sub
Private Sub Command2_Click()
Label1.Caption = ""
Label2.Caption = ""
End Sub
Private Sub Command3_Click()
If ck = True Then
send(0) = Text1.Text
MSComm1.OutBufferCount = 0
MSComm1.Output = send
Label2.Caption = Label2.Caption & Text1.Text
End If
End Sub
Private Sub Form_Load()
Dim i As Integer
For i = 0 To 10
Combo1.List(i) = "COM" & i + 1
Next i
Combo2.List(0) = 110
Combo2.List(1) = 300
Combo2.List(2) = 600
Combo2.List(3) = 1200
Combo2.List(4) = 2400
Combo2.List(5) = 9600
Combo2.List(6) = 14400
Combo2.List(7) = 19200
Combo2.List(8) = 115200
Combo2.ListIndex = 0
Combo1.ListIndex = 0
Label1.Caption = ""
Label2.Caption = ""
End Sub
Private Sub MSComm1_OnComm()
Dim i As Byte
If MSComm1.CommEvent = comEvReceive Then
zz = MSComm1.Input
For i = 0 To UBound(zz) Step 1
js = (zz(i))
Next
Label1.Caption = Label1.Caption & js
MSComm1.InBufferCount = 0
End If
End Sub
展开全部
这个完全可以的,如果都是从零开始,就用VB吧,这个简单,相对来说灵活性也还可以
下面我给你比较一下这三种做这个功能的优缺点
VC++ 复杂,难上手 高度灵活
VB 入门简单 灵活度一般吧,但是技术拔高到一定程度后也不差
Lab 简单 灵活性几乎没有,必须按照规定的来
回答可以编辑的话,我给你上传一个例子,不过网上很多很多这相关的例子
用单片机的232串口,VB就用mscom控件,新版的vb.net的控件换名字了,更好用。
电脑如果没有232接口,到淘宝搜索usb转232接口,大把的
下面我给你比较一下这三种做这个功能的优缺点
VC++ 复杂,难上手 高度灵活
VB 入门简单 灵活度一般吧,但是技术拔高到一定程度后也不差
Lab 简单 灵活性几乎没有,必须按照规定的来
回答可以编辑的话,我给你上传一个例子,不过网上很多很多这相关的例子
用单片机的232串口,VB就用mscom控件,新版的vb.net的控件换名字了,更好用。
电脑如果没有232接口,到淘宝搜索usb转232接口,大把的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
自己做一个简单的通信协议,就行了。VB的话做串口通信也很方便的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询