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
整体程序是这样子的,运行的时候时候提示总是不成功,也不知道问题出在那里了。请各位大侠帮我看看。谢谢!
展开
 我来答
hilinx
2010-08-07 · 超过42用户采纳过TA的回答
知道答主
回答量:216
采纳率:0%
帮助的人:106万
展开全部
太阳雨多年积攒极其珍贵的原创VB串口通信技术资料V3.0

VB串口通信编程源码200个,多种行业多种应用...
VB串口通信技术文章160篇,详尽地对VB串口通信的诠释...
VB串口通信电子书籍16部,工业通信名家著作,经典细致...
VB串口通信控件16个,简化串口通信编码,提高开发效率...
VB串口视频教程46个,两套完整视频教程,讲解直观,更快掌握...

超级赠品一:OSI网络模型教程48M
超级赠品二:串口硬件层知识大全资料包24M
超级赠品三:串口调试工具80个,应用于各种串口调试与校验计算...
超级赠品四:程序员发展类文章和书籍12部,帮助您的成长,健康和发展....
超级赠品五:更送虚拟串口调试软件, 帮助你在没有串口的电脑上也能正常调试...

你在淘宝搜索“太阳雨VB串口资料”就可以找到,希望可以帮助到你。
同时,还有"太阳雨VC串口资料"和"太阳雨DELPHI"串口资料...
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
swmupc
2010-08-07 · TA获得超过5555个赞
知道小有建树答主
回答量:361
采纳率:0%
帮助的人:238万
展开全部
程序报错还是你没有得到理想的结果?
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式