以一种形式添加的串行端口无法从另一个类 vb.net 访问
我在 vb.net 表单中添加了一个串行端口 com1。我创建了一个新类并编写了一个打开 com1 的方法,并在主窗体中创建了它的对象,并调用了该方法及其打开。
然后我创建了另一个类,编写了一个方法来将数据写入 com,并以同样的方式创建了一个对象并调用它,但当端口关闭时我收到错误。我做错了什么。
打开端口
公共类 openport 公共子开放通信 mainform.com1.open 结束子 end class
//in the mian form
dim cc as openport
cc.opencom
'上面的东西有效
进行相同的操作时,
但是当我在另一个类中使用mainform.com1.write(data)
我在端口关闭时收到错误。
I added a serial port com1 to my vb.net form. I created a new class and wrote a method to open the com1 and created its object in the main form and called the method and its opening.
THen i created another class wrote a method to write data to the com and same way created an object and called it but i am getting the error as port is closed. What am i doing wrong.
To open the port
public class openport
public sub opencom
mainform.com1.open
end sub
end class
//in the mian form
dim cc as openport
cc.opencom
'The above stuff works
But when i do same thing in another class for writing using
mainform.com1.write(data)
i am getting an error as port closed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在定义一种通讯,然后打开另一种通讯。检查一下,如果仍然有问题,请发布完整的代码。
It looks like you are defining one comport, then opening a different one. Check that, if you still have issues post your complete code.