关于串口通信返回串口是否打开状态的问题。

sy123782568 2010-10-21 04:51:17
If Not RS232.IsOpen Then '尚未开启
RS232.Open() '开启通讯端口
SetTimeB.Enabled = True '使能按钮
TestB.Enabled = True
ReadComB.Enabled = True
SentB.Enabled = True
解除锁定ToolStripMenuItem.Enabled = True
Else
MsgBox("~~通讯端口开启错误(通讯端口已被开启)~~", MsgBoxStyle.Critical Or MsgBoxStyle.OkCancel)
End
不知为何,不管串口是否打开,rs232.isopen返回的都是false。
...全文
271 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanlongwuhui 2010-10-22
  • 打赏
  • 举报
回复
试试端口已经开启的,先关闭端口,再重新打开端口进行操作
Tosp2012 2010-10-21
  • 打赏
  • 举报
回复
If Not RS232.IsOpen Then '尚未开启
RS232.mportname = TStripCmbCOM.SelectedItem.ToString
RS232.mbaudrate = 9600
RS232mparity = Parity.None
RS232.mdatabit = 8
RS232.mstopbit = StopBits.Two

RS232.Open()

SetTimeB.Enabled = True '使能按钮
TestB.Enabled = True
ReadComB.Enabled = True
SentB.Enabled = True
解除锁定ToolStripMenuItem.Enabled = True
Else
MsgBox("~~通讯端口开启错误(通讯端口已被开启)~~", MsgBoxStyle.Critical Or MsgBoxStyle.OkCancel)
End
Tosp2012 2010-10-21
  • 打赏
  • 举报
回复
If RS232.IsOpen=false Then '尚未开启
RS232.Open() '开启通讯端口
SetTimeB.Enabled = True '使能按钮
TestB.Enabled = True
ReadComB.Enabled = True
SentB.Enabled = True
解除锁定ToolStripMenuItem.Enabled = True
Else
MsgBox("~~通讯端口开启错误(通讯端口已被开启)~~", MsgBoxStyle.Critical Or MsgBoxStyle.OkCancel)
End
sy123782568 2010-10-21
  • 打赏
  • 举报
回复
我的串口正常。比如我用程序打开了COM1口,我接着再打开一次,程序就出错了。就是.isopen的返回值不对。打开后,他的返回值应该是TRUE。
Tosp2012 2010-10-21
  • 打赏
  • 举报
回复
检查一下你的电脑的串口是否开启。

如果你的电脑Bios把串口禁用了,你打开每次都是false
兔子-顾问 2010-10-21
  • 打赏
  • 举报
回复
贴完整的,就是说你可能实例化了多次。每次创建一个新的SerialPort对象,那IsOpen属性当然都是一样的,贴完整相关代码。
sy123782568 2010-10-21
  • 打赏
  • 举报
回复
Imports System.IO.Ports Imports
System.Text
Public Class Form1
Dim RS232 As SerialPort


Dim mbaudrate As Integer
Dim mparity As Parity
Dim mdatabit As Integer
Dim mstopbit As StopBits
Dim mportname As String

mportname = TStripCmbCOM.SelectedItem.ToString
mbaudrate = 9600
mparity = Parity.None
mdatabit = 8
mstopbit = StopBits.Two
rs232 = New SerialPort(mportname, mbaudrate, mparity, mdatabit, mstopbit

已经定义过了
兔子-顾问 2010-10-21
  • 打赏
  • 举报
回复
RS232 是什么?
你是否多次创建了新的实例?

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧