串行端口上连接的多个设备 - 如何知道哪个设备连接到哪个端口
我有一些通过串行端口进行通信的设备。因为,它们并不总是连接到同一个串行端口,所以我需要确切地知道当我发送数据时我正在与哪个设备进行通信。如何检查哪个设备连接到哪个 com 端口。
i have a few devices that communicate through serial port. Since, they are not always connected to the same serial port, so i need to know exactly which device i'm communicating with when i send data. How can I check which device is connected to which com port.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最常用的解决方案是“ping”每个串行端口,然后检查回复。对您的设备进行编程,使其在收到特殊请求时回复特定消息,例如,如果收到“Hello”,它将回复“嗨,我是设备 X”。这样你就可以依次向每个串口发送“Hello”,等待一秒钟左右,如果收到你期望的回复,那么你就知道要使用哪个串口了。
但这可能会使连接到串行端口的某些设备感到困惑,因此您需要考虑用户连接的设备类型。在大多数情况下,如果您选择设备不希望接收的关键字,它只会丢弃您发送的请求并等待另一个请求。
The solution that is most often used is to "ping" each serial port and then check the reply. Program your device to reply with a certain message when it receives a special request, e.g. if it receives "Hello" it will reply "Hi, I'm device X". This way you can send "Hello" to each serial port in sequence, wait a second or so, and if you receive the reply you were expecting, then you know what serial port to use.
This might confuse some devices connected to the serial port though, so you need to consider what kind of devices your users have connected. In most cases, if you pick a keyword that the device is not expecting to receive, it will simply discard of the request you send it and wait for another request.
在某些情况下,rs-232 P'n'P 功能可能可用
In some cases rs-232 P'n'P features may be usable