其实我对串口一无所知.但我看到了一个发送命令的例子:
actually I know no thing about serial port. but I see an example of sending it an at-command:
echo -e "AT" > /dev/smd0
什么是/dev/smd0 以及为什么有时将其替换为/dev/ttyS0.
What is /dev/smd0 and why they sometimes replace it with /dev/ttyS0.
/dev/smd0
和 /dev/ttyS0
是 设备文件.此类文件是 虚拟文件,它们提供文件 I/O 操作接口,用于处理一些底层事物,例如例如串口、硬盘和内存等硬件资源,或者进程信息、随机数输入、终端屏幕输出等非硬件资源.
/dev/smd0
and /dev/ttyS0
are device files. Such files are virtual files that provide a file I/O operation interface for working with some underlying thing like for instance hardware resources like serial ports, hard disks and memory, or with non-hardware resources like process information, random number input, terminal screen output, etc.
设备文件有两种风格,字符和块.串口是字符设备,你可以验证 c
是 ls -l
输出的第一个字符:
Device files comes in two flavours, character and block. Serial ports are character devices, you can verify with c
being the first character in output from ls -l
:
$ ls -l /dev/ttyS0
crw-rw----. 1 root dialout 4, 64 Apr 7 00:25 /dev/ttyS0
$
<小时>
/dev/ttyS0
是 linux 桌面计算机上用于串口的设备名称,对应于 DOS/Windows 中的 COM1
(在非常非常早期使用了 linux /dev/cua
,你可能偶尔会遇到对它的引用).对于到手机的虚拟 USB 串行接口,使用 /dev/ttyACM0
和 /dev/ttyACM1
.其他一些设备使用/dev/ttyUSB0.对于 Android,使用了几个不同的设备文件名,其中 /dev/smd0
是其中之一.您的手机可能会使用另一部手机,因此您必须检查您应该专门为您的手机使用的手机.
/dev/ttyS0
is the device name used for serial ports on on linux desktop computers, corresponding to COM1
in DOS/Windows (in the very, very early days of linux /dev/cua
was used, you might occasionally encounter references to that). For virtual USB serial interfaces to mobile phones /dev/ttyACM0
and /dev/ttyACM1
are used. Some other devices use /dev/ttyUSB0. For Android there are a few different device file names in use where /dev/smd0
is one of them. Your phone might use another one, so you have to check what you should use specifically for your phone.
命令echo -e "AT" >/dev/smd0
没有意义.-e
选项可以解释反斜杠转义字符,但由于以下字符串不包含此类字符,因此它仅等效于 echo "AT" >/dev/smd0
.
The command echo -e "AT" > /dev/smd0
does not make sense. The -e
option enables interpretation of backslash-escaped characters, but since the following string contains no such characters it is equivalent to just echo "AT" > /dev/smd0
.
但是,当向调制解调器发送 AT 命令时,命令行应该仅以
结束,没有其他内容.这是由 V.250 规定的.
However, when sending AT commands to a modem, the command line should be terminated with only
and nothing else. This is mandated by V.250.
因此向调制解调器发送命令AT"的正确命令应该是
So the proper command to send the command "AT" to the modem should be
echo -n -e "AT
" > /dev/smd0
<小时>
但即使将 AT 命令正确发送到调制解调器,您也必须读回调制解调器的响应.在执行此操作时多次关闭和(重新)打开设备文件(您将通过运行一系列 shell 命令来完成)不是一个好方法,所以我建议您使用我的程序 atinout 专门写用于命令行 AT 命令通信:
But even when getting as far as sending the AT command correctly to the modem, you must read back the responses from the modem. Closing and (re-)opening the device file several times while doing this (which you will do by running a sequence of shell commands) is not a good way to go about, so I would recommend that you use my program atinout which is specifically written to be used for command line AT command communication:
$ echo AT | atinout - /dev/smd0 -
AT
OK
$
或
$ echo AT > input.txt
$ atinout input.txt /dev/smd0 output.txt
$ cat output.txt
AT
OK
$
这样您将正确执行所有调制解调器通信.
This way you will get all modem communication performed correctly.
这篇关于如何处理android手机中的串口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!