从 VBA 访问串行端口的最佳方法是什么? [英] What is the best way to access a serial port from VBA?

查看:50
本文介绍了从 VBA 访问串行端口的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 VBA 访问串行端口的最佳方法是什么?

What is the best way to access a serial port from VBA?

我需要我们的一些销售代表能够从 PowerPoint 中的操作按钮通过串行端口发送一个简单的字符串.我不常用 VBA,尤其是像这样的东西.通常我会把它变成某种应用程序,但我实际上并不认为这个想法是那么糟糕.这将是他们在投影仪上演示此设备并与其他销售人员和非技术人员交谈时的便捷工具.此外,这个销售人员对 VBA 或 PowerPoint 演示文稿进行小幅修改也没有问题,但在重新编译 .NET 应用程序时就不行了.

I have a need for some of our sales reps to be able to send a simple string over the serial port from an action button in PowerPoint. I don't commonly use VBA, especially for anything like this. Normally I would turn it into an application of some sort, but I actually don't think the idea is that bad. It will be a handy tool for them to demo this device with while on a projector and talking to other sales guys and non technical people. Also, this sales guy will have no problem making small modifications to the VBA or PowerPoint presentation, but would not do as well with recompiling a .NET application.

我知道我们可以通过从动作演示文稿中运行的批处理文件来完成,但这并不让我很高兴.我想我们可能可以访问一个 COM 对象并从那里运行,但我对在 VBA 中使用的最新和最好的库并不真正了解,而且快速了解如何轻松打开它也很不错,发送并关闭连接.

I know we could do it through a batch file run from the presentation on the action, but that doesn't make me very happy. I figure we could probably access a COM object and run from there, but again I am not real up on the latest and greatest libraries to use in VBA, and it would also be nice to get a quick little primer in how to easily open, send and close the connection.

由于这需要在多人的计算机上运行,​​如果它可以很容易地转移到其他机器上就更好了.我应该可以说它必须在 Office 2007 和 Windows XP 上运行.不过,与其他任何东西的兼容性将是一个不错的奖励.

Since this will need to be run on multiple people's computers, it would be nice if it would be easily transportable to other machines. I should be able to say it has to run on Office 2007 and Windows XP. Compatibility with anything else would be a nice bonus though.

我应该如何处理这个问题?有什么好的提示或技巧吗?图书馆推荐?

How should I go about handling this? Any good tips or tricks? Library recommendations?

推荐答案

Win32 API 将串口作为文件处理.您可以通过从 VBA 中调用这些 API 函数直接访问串行端口.我必须为旧的 .NET 应用程序执行此操作,但 VBA 也不例外.

The Win32 API handles the serial port as a file. You can access the serial ports directly by calling these API functions from within VBA. I had to do this for an old .NET application but VBA is no different.

我没有在这个网站上为你散布它,而是多年来我一直坚持的参考.如何在VBA中进行串口通讯

Rather than hash it out for you on this site, here's a reference I've hung onto over the years. How to perform serial port communications in VBA

这篇关于从 VBA 访问串行端口的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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