如何使单独的进程共享通信端口 [英] How to make separate processes share communication port

查看:65
本文介绍了如何使单独的进程共享通信端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个蜂鸣器连接到不同引脚上的一个串口。我有一个可以产生两个实例的程序。我希望每个实例都能驱动一个蜂鸣器。我面临的问题是第二个实例无法使用CreateFile方法获取comport(COM1)的句柄,因为这会返回拒绝访问错误。



我不能找到一个权威的来源,但我遇到一些人说在谷歌搜索中无法共享COM端口句柄。现在我试图以某种方式复制第二个实例中的COM端口句柄并使用它。



它是否可能,你会怎么做?我正在寻找最简单的解决方案来达到预期的效果。很抱歉没有示例代码;我完全迷失了如何解决这个问题。

I've got two buzzers hooked up to one serial port on different pins. I've got a program which can spawn two instances. I want each instance to drive one buzzer each. The problem I'm facing is that the second instance cannot get a handle to the comport (COM1) using CreateFile method, as this returns access denied error.

I cannot find an authoritative source for this, but I've come across a few people saying that COM port handle cannot be shared in Google searching. Now I'm trying to somehow duplicate the COM port handle in the second instance and use it.

Is it possible at all and how would you do it? I'm looking for the simplest solution to achieve the desired results. Sorry for not having example codes; I'm absolutely lost in how to attack this problem.

推荐答案

Quote:

我找不到这方面的权威来源,但我遇到过一些人说COM端口句柄无法共享

I cannot find an authoritative source for this, but I've come across a few people saying that COM port handle cannot be shared

据我所知, Windows 。作为一种解决方法,您可以对服务器应用程序进行编码,该应用程序负责与向其发送请求的多个客户端进行串行通信(使用您喜欢的 IPC 技术)。然后,服务器可以序列化请求,以便将有意义的数据发送到串行端口。

As far as I know that's true on Windows. As a workaround you could code a server application that takes care of serial communication with several clients sending requests to it (using the IPC technique you prefer). Server could then serialize the requests in order to send meaningful data to the serial port.


这篇关于如何使单独的进程共享通信端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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