COM 端口 - 如何识别设备 (.net/c#)
我正在为 Windows CE 编程,并且需要连接到扫描仪。没有问题 - 我知道它在端口 COM0 上,但是如果我早些时候插入另一个设备,它会获得另一个 COM 端口...要获取所有 com 端口,简单的方法是:
SerialPort.GetPortNames()
但我不知道如何识别设备?有没有标准的方法?我无法“ping”它,因为有一个设备只发送数据...它一直在发送垃圾数据...而且我不知道如何“ping”设备...
I'm programming for Windows CE and I need to connect to a scanner. There is no problem - I know that it is on port COM0, but if I plug in another device earlier it gets another COM port... to get all com ports the easy way is:
SerialPort.GetPortNames()
But I don't know how to identify a device? Is there any standard way? I can't 'ping' it since there is one device that only sends data... it spams data all the time... and I don't know how to 'ping' a device...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
串行连接的问题是无状态。你无法知道对方是否有人在听或者谁在听。
要找出这一点,您有几个选择:
AT
到调制解调器,然后您将收到OK
因此,如果您无法使用上述任何方法,则无法自动检测要使用的端口,因此唯一的工作模型是询问用户正确的设置(例如具有可用端口或波特率的组合框)。 、不同布尔配置设置的复选框等)。
The problem of a serial connection is that is stateless. You can't know if anyone is on the other side listening or who is listening.
To find this out you just have a few choices:
AT
and you'll receive anOK
.So if you can't use any of the above methods you can't automatically detect which port to use. So the only working model is to ask the user for the correct setting(s) (e.g. ComboBox with available ports or BaudRates, CheckBoxes for the different boolean configuration settings, etc).