检查串行端口是否已连接到计算机。 [英] Check if serial port is connected to a machine .

查看:72
本文介绍了检查串行端口是否已连接到计算机。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道有哪些技术可以确定端口是连接到设备而不是串口仿真器。

是否可以检查数据到达的时间并确定它是否来自设备.. ??



我尝试过的事情:



我无法尝试其他任何事情,但检查数据到达时间但没有产生任何结果。

Hi, I would like to know what techniques are there to determine if a port is connected to a device and not to a serial port emulator .
Is it possible to check the timing of the data arrivals and determine if it from the device or not .. ??

What I have tried:

I couldn't try anything else but check the data arrival times but that yielded nothing .

推荐答案

如果设备已连接,您可以使用设备特定协议进行通信。如果失败,则没有设备连接或者是不同类型的设备。



串口仿真器是什么意思?



如果您的意思是一种模拟特定设备的软件,通常无法通过通信和计时确定是否使用了软件仿真或真实设备,因为此类仿真器的目标是模拟包括时间在内的真实设备的行为。



或者您是指USB转串口转换器之类的转换器?



在这两种情况下(软件模拟器和转换器),您都可以查询串行端口的系统信息,以检查它是真实端口还是虚拟端口。 CodeProject文章一个有用的WMI工具和放大器;如何查找USB到串行适配器 [ ^ ]提供了一个示例应用程序来查询可用于确定端口是真实还是虚拟的信息。



以上使用WMI查询信息。请参阅 c# - 如何通过友好名称打开串口? - 堆栈溢出 [ ^ ]。 SPDRP_SERVICE 属性将包含物理端口的Serial和虚拟端口的其他字符串。
If a device is connected you can communicate using the device specific protocol. If this fails, there is no device connected or it is a different kind of device.

What do you mean by serial port emulator?

If you mean a kind of software that emulates a specific device you can usually not determine by communication and timing if a software emulation or a real device is used because the goal of such emulators is to simulate the behaviour of a real device including the timings.

Or do you refer to a converter like an USB to serial converter?

In both cases (software emulator and converter) you can query the system information for the serial port to check if it is a "real" port or a virtual one. The CodeProject article A Useful WMI Tool & How To Find USB to Serial Adaptors[^] provides an example application to query the information which can be used to decide if a port is "real" or virtual.

The above uses WMI to query the information. See c# - How to open a serial port by friendly name? - Stack Overflow[^] for a solution using the SetupAPI. The SPDRP_SERVICE property will contain "Serial" for physical ports and other strings for virtual ones.


串行端口不支持任何检查。您只能检查计算机的串行端口是否未连接到某种类型的设备,这些设备将支持对某些明确定义的输入做出明确定义的响应。



时间严格地说,也不是一种补救措施,因为仿真器也可以支持一些模仿非常现实行为的时机。我认为你甚至不应该以这种方式提出问题。如果您在产品中使用模拟器,请提供模拟器,该模拟器的行为方式与设备的行为有所不同。不幸的是,我不知道你的工作场景建议更具体的东西,但主要的想法是你不能保护你的产品免受客户完全不合理的行为,但你可以设计一种方法来防止随机错误。< br $>


-SA
Serial port is not designed to support any kind of check up. You can only check up that a computer's serial port is not connected to certain kind of device which would support some well-defined response to certain well-defined input.

Timing, strictly speaking, is also not a remedy, because an emulator, too, can support some timing which would mimic quite realistic behavior. I don't think you should even pose the problem this way. If you use the emulator in your product, supply the emulator which behave in certain way different from the behavior of your device. Unfortunately, I don't know your working scenarios to advise something more concrete, but the main idea is that you cannot protect your product from a totally unreasonable behavior of a customer anyway, but you can devise a way to protect from random mistakes.

—SA


这篇关于检查串行端口是否已连接到计算机。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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