现在的位置: 首页 > 综合 > 正文

在虚拟机中用linux串口通信

2018年04月22日 ⁄ 综合 ⁄ 共 5185字 ⁄ 字号 评论关闭

转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://beartad.blogbus.com/logs/61731977.html

首先,将串口设备加入虚拟机中:setting->serial port->use physical port on the host->COM1->Finish

之后,查看Fedora中是否安装了minicom: rpm -qa|grep minicom,如果没有,那么:yum install minicom

安装成功之后对minicom进行设置:

以下内容转自:http://chen.y.168.blog.163.com/blog/static/1117773012009827105738591/

  安装好后,需要先对minicom进行配置,不能直接输入minicom,因为minicom运行时默认在/dev下有modem这个目录,而实际并没有,因此要修改默认的配置。一般第一次启动,需要使用命令minicom –s 对minicom进行配置,配置完成后,选择Save setup as df1,以后就可以直接使用minicom了。

(0)安装minicom,未配置前在终端中输入命令minicom,提示如:
#minicom
minicom: there is no global configuration file /etc/minirc.dfl
Ask your sysadmin to create on

e (with minicom -s).
(1)在root下,输入命令minicom –s,屏幕出现如下的界面:
# minicom -s
minicom: WARNING: configuration file not found, using defaults
            +-----[configuration]------+
            | Filenames and paths      |
            | File transfer protocols     |
            | Serial port setup             |
            | Modem and dialing         |
            | Screen and keyboard     |
            | Save setup as dfl           |
            | Save setup as..             |
            | Exit                                |
            | Exit from Minicom          |
           +------------------------------+

(2)设置serial port setup
  使用down箭头选择serial port setup,出现具体各选项的配置:
    +-----------------------------------------------------------------------+
   | A -    Serial Device      : /dev/modem                                  |
   | B - Lockfile Location     : /var/lock                                       |        
   | C -   Callin Program      :                                                    |
   | D -  Callout Program      :                                                   |
   | E -    Bps/Par/Bits       : 115200 8N1                                 |
   | F - Hardware Flow Control : Yes                                       |
   | G - Software Flow Control : No                                          |
    |                                                                                           |
   |    Change which setting?                                                    |
    +-----------------------------------------------------------------------+
说明:
将选项A的值设置为/dev/ttyS0表示是串口1,如用串口2,设置为/dev/ttyS1,依次类推;
将选项E的值(波特率)设置为115200;
将选项F的值(硬件流)改成No;
 
设置过程中命令的使用,例如需要修改选项A的值,在Change with setting?选项后输入
A则光标转移到A选项后,可以对A选项的值进行修改。
修改完后的界面如下:
     +---------------------------------------------------------------------+
    | A -    Serial Device      : /dev/ttyS0                                    |
    | B - Lockfile Location     : /var/lock                                     |
    | C -   Callin Program      :                                                   |
    | D -  Callout Program      :                                                  |
    | E -    Bps/Par/Bits       : 115200 8N1                                |
    | F - Hardware Flow Control : No                                        |
    | G - Software Flow Control : No                                         |

    |    Change which setting?                                                  | 

     +----------------------------------------------------------------------+
按回车退回[configuration]界面。
(3)在[configuration]界面中,选择Save setup as dfl。
  选择Save setup as dfl选项将修改后的配置信息进行保存为默认的配置选项。
(4)选择Exit from minicom 。
  选择Exit from minicom 选项从配置菜单返回到命令行。
(5)重新启动minicom,则可以使用。出现的界面如下:
#minicom
Welcome to minicom 2.3
OPTIONS: I18n
Compiled on Feb 26 2009, 00:28:35.
Port /dev/ttyS0

               Press CTRL-A Z for help on special keys

附加说明:
   minicom 启动后,先按 Ctrl+A 键,再按 Z 键(注意不是连续按,Ctrl+A松开后才按 Z) ,进入主配置界面。如按q可退回终端。
Welc    +---------------------------------------------------------------+
             |                     Minicom Command Summary              |
OPTIO |                                                                                 |
Compi  |        Commands can be called by CTRL-A<key>     |
Port     |                                                              |
|                           Main Functions                  Other Functions             |
|                                                                                                            |
| Dialing directory.......D    run script (Go).....G | Clear Screen...    ....C |
| Send files.................S    Receive files.........R | cOnfigure Minicom..O |
| comm Parameters....P    Add linefeed.........A | Suspend minicom....J |
| Capture on/off..........L    Hangup.................H | eXit and reset.........X |
| send break..............F    initialize Modem....M | Quit with no reset. ..Q |
| Terminal settings...T    run Kermit..............K | Cursor key mode......I |
| lineWrap on/off.......W    local Echo on/off....E | Help screen.............Z |
| Paste file.................Y                                     | scroll Back...............B |
|                                                                                                             |
|      Select function or press Enter for none.                                         |
|                                                                                                             |
|             Written by Miquel van Smoorenburg 1991-1995                     |
|             Some additions by Jukka Lahtinen 1997-2000                       |
|             i18n by Arnaldo Carvalho de Melo 1998                                 |
+-------------------------------------------------------------------------------------+串口转USB线在linux下使用
首先把usb转串口线插上然后用dmesg | grep usb查找如果看到:
“drivers/usb/serial/usb-serial.c: USB Serial support registered for Generic”
就说明设备已被识别,然后往下看
drivers/usb/serial/usb-serial.c: USB Serial support registered for PL-2303
usb 2-2: PL-2303 converter now attached to ttyUSB0 (or usb/tts/0 for devfs)
说明我的usb转串口芯片是PL-2303,对应系统设备是 dev/usb/tts/0,最后只需在minicom配置文件里将端口改成/dev/usb/tts/0就可以使用了:)

抱歉!评论已关闭.