嵌入式linux,如何一键切换串口的使用?
我是一名商业程序员,拥有几年的 Linux 管理经验。我开始接触嵌入式Linux。昨天,我们正在讨论一种新的设备设计,有人问了我一些我无法回答的问题。
工程师们希望在带有串行端口的电子板上安装一些按钮。操作系统是Linux。
通常,当用户连接到串行端口时,协议将回答他而不是 Linux 登录提示。然而,如果他按下设备上的一系列按钮,Linux 提示符将在串行端口上回答他。
除了处理按钮中断处理的 Linux 驱动程序之外,如何才能像这样切换串行端口的基本用途呢?有人有关于如何执行此操作的 URL 参考吗? (最好有一些示例代码)
注意:我建议为给定用户提供一个不错的登录菜单,但没有办法。
感谢您提出任何建议。
此致, 伯特
I am a business programmer with a few years of Linux administration experience. I'm starting out in embedded Linux. Yesterday, we were discussing a new device design and I was asked a few questions I had no answers for.
The engineers want to have some push buttons on an electronic board with a serial port on it. The OS is Linux.
Normally, when a user will connect to the serial port, a protocol will answer him instead of a Linux login prompt. However, if he pushes a sequence of buttons on the device, a Linux prompt will answer him on the serial port instead.
The Linux driver to handle the push button interrupt handling aside, how can you switch the basic use of the serial port like that? Does anyone have a URL reference on how to do this? (preferably with some sample code)
Note: I proposed providing a nice menu on login for a given user, but no can do.
Thanks in advice for any suggestions.
Best regards,
Bert
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
主要问题是实现设备协议的进程可能保持串行端口打开。
在这种情况下,您可能应该:
等待按钮事件
让协议进程关闭串行端口 - 完全终止该进程也可能对您
启动
*getty
进程 - 或您的嵌入式目标用于在串行端口上显示登录提示的任何内容完成后恢复协议进程
编辑:
在上面的步骤中,我假设更常见的情况是控制串行端口的进程(例如
pppd
)无法充当getty
替代以提供登录提示。它通常也不是提供 telnet/SSH/任何登录的同一进程。也就是说,在定制的嵌入式 Linux 系统上,一个进程很可能会做不止一件事。在这种情况下,您必须配置或修改该流程以在适当的时候切换操作模式。
如果没有有关嵌入式目标的更多信息,就不可能提供更具体的答案。
The main problem is that the process that implements your device protocol is probably keeping the serial port open.
In this case you should probably:
Wait for the button event
Have the protocol process close the serial port - terminating that process completely might also do for you
Launch a
*getty
process - or whatever your embedded target uses to present a login prompt on the serial portRestore the protocol process once you are done
EDIT:
In the steps above I assume the more common case where the process that controls the serial port (e.g.
pppd
) is not able to act as agetty
substitute to provide a login prompt. It is also typically not the same process that provides telnet/SSH/whatever logins.That said, it's quite possible on a customised embedded Linux system for a process to do more than one thing. In that case you have to configure or modify that process to switch operational modes when appropriate.
Without more information about your embedded target it's impossible to provide a more specific answer.
getty
进程通常在串行端口上启动,以通过/sbin/init
提供登录提示,该提示在/etc/inittab
中配置。init
有“运行级别”的概念。每个运行级别定义一组单独的进程,init
将继续运行它们。实现此目的的一种优雅方法是设计“协议”进程,使其由init
启动,与getty
的方式相同。然后,您可以告诉init
在某些运行级别中运行您的进程,并在其他运行级别中运行getty
,并使用按钮在运行级别之间切换。例如,您的/etc/inittab
可能包括:这将在运行级别 3、4 和 5 的第一个串行端口上运行您的
protocol
命令;但getty
处于运行级别 2。The
getty
process is usually started on serial ports to provide a login prompt by/sbin/init
, which is configured in/etc/inittab
.init
has the concept of "runlevels". Each runlevel defines a separate set of processes thatinit
will keep running. One elegant way to implement this would be to design your "protocol" process so that it is started byinit
, in the same way asgetty
. You can then tellinit
to run your process in some runlevels, andgetty
in others, and have the pushbutton switch between runlevels. For example, your/etc/inittab
might include:This will run your
protocol
command on the first serial port in runlevels 3, 4 and 5; butgetty
in runlevel 2.