VB串口程序的疑惑
PrivateSubCombo1_Click()IfMSComm1.PortOpen=TrueThen'如果串口打开先关闭后在进行其他操作MSComm1.PortOpen...
Private Sub Combo1_Click()
If MSComm1.PortOpen = True Then '如果串口打开先关闭后在进行其他操作
MSComm1.PortOpen = False
End If
MSComm1.CommPort = Combo1.ListIndex + 1
End Sub
Private Sub Command1_Click()
Text1.Text = ""
End Sub
Private Sub Command2_Click()
On Error GoTo uerror
If Command2.Caption = "关闭串口" Then
MSComm1.PortOpen = False
Command2.Caption = "打开串口" '按钮文字改变
Shape1.FillColor = &HFFFFC0 '灯颜色改变
Else
MSComm1.PortOpen = True
Command2.Caption = &HFF
End If
Exit Sub
uerror:
msg$ = "无效端口号" '错误显示
Title$ = "串口调试助手"
x = MsgBox(msg$, 48, Title$) '48表示显示警告图标
End Sub
Private Sub Form_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
Else
End If
Combo1.AddItem "COM1"
Combo1.AddItem "COM2"
Combo1.AddItem "COM3"
Combo1.AddItem "COM4"
Combo1.AddItem "COM5"
Combo1.AddItem "COM6"
Combo1.AddItem "COM7"
Combo1.AddItem "COM8"
Combo1.ListIndex = 0
MSComm1.CommPort = 3
MSComm1.Settings = "19200,n,8,1"
Command2.Caption = "打开串口"
Shape1.FillColor = &HFFFFC0
Option2.Value = True
Combo2.AddItem = "256000"
Combo2.AddItem = "128000"
Combo2.AddItem = "115200"
Combo2.AddItem = "57600"
Combo2.AddItem = "38400"
Combo2.AddItem = "28800"
Combo2.AddItem = "19200"
Combo2.AddItem = "9600"
Combo2.AddItem = "4800"
Combo2.AddItem = "2400"
Combo2.AddItem = "1200"
Combo3.AddItem = "无 None"
Combo3.AddItem = "奇 Odd"
Combo3.AddItem = "偶 Even"
Combo4.AddItem "4"
Combo4.AddItem "5"
Combo4.AddItem "6"
Combo4.AddItem "7"
Combo4.AddItem "8"
Combo4.AddItem "1"
Combo4.AddItem "2"
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
End Sub
Private Sub MSComm1_OnComm()
Dim BytRexeived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
Case comEventRxOver '接收缓冲区溢出
Text1.Text = ""
Exit Sub
Case comEvReceive '接收缓冲区有数据
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
If MSComm1.InputMode = comInputModeBinary Then
BytReceived() = strBuff
For i = 0 To UBound(BytRexeived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i)) & " "
Else
strData = strData & Hex(BytReceived(i)) & " "
End If
Next
Text1 = Text1 & strData
strData = ""
Else
Text1 = Text1 & strBuff
End If
End Select
End Sub
End Sub
Private Sub Option1_Click()
MSComm1.InputMode = comInputModeText
End Sub
Private Sub Option2_Click()
MSComm1.InputMode = comInputModeBinary
End Sub
整体程序是这样子的,运行的时候时候提示总是不成功,也不知道问题出在那里了。请各位大侠帮我看看。谢谢! 展开
If MSComm1.PortOpen = True Then '如果串口打开先关闭后在进行其他操作
MSComm1.PortOpen = False
End If
MSComm1.CommPort = Combo1.ListIndex + 1
End Sub
Private Sub Command1_Click()
Text1.Text = ""
End Sub
Private Sub Command2_Click()
On Error GoTo uerror
If Command2.Caption = "关闭串口" Then
MSComm1.PortOpen = False
Command2.Caption = "打开串口" '按钮文字改变
Shape1.FillColor = &HFFFFC0 '灯颜色改变
Else
MSComm1.PortOpen = True
Command2.Caption = &HFF
End If
Exit Sub
uerror:
msg$ = "无效端口号" '错误显示
Title$ = "串口调试助手"
x = MsgBox(msg$, 48, Title$) '48表示显示警告图标
End Sub
Private Sub Form_Click()
If MSComm1.PortOpen = True Then
MSComm1.PortOpen = False
Else
End If
Combo1.AddItem "COM1"
Combo1.AddItem "COM2"
Combo1.AddItem "COM3"
Combo1.AddItem "COM4"
Combo1.AddItem "COM5"
Combo1.AddItem "COM6"
Combo1.AddItem "COM7"
Combo1.AddItem "COM8"
Combo1.ListIndex = 0
MSComm1.CommPort = 3
MSComm1.Settings = "19200,n,8,1"
Command2.Caption = "打开串口"
Shape1.FillColor = &HFFFFC0
Option2.Value = True
Combo2.AddItem = "256000"
Combo2.AddItem = "128000"
Combo2.AddItem = "115200"
Combo2.AddItem = "57600"
Combo2.AddItem = "38400"
Combo2.AddItem = "28800"
Combo2.AddItem = "19200"
Combo2.AddItem = "9600"
Combo2.AddItem = "4800"
Combo2.AddItem = "2400"
Combo2.AddItem = "1200"
Combo3.AddItem = "无 None"
Combo3.AddItem = "奇 Odd"
Combo3.AddItem = "偶 Even"
Combo4.AddItem "4"
Combo4.AddItem "5"
Combo4.AddItem "6"
Combo4.AddItem "7"
Combo4.AddItem "8"
Combo4.AddItem "1"
Combo4.AddItem "2"
MSComm1.InBufferSize = 1024
MSComm1.OutBufferSize = 512
End Sub
Private Sub MSComm1_OnComm()
Dim BytRexeived() As Byte
Dim strBuff As String
Dim i As Integer
Select Case MSComm1.CommEvent '事件发生
Case comEventRxOver '接收缓冲区溢出
Text1.Text = ""
Exit Sub
Case comEvReceive '接收缓冲区有数据
MSComm1.InputLen = 0 '读入缓冲区全部内容
strBuff = MSComm1.Input '读入到缓冲区
If MSComm1.InputMode = comInputModeBinary Then
BytReceived() = strBuff
For i = 0 To UBound(BytRexeived)
If Len(Hex(BytReceived(i))) = 1 Then
strData = strData & "0" & Hex(BytReceived(i)) & " "
Else
strData = strData & Hex(BytReceived(i)) & " "
End If
Next
Text1 = Text1 & strData
strData = ""
Else
Text1 = Text1 & strBuff
End If
End Select
End Sub
End Sub
Private Sub Option1_Click()
MSComm1.InputMode = comInputModeText
End Sub
Private Sub Option2_Click()
MSComm1.InputMode = comInputModeBinary
End Sub
整体程序是这样子的,运行的时候时候提示总是不成功,也不知道问题出在那里了。请各位大侠帮我看看。谢谢! 展开
2个回答
展开全部
太阳雨多年积攒极其珍贵的原创VB串口通信技术资料V3.0
VB串口通信编程源码200个,多种行业多种应用...
VB串口通信技术文章160篇,详尽地对VB串口通信的诠释...
VB串口通信电子书籍16部,工业通信名家著作,经典细致...
VB串口通信控件16个,简化串口通信编码,提高开发效率...
VB串口视频教程46个,两套完整视频教程,讲解直观,更快掌握...
超级赠品一:OSI网络模型教程48M
超级赠品二:串口硬件层知识大全资料包24M
超级赠品三:串口调试工具80个,应用于各种串口调试与校验计算...
超级赠品四:程序员发展类文章和书籍12部,帮助您的成长,健康和发展....
超级赠品五:更送虚拟串口调试软件, 帮助你在没有串口的电脑上也能正常调试...
你在淘宝搜索“太阳雨VB串口资料”就可以找到,希望可以帮助到你。
同时,还有"太阳雨VC串口资料"和"太阳雨DELPHI"串口资料...
VB串口通信编程源码200个,多种行业多种应用...
VB串口通信技术文章160篇,详尽地对VB串口通信的诠释...
VB串口通信电子书籍16部,工业通信名家著作,经典细致...
VB串口通信控件16个,简化串口通信编码,提高开发效率...
VB串口视频教程46个,两套完整视频教程,讲解直观,更快掌握...
超级赠品一:OSI网络模型教程48M
超级赠品二:串口硬件层知识大全资料包24M
超级赠品三:串口调试工具80个,应用于各种串口调试与校验计算...
超级赠品四:程序员发展类文章和书籍12部,帮助您的成长,健康和发展....
超级赠品五:更送虚拟串口调试软件, 帮助你在没有串口的电脑上也能正常调试...
你在淘宝搜索“太阳雨VB串口资料”就可以找到,希望可以帮助到你。
同时,还有"太阳雨VC串口资料"和"太阳雨DELPHI"串口资料...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询