VB上位机程序VB上位机程序VB上位机程序VB上位机程序
源代码在线查看: config.frm
VERSION 5.00
Begin VB.Form Config
BackColor = &H00C0FFFF&
Caption = "设置参数"
ClientHeight = 2985
ClientLeft = 60
ClientTop = 450
ClientWidth = 3795
LinkTopic = "Form1"
ScaleHeight = 2985
ScaleWidth = 3795
StartUpPosition = 3 '窗口缺省
Begin VB.CommandButton cmdOk
Caption = "确定"
Height = 375
Left = 600
TabIndex = 5
Top = 2040
Width = 975
End
Begin VB.TextBox txtSetting
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1680
TabIndex = 4
Text = "9600,n,8,1"
Top = 1200
Width = 975
End
Begin VB.ComboBox Combo1
Height = 300
Left = 1680
TabIndex = 3
Text = "Combo1"
Top = 600
Width = 975
End
Begin VB.CommandButton cmdCancel
Caption = "取消"
Height = 375
Left = 2040
TabIndex = 0
Top = 2040
Width = 855
End
Begin VB.Label Label2
BackColor = &H00C0FFFF&
Caption = "串口设置:"
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 600
TabIndex = 2
Top = 1320
Width = 975
End
Begin VB.Label Label1
BackColor = &H00C0FFFF&
Caption = "串口选择:"
BeginProperty Font
Name = "Times New Roman"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 600
TabIndex = 1
Top = 600
Width = 975
End
End
Attribute VB_Name = "Config"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub cmdCancel_Click()
Config.Hide
Unload Config
End Sub
Private Sub cmdOk_Click()
On Error GoTo SettingError
intPort = Val(Config.Combo1.ListIndex)
strSet = Config.txtSetting.Text
If Not Main.MSComm1.PortOpen Then
Main.MSComm1.CommPort = intPort
Main.MSComm1.Settings = strSet
Main.MSComm1.PortOpen = True
End If
Config.Hide
Unload Config
Exit Sub
SettingError:
intPort = 2
strSet = "9600,n,8,1"
Config.Show
Config.Combo1.Text = Str(intPort)
Config.txtSetting.Text = strSet
MsgBox (Error(Err.Number))
End Sub
Private Sub Combo1_Change()
If Combo1.ListIndex + 1 com_last_num Then '选的端口跟上次一样就不检测了
'先关闭上一个打开的端口
If com_last_open_num 0 Then
Main.MSComm1.PortOpen = False
End If
If Test_COM(Combo1.ListIndex + 1) = True Then
com_last_open_num = 0 '哈哈,注意此处要清零
End If
com_last_num = Combo1.ListIndex + 1
End Sub
'检测端口号函数'
Private Function Test_COM(com_num As Integer) As Boolean
If com_num com_last_num Or Command1.Caption = "打开端口" Then '选的端口跟上次一样就不检测了
On Error GoTo Comm_Error
Main.MSComm1.CommPort = com_num '这里接收传入的串口号
Main.MSComm1.PortOpen = True
Main.MSComm1.PortOpen = False
Test_COM = True '如果操作成功,则说明当前串口可用,返回1,表示串口可用
Exit Function
Comm_Error:
If Err.Number = 8002 Then
MsgBox "串口不存在!"
ElseIf Err.Number = 8005 Then
MsgBox "串口已打开!"
Else
MsgBox "其它错误"
End If
Test_COM = False '如果出错,则返回0
Exit Function
Resume Next
End If
End Function
'端口初始化子程序'
Private Sub initial_com(com_num As Integer)
Main.MSComm1.CommPort = com_num ' 设置通讯串口
Main.MSComm1.Settings = "9600,n,8,1" '设置波特率和发送字符格式
Main.MSComm1.OutBufferSize = 1024 ' 设置发送缓冲区1024Byte
Main.MSComm1.InBufferSize = 1024 '设置接收缓冲区1024Byte
Main.MSComm1.InputMode = 1
Main.MSComm1.InputLen = 0 '设置或返回一次从接收缓冲区中读取字节数,0表示一次读取所有数据
Main.MSComm1.InBufferCount = 0
Main.MSComm1.SThreshold = 1
Main.MSComm1.RThreshold = 1 ' 每个字符到接收缓冲区都触发接收事件
MSComm1.PortOpen = True ' 打开串口
End Sub
'界面初始化'
Private Sub Form_Load()
Combo1.Text = "COM4"
End Sub
|
相关资源 |
|
-
一般OPTO22工业控制器主要用于IO控制,用途比较广泛而其上位机一般使用DELPHI平台或C平台进行建模和控制,该程序实现了OPTO和DELPHI平台下上位机之间模拟量数字量的传输,并以得到实际应用
-
一般OPTO22工业控制器主要用于IO控制,用途比较广泛而其上位机一般使用DELPHI平台或BCB平台进行建模和控制,该程序实现了OPTO和C++builder平台下上位机之间模拟量数字量的传输,并以
-
电脑通过串口控制单片机,当按下0~9按钮后,电脑发送给单片机,单片机用八段数码管显示出来.程序中的控件在本站能找到ComDrv32.上位机用Dephi7编写,下位机用Keil2编写.分别装在两个文件夹
-
串口实现双机互联,仅供参考!VC控件MSComm编写串口通信程序的源代码
-
实现pc机和安装无线CF卡的手持设备之间的通信的程序源代码
-
libsvm-2.5程序代码导读 这是一个中文版的针对支持向量机源程序libsvm-2.5代码导读文档,由个人经验所得, 为您看libsvm程序省了不少的力气!非常难得!
-
本程序为某企业的税控机固件程序.基于东芝TMP93CS41 16位单片机编写,符合国家标准.该程序已经经过多次长期调试.
-
一个ASP.net给上传图片加水印的程序,网上有C#版的,本人习惯用VB.net所以就做了一个VB.net版的,您有什么疑问请发送邮件到Nick4@tom.com
|