如何应对Android手机串口? [英] how to deal with the serial port in android mobile?

查看:379
本文介绍了如何应对Android手机串口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实我知道没有对串口的事情。但我看到它发送的一个例子的AT命令:

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.

的设备文件有两种版本,字符和块。串行端口字符设备,你可以用验证ç为输出的第一个字符从的ls -l <​​/ code>:

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台式机的设备名称,对应 COM1 在DOS / Windows的(在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.

命令回声-eAT&GT;为/ dev / SMD0 没有意义。在 -e 选项启用的反斜杠转义字符间pretation,但由于以下字符串不包含此类字符它仅相当于回声AT&GT;为/ 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发送到调制解调器的命令时,命令行应使用只用 \\ r ,没有别的终止。这是由 V.250 授权。

However, when sending AT commands to a modem, the command line should be terminated with only \r 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\r" > /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手机串口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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