处理跨平台程序的 COM 端口的最佳方法?

发布于 2024-09-08 21:08:55 字数 137 浏览 2 评论 0原文

我正在编写一个应用程序,需要将数据发送到连接到 COM 端口的串行设备。 我很困惑处理这种设备的最佳方法是什么?

我应该用 C++ 编写通信模块还是用 Java 编写?

我想在 Windows 和 Linux 上运行该应用程序。

I am writing an application which need to send data to a serial device attached to a COM port.
I am confused as to what is the best way to deal with such a device?

Shall I write the communication module in C++ or shall I write this in Java?

I want to run the application on Windows as well as Linux.

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

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

发布评论

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

评论(6

还不是爱你 2024-09-15 21:08:55

在 Linux 上,我推荐 libserial。您也可以考虑使用Python。有一个多平台 pySerial 模块。如果您决定使用 Java,rxtx 是一个多平台库。在 Windows 上,您可以使用 Windows API 进行串行通信 并将其与 libserial 结合使用按照 @Dharma 的建议使用 #ifndef

On Linux I would recommend libserial. You could also consider using Python. There is a multi platform pySerial module. If you decide for Java, rxtx is a multi platform library. On Windows you may use the Windows API for serial communications and combine it with libserial using #ifndef as @Dharma suggested.

我们只是彼此的过ke 2024-09-15 21:08:55

我推荐你:

Boost ASIO

QextSerialPort(基于 Qt)

I recommend you:

Boost ASIO

QextSerialPort (based on Qt)

我还不会笑 2024-09-15 21:08:55

您可以通过为 Windows 代码指定 #ifndef“_WINDOWS_CODE” 为 Linux 代码指定 else 部分来用 C++ 编写模块。

在 Vc++ 中编译时,将 (_WINDOWS_CODE) 宏放入项目设置中
并在 gc++ 中从项目文件中删除宏

You can write the module in c++ by specyfying the #ifndef "_WINDOWS_CODE" for windows code and else part for the linux code.

while compiling in Vc++ put the (_WINDOWS_CODE)macros in the projecty settings
and in gc++ remove the macro from project file

贪了杯 2024-09-15 21:08:55

COM 端口只是一个普通的位管。 API 预计相当简单。在 C++ 中,世界在写入端口方面拥有更多的经验。

另一个问题是 - 你知道它是什么端口号吗?有多种方法可以确定哪一个是您的,例如 Windows 上的设置 API。

COM port is just a plain bit pipe. The APIs are expected to be fairly simple. In C++, the world has much more experience with writing to ports.

Other question would be - do you know what port number it is? There're several ways to find out which one is yours, like setup API on windows.

黑色毁心梦 2024-09-15 21:08:55

我的建议是,如果您想在 Linux 和 Windows 上运行应用程序,请选择 JAVA!。您无需编译即可运行您的程序。否则你必须为 Windows 和 Linux 分发单独的二进制文件。

另外还有在 Windows 和 Linux 中使用 C++ 访问 SerialPort 的编程模型,由于我是一名 Windows C++ 开发人员,因此您可以使用 CreateFile WIn32 Api 来访问串行端口。

My suggestion, if you want to run you application in both linux and Windows, go for JAVA!. you can run your program without any need of compilation. otherwise you have to distribute seperate binary for both Windows and Linux.

Also programming model in both windows and linux for accessing SerialPort in C++, As i am preliminary a Windows C++ developer, you can use CreateFile WIn32 Api to access serial port.

海未深 2024-09-15 21:08:55

我要写通信模块吗
用 C++ 写还是用 JAVA 写?

你对哪个比较熟悉?您仅限于这两种语言吗?您还可以将 python 与 pyserial 一起使用。

您将此作为个人项目进行吗?是为了工作吗?还有其他人和你一起做这件事吗?他们更熟悉什么?

对于 C++,您可以使用 Boost.Asio

对于Java...我不知道。

shall i write the communication module
in C++ or shall i write this in JAVA?

Which are you more familiar with? Are you limited to these two languages? You could also use python with pyserial.

Are you doing this as a personal project? Is it for work? Is someone else working on this with you? What are they more familiar with?

For C++ you could use Boost.Asio.

For Java ... I don't know.

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