串行端口 - 如何对我的设备执行安全搜索? [英] Serial port - how to perform safe search for my device?

查看:66
本文介绍了串行端口 - 如何对我的设备执行安全搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写与我自己设计的电子设备进行通信(通过串行端口)的应用程序.

Im writing application that communicate (via serial port) with electronic device which i designed myself.

当我的 PC 应用程序启动时 - 它会一一打开可用的 COM 端口并发送一些字符串(例如你是什么?").

When my PC application starts - it opens available COM ports one by one and it sends some string ("What are you?" for example).

我的设备经过编程,可以用自己的 ID 回答那个神奇的问题"(例如:我是监督员工的邪恶设备").

My device is programmed, to reply to that "magic question" with own ID (for example: "I am evil device for supervising employees").

当我的 PC 软件收到神奇回复"时,它开始正常工作,不再搜索其他端口.

When my PC software receive that "magic reply" it starts working normally and its not searching other ports anymore.

当然我不会在数据传输中使用愚蠢的问题,这只是示例.

Of course im not using stupid questions in data transmission, its just example.

问题是 - 我可以在所有(不忙)端口上发送字符串以发现我的设备吗?

如果可以的话——问题"字符串应该是什么样的?有没有标准化的标准?

If I can - how that "question" string should look? Are there any normalized standards?

这不是我桌上的第一个这样的项目,但现在我正在为小行业开发解决方案,我需要更多地关注我的应用程序在做什么,因为可能有其他设备连接到 COM 端口而我不知道他们会如何反应.

This is not first project like this on my desk, but now im developing solution for little industry and i need to pay more attention what my application is doing, because there may be other devices connected to COM ports and I do not know how they can react.

对不起,如果我犯了一些语言错误,英语是我的第三语言.

Im sorry, if i made some language mistakes, english is my third language.

提前感谢您的回复.

推荐答案

不,你不会想要那样做.

No, you wouldn't want to do that.

当您使用 COM 串行端口时,您不知道端口中插入了什么.它可能什么都没有,你的设备、调制解调器、鼠标(虽然我相信没有人再使用它了......)或任何你无法想象的东西.

When you are using COM serial port, you have no idea what is plugged into the port. It could be nothing, your device, a modem, a mouse (though I believe nobody uses this anymore...) or whatever you can't even imagine.

想象一下,如果它连接到另一台计算机(可能是 Linux/路由器),发送东西可能会导致执行那个命令",从而产生意想不到的效果(尽管您的程序可能没有注意到).或者如果它是一些编程错误的设备,它可能会触发固件中的错误,从而导致设备出现故障并导致其出现故障.

Imagine if it is connected to another computer (probably a Linux/router), sending things may lead to execution of "that command", thus creating unexpected effects (though your program may not notice). Or if it is some badly-programmed device, it may trigger a bug in the firmware, thus failing the device and making it malfunction.

简而言之,在最坏的情况下,您可能导致灾难性事件.

In short, in the worst case, you can cause a catastrophic event.

串行(我假设为 RS232 或 UART)通信没有指定的传输协议(与 USB 相比,有一个)来识别设备,因此它不是故障安全的.用户必须确保他选择了正确的端口.这大概是硬件厂商选择 USB 的原因之一,也是 USB 如此流行,甚至是电脑白痴的原因之一.

Serial (RS232 or UART I assume) communications don't have a designated transfer protocol (in contrast to USB which has one) to identify a device, so it isn't fail-safe. The user must make sure he selected the correct port. This is probably one of the reasons why hardware manufacturers choose USB, and one of the reasons why USB is so popular, even to computer idiots.

这篇关于串行端口 - 如何对我的设备执行安全搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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