1. 程式人生 > >linux增加串列埠傳送檔案功能 以及minicom

linux增加串列埠傳送檔案功能 以及minicom

特此宣告我是轉載的,紅字部分為我新增的。

安裝配置minicom並實現通過minicom傳輸檔案

參考文獻:
嵌入式linux系統與主機通過串列埠傳輸檔案
ubuntu 下minicom的安裝及使用
作業系統:ubuntu10.04
交叉編譯器:arm-linux-gcc-4.1.1
一、安裝配置minicom
1、安裝minicom
[email protected]:~$ sudo apt-get install minicom
2、配置minicom
[email protected]:~$ sudo minicom -s
出現這樣的配置介面:
+-----[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 |
+--------------------------+
選擇Serial port setup, 會看到這樣的選項:
+-----------------------------------------------------------------------+
| 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? |
+-----------------------------------------------------------------------+
輸入前面對應的字母即可進入相應的選項。將選項A的值設定為/dev/ttyS0 表示是串列埠1,將選項E的值設定為115200,將選項F設定為NO(請根據實際情況配置).
設定預設上傳/下載的目錄,選擇Filenames and paths , 會看到這樣的選項:
+-----------------------------------------------------------------------+
| A - Download directory : /home/lingd/arm/download |
| B - Upload directory : /home/lingd/arm/upload |
| C - Script directory : |
| D - Script program : runscript |
| E - Kermit program : |
| F - Logging options |
| |
| Change which setting? |
+-----------------------------------------------------------------------+
注意:開發板傳送給pc的檔案將儲存在Download directory所設定的目錄中,而pc要下載到開發板的檔案儲存在Upload directory所設定的目錄中
設定完成後,選擇”Save setup as dfl”,儲存為預設設定.
然後選擇“Exit”,即可進入Minicom的主介面:
Welcome to minicom 2.4

OPTIONS: I18n
Compiled on Jan 25 2010, 06:49:09.
Port /dev/ttyS0

Press CTRL-A Z for help on special keys

按Ctrl-A,再按z,可以獲取到minicom CTRL-A命令的幫助資訊
Welco+-------------------------------------------------------------------+
| Minicom Command Summary |
OPTIO| |
Compi| Commands can be called by CTRL-A <key> |
Port | |
| Main Functions Other Functions |
Press| |
| 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 |
+-------------------------------------------------------------------+
CTRL-A Z for help |115200 8N1 | NOR | Minicom 2.4 | VT102 | Offline
其中,我們用CTRL-A s來發送檔案給開發板;而用CTRL-A r來接收開發板上的檔案
二、為pc安裝lrzsz
lrzsz is a unix communication package providing the XMODEM, YMODEM ZMODEM file transfer protocols.
[email protected]
:~$ sudo apt-get install lrzsz
三、交叉編譯lrzsz並下載到開發板上
1、下載lrzsz原始碼包
到http://download.chinaunix.net/download/0007000/6293.shtml,下一個lrzsz的tar包,
2、解壓縮後,到解壓目錄中執行./configure
[email protected]:~/arm$ tar -zxf lrzsz-0.12.20.tar.gz
[email protected]:~/arm$ cd lrzsz-0.12.20/
[email protected]:~/arm/lrzsz-0.12.20$ ./configure
creating cache ./config.cache
checking for a BSD compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking whether make sets ${MAKE}... yes
checking for working aclocal... missing
checking for working autoconf... missing
checking for working automake... missing
checking for working autoheader... missing
checking for working makeinfo... missing
checking for gcc... gcc
checking whether the C compiler (gcc ) works... yes
checking whether the C compiler (gcc ) is a cross-compiler... no
checking whether we are using GNU C... yes
checking whether gcc accepts -g... yes
checking how to run the C preprocessor... gcc -E
checking whether gcc needs -traditional... no
checking for ranlib... ranlib
checking for POSIXized ISC... no
checking for AIX... no
checking for minix/config.h... no
checking for gcc option to accept ANSI C... none needed
checking for function prototypes... yes
checking for working const... yes
checking for inline... inline
checking for syslog in -lsocket... no
checking for syslog in -lbe... no
checking for gethostbyname in -lnsl... yes
checking for ANSI C header files... yes
checking for fcntl.h... yes
checking for limits.h... yes
checking for sys/ioctl.h... yes
checking for sys/time.h... yes
checking for unistd.h... yes
checking for sys/times.h... yes
checking for termios.h... yes
checking for sys/termios.h... yes
checking for termio.h... yes
checking for sys/termio.h... no
checking for sgtty.h... yes
checking for termios.h... (cached) yes
checking for sys/termios.h... (cached) yes
checking for termio.h... (cached) yes
checking for sys/termio.h... (cached) no
checking for sgtty.h... (cached) yes
checking for sys/mman.h... yes
checking for utime.h... yes
checking for syslog.h... yes
checking for sys/syslog.h... yes
checking for sys/param.h... yes
checking for sys/select.h... yes
checking for strings.h... yes
checking for arpa/inet.h... yes
checking for size_t... yes
checking for mode_t... yes
checking for off_t... yes
checking for speed_t... yes
checking for st_rdev in struct stat... yes
checking whether time.h and sys/time.h may both be included... yes
checking whether sys/time.h and sys/select.h may both be included... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for errno declaration... yes
checking whether setvbuf arguments are reversed... no
checking return type of signal handlers... void
checking for unistd.h... (cached) yes
checking for getpagesize... yes
checking for working mmap... yes
checking for working alloca.h... yes
checking for alloca... yes
checking for gettimeofday... yes
checking for settimeofday... yes
checking for strchr... yes
checking for memcpy... yes
checking for select... yes
checking for vprintf... yes
checking for times... yes
checking for rdchk... no
checking for utime... yes
checking for syslog... yes
checking for siginterrupt... yes
checking for mkdir... yes
checking for mktime... yes
checking for strerror... yes
checking for strstr... yes
checking for strdup... yes
checking for strtoul... yes
checking for strtol... yes
checking for strpbrk... yes
checking for stpcpy... yes
checking for strftime... yes
checking for vasprintf... yes
checking for getopt_long... yes
checking for ftime... yes
checking that ftime works correctly... yes
checking for timezone variable... yes
checking for LOG_UUCP... yes
checking for argz.h... yes
checking for limits.h... (cached) yes
checking for locale.h... yes
checking for nl_types.h... yes
checking for malloc.h... yes
checking for string.h... yes
checking for unistd.h... (cached) yes
checking for values.h... yes
checking for sys/param.h... (cached) yes
checking for getcwd... yes
checking for munmap... yes
checking for putenv... yes
checking for setenv... yes
checking for setlocale... yes
checking for strchr... (cached) yes
checking for strcasecmp... yes
checking for __argz_count... yes
checking for __argz_stringify... yes
checking for __argz_next... yes
checking for LC_MESSAGES... yes
checking whether NLS is requested... yes
checking whether included gettext is requested... no
checking for libintl.h... yes
checking for gettext in libc... yes
checking for msgfmt... /usr/bin/msgfmt
checking for dcgettext... yes
checking for gmsgfmt... /usr/bin/msgfmt
checking for xgettext... /usr/bin/xgettext
checking for catalogs to be installed... de
updating cache ./config.cache
creating ./config.status
creating Makefile
creating intl/Makefile
creating lib/Makefile
creating testsuite/Makefile
creating man/Makefile
creating po/Makefile.in
creating src/Makefile
creating debian/rules
creating Specfile
creating systype
creating src/lrzszbug
creating config.h
3、修改Makefile
有三個Makefile需要修改,分別是~/arm/lrzsz-0.12.20/Makefile、~/arm/lrzsz-0.12.20/lib/Makefile、~/arm/lrzsz-0.12.20/src/Makefile
[email protected]
:~/arm/lrzsz-0.12.20$ vi Makefile
[email protected]:~/arm/lrzsz-0.12.20$ vi lib/Makefile

[email protected]:~/arm/lrzsz-0.12.20$ vi src/Makefile

這個地方不僅僅要修改這個三個資料夾裡的Makefile 其他資料夾裡的也要修改,切記!

將這三個Makefile中的所有gcc替代成你開發板所需要的交叉編譯器,如arm-linux-gcc
即:
CC = gcc
CPP = gcc -E
都改成
CC = arm-linux-gcc
CPP = arm-linux-gcc -E
4、編譯
[email protected]
:~/arm/lrzsz-0.12.20$ make
在lrzsz-0.12.20/src目錄下會生成兩個可執行檔案lsz、lrz(或者sz、rz),把它們下載到開發板linux系統的/bin目錄下。
[email protected]:~/arm/lrzsz-0.12.20$ cd src
[email protected]:~/arm/lrzsz-0.12.20/src$ ls
ansi2knr.1 lrz lsyslog.o Makefile.in tcp.o zm.o
ansi2knr.c lrz.c lsz protname.c timing.c zmodem.h
canit.c lrz.o lsz.c protname.o timing.h zperr.c
canit.o lrzszbug lsz.o rbsb.c timing.o zperr.o
crctab.c lrzszbug.in Makefile rbsb.o zglobal.h zreadline.c
crctab.o lsyslog.c Makefile.am tcp.c zm.c zreadline.o
四、測試
1、開發板-->PC機
在開發板上輸入 lsz filename,然後會出現一個傳輸介面,傳輸完成後可以在你設定的預設下載目錄Download directory裡找到這個檔案。
2、PC機-->開發板
在開發板上先進入/tmp 目錄,然後輸入lrz。
# cd /tmp
# lrz
?z waiting to receive.**B0100000023be50
按Ctrl-A,再按s,選擇zmoden,會出現一個選擇檔案的介面,選擇你要傳輸的檔案(按一下空格鍵選擇目錄,按兩下空格鍵進入目錄),回車後出現一個傳輸介面,傳輸完成後,便可以在開發板的/tmp目錄下找到這個檔案了。