Visual Basic和串口 [英] Visual basic and serial ports

查看:82
本文介绍了Visual Basic和串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将设备连接到计算机并打开设备管理器。 com端口是COM20。



我正在尝试通过发送十六进制命令通过串口与设备通信,并希望收到一些十六进制。



VB如何知道我想和那个端口通话?我是否必须在表单设计中添加一个串口(从工具箱中)?



我尝试过:



好​​吧,我确实尝试过任何事情,那就是我来这里的原因。我也想理解它。

I've connected a device into my computer and opened device manager. THe com port is is COM20.

I'm am trying to communicate with the device over serial by sending hex commands and will hopefully receive some hex.

How does VB know that I want to talk to that port? Do I have to add a serial port (from toolbox) to my form design?

What I have tried:

Well I ahvent tried anything just yet, thats' why I came here. I want to understand it too.

推荐答案

是的,您可以通过创建类的实例直接从设计器或代码中添加SerialPort控件自己。

SerialPort类具有允许您设置端口的属性,以及波特率,BPC,奇偶校验等通信参数,这些参数必须正确才能成功与您交谈具体设备: SerialPort Class(System.IO.Ports ) [ ^ ] - 链接包含一个基本示例,但我强烈建议您在开始编码之前通过Hyperterminal或类似方式证明通信。这样你至少知道你认为应该工作的通信参数,并且你可以在开始添加你不知道的代码的代码之前双向地与设备交谈!
Yes, you do add a SerialPort control, either from the designer, or in your code directly by creating an instance of the class yourself.
The SerialPort class has properties which allow you to set the port, as well as the communications parameters such as Baud rate, BPC, Parity and suchlike which must be correct in order to talk successfully to your specific device: SerialPort Class (System.IO.Ports)[^] - the link incliudes a basic example, but I'd strongly suggest that you "prove" teh communicatiosn via Hyperterminal or similar before you start coding. That way you at least know that the communications parameters that you think should work do, and that you can talk bidirectionally to the device before you start adding teh comlication of code that you don't know works either!


这篇关于Visual Basic和串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆