VB6串口编程

发布于 2024-08-31 19:51:46 字数 135 浏览 4 评论 0 原文

我需要通过串口控制另一个电路。 (我听说引脚4和引脚7用于此目的。如果这些引脚不正确,请告诉我哪些引脚用于此目的。

我的要求是将这些引脚设置为高或低并读取它们的电平(高或低)低)通过 VB6 程序

有什么想法可以完成任务吗?

I need to control another circuit through the serial port. (I have heard that pin 4 and pin 7 are used for that purpose. If these pins are incorrect, please tell me what pins are used for such purposes

My requirement is to set those pins to high or low and read their levels(high or low) through a VB6 program.

Any ideas on how to accomplish the task?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

可爱暴击 2024-09-07 19:51:46

其他答案中有很好的高级建议,但从实际的角度来看,它非常简单。有两个控制输入(DSR 和 CTS)和两个控制输出(DTR 和 RTS)。 DTR 位于引脚 4(9 引脚版本),RTS 位于引脚 7。DSR / CTS 位于引脚 6 和 8。

将 Comm Port 对象放置在 VB 窗体上,并将 .CommPort 设置为您的端口号。对于纯粹的逻辑控制目的,您使用什么 .Settings (波特率等)并不重要,因为您不会发送和接收任何串行数据,因此只需接受默认值即可。

设置 .PortOpen = True,然后根据需要将 .DTREnable / .RTSEnable 设置为 true 或 false,更改 DTR 和 RTS 输出。您应该在设计时将这些设置为 False 以避免错误触发。请注意,当 PC 重新启动时,系统可能会切换这些行。

您可以轮询 .CTSHolding.DSRHolding 属性来检测这些输入的更改,或者对 .OnComm 事件做出反应,该事件将收到信号当其中任何一个发生变化时。您仍然需要找出导致该事件的原因,但这只是一个 Select Case。

There's good high-level advice in other answers, but from a practical POV it's pretty simple. There are two control inputs (DSR and CTS) and two control outputs (DTR and RTS). DTR is on pin 4 (9-pin version) and RTS is on pin 7. DSR / CTS are pins 6 and 8.

Place a Comm Port object on a VB form, and set .CommPort to the number of your port. For pure logic control purposes it doesn't matter what .Settings (baudrate etc) you use because you won't be sending and receiving any serial data, so just accept the defaults.

Set .PortOpen = True, then change the DTR and RTS outputs by setting .DTREnable / .RTSEnable to true or false as required. You should set these False at design time to avoid false triggering. Be aware that these lines may be toggled by the system when the PC reboots.

You can poll the .CTSHolding and .DSRHolding properties to detect changes on those inputs, or react to the .OnComm event, which will get signaled when there's a change in either one. You still have to sort out which one caused the event, but that's just a Select Case.

九公里浅绿 2024-09-07 19:51:46

您不必担心各个引脚。大多数操作系统都会公开系统调用来为您操作引脚,并且某些语言(包括 VB6)提供了使用这些系统调用的方法。在 Google 上快速搜索后,找到了教程,其中包含有关引脚的一些详细信息,如果你有兴趣的话。然而,这个看起来更容易理解,至少在我看来是这样。

You don't have to worry about the individual pins. Most operating systems expose system calls to manipulate the pins for you, and some languages (including VB6) provide ways to use those system calls. A quick Google search turned up a tutorial that includes some details on the pins, if you're interested. However, this one looks a little easier to follow, at least in my opinion.

少钕鈤記 2024-09-07 19:51:46

Richard Grier 的《Visual Basic 程序员串行通信指南》是一本涵盖 VB6(和 VB.Net)的好书:可以从 他的网站,大约 40 美元加运费。

看起来他仍然在 VB6 新闻组,所以这是询问串行编程的好地方。

Richard Grier's Visual Basic Programmer's Guide to Serial Communications is a good book that covers VB6 (and VB.Net): it's available from his website, about $40 US plus shipping.

It looks like he still hangs out on the VB6 newsgroup, so that's a good place to ask about serial programming.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文