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

查看:321
本文介绍了从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天全站免登陆