我已经通过以下命令安装了 minicom:
sudo apt-get minicom
我通过 USB 转串行控制台电缆与 HP 5130 交换机连接。根据以下命令,我的串行端口名称为 /dev/ttyUSB0:
dmesg | grep tty
[ 0.000000] console [tty0] enabled
[49689.082419] usb 3-2: pl2303 converter now attached to ttyUSB0
额外检查:
ls -l /dev/ttyUSB0
如果我拔下 USB 电缆,会出现以下错误:
ls: cannot access /dev/ttyUSB0: No such file or directory
因此我认为 ttyUSB0 是正确的端口
我对minicom的设置进行了如下编辑:
+-----------------------------------------------------------------------+
| A - Serial Device : /dev/ttyUSB0 |
| B - Lockfile Location : /var/lock |
| C - Callin Program : |
| D - Callout Program : |
| E - Bps/Par/Bits : 9600 8N1 |
| F - Hardware Flow Control : Yes |
| G - Software Flow Control : No |
| |
| Change which setting? |
+-----------------------------------------------------------------------+
并启动 minicom
但是,除了这个之外我没有得到任何输出:
Welcome to minicom 2.7
OPTIONS: I18n
Compiled on Jan 1 2014, 17:13:22.
Port /dev/ttyUSB0, 15:02:26
Press CTRL-A Z for help on special keys
CTRL-A Z for help | 9600 8N1 | NOR | Minicom 2.7 | VT102 | Offline | ttyUSB0
我认为问题出在离线状态?
答案1
参见此部分...
F - 硬件流控制:是
将其更改为“否”(或关闭......无论什么)并重新启动 minicom。
答案2
当您拔下并重新插入 USB 时,设备会更改为/dev/ttyUSB1
或/dev/ttyUSB2
取决于您重新插入 USB 的次数。尝试连接另一台设备。
从错误来看 我相信当您重新插入 USB 时ls: cannot access /dev/ttyUSB0: No such file or directory
终端控制器会发生变化。/dev/ttyUSBX
答案3
就ls /dev/ttyUSB*
在那时sudo minicom -D /dev/ttyUSBx
您还可以使用我的 shell 脚本在新的终端中打开所有 minicom:
#!/bin/bash
open_minicom(){
PORT_IP=2
PORT_IP=$((PORT_IP+$1))
gnome-terminal -t "Minicom port $1 - 192.168.1.$PORT_IP" -x ./tmp_script"$1".sh
#./minicom_PORT.sh "$PORT_NUM"
}
generate_script(){
echo "$1"
PORT_NUM="$1"
PORT_IP=2
PORT_IP=$((PORT_IP+$1))
#gconftool-2 --set /apps/gnome-terminal/profiles/Default/title --type=string "Minicom port $PORT_NUM"
#############################generat script
touch tmp_script"$1".sh
chmod 777 tmp_script"$1".sh
cat <<EOT >> tmp_script"$1".sh
#!/usr/bin/expect -f
spawn sudo minicom -D /dev/ttyUSB$PORT_NUM -S set_ip"$PORT_IP".sh
expect {
-re ".*sword.*" {
exp_send "$pass\r"
}
}
interact
EOT
###############################
#open terminal
}
generate_eth(){
PORT_IP=2
PORT_IP=$((PORT_IP+$1))
touch set_ip"$PORT_IP".sh
chmod 777 set_ip"$PORT_IP".sh
cat <<EOT >> set_ip"$PORT_IP".sh
#!/bin/bash
ifconfig eth0 192.168.1.$PORT_IP down up
EOT
}
MY_distractor(){
rm tmp_script*.sh set_ip*.sh
}
#printf "\n$NUM_OF_PORTS\n"
##############################
# MAIN #
##############################
NUM_OF_PORTS="$(ls /dev/ttyUSB* | grep -v ^l | wc -l)"
if [ $# -eq 0 ]
then
printf "No password arguments supplied\n Plase run ./your_script password \n Exiting......\n" && exit 1;
else
pass="$1"
fi
if [ "$NUM_OF_PORTS" == "0" ]; then
printf "Not found any minicom ports\n Exiting......\n" && exit 1;
fi
for (( i=0; i < $NUM_OF_PORTS ; i++ ))
do
generate_script "$i"
done
echo "$(ls tmp_script*.sh)"
for (( i=0; i < $NUM_OF_PORTS ; i++ ))
do
generate_eth "$i"
done
for (( i=0; i < $NUM_OF_PORTS ; i++ ))
do
open_minicom "$i"
done
sleep 1
MY_distractor