📄 serial.html
字号:
</ul><p>If you have connected a terminal to the first serial port (<ttclass="DEVICENAME">COM1</tt> in <span class="TRADEMARK">MS-DOS</span>®), then youwill use <tt class="FILENAME">/dev/ttyd0</tt> to refer to the terminal. If the terminalis on the second serial port (also known as <tt class="DEVICENAME">COM2</tt>), use <ttclass="FILENAME">/dev/ttyd1</tt>, and so forth.</p></div></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN28570" name="AEN28570">20.2.3 Kernel Configuration</a></h2><p>FreeBSD supports four serial ports by default. In the <spanclass="TRADEMARK">MS-DOS</span> world, these are known as <ttclass="DEVICENAME">COM1</tt>, <tt class="DEVICENAME">COM2</tt>, <ttclass="DEVICENAME">COM3</tt>, and <tt class="DEVICENAME">COM4</tt>. FreeBSD currentlysupports ``dumb'' multiport serial interface cards, such as the BocaBoard 1008 and 2016,as well as more intelligent multi-port cards such as those made by Digiboard and StallionTechnologies. However, the default kernel only looks for the standard COM ports.</p><p>To see if your kernel recognizes any of your serial ports, watch for messages whilethe kernel is booting, or use the <tt class="COMMAND">/sbin/dmesg</tt> command to replaythe kernel's boot messages. In particular, look for messages that start with thecharacters <var class="LITERAL">sio</var>.</p><div class="TIP"><blockquote class="TIP"><p><b>Tip:</b> To view just the messages that have the word <varclass="LITERAL">sio</var>, use the command:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">/sbin/dmesg | grep 'sio'</kbd></pre></blockquote></div><p>For example, on a system with four serial ports, these are the serial-port specifickernel boot messages:</p><pre class="SCREEN">sio0 at 0x3f8-0x3ff irq 4 on isasio0: type 16550Asio1 at 0x2f8-0x2ff irq 3 on isasio1: type 16550Asio2 at 0x3e8-0x3ef irq 5 on isasio2: type 16550Asio3 at 0x2e8-0x2ef irq 9 on isasio3: type 16550A</pre><p>If your kernel does not recognize all of your serial ports, you will probably need toconfigure a custom FreeBSD kernel for your system. For detailed information onconfiguring your kernel, please see <a href="kernelconfig.html">Chapter 8</a>.</p><p>The relevant device lines for your kernel configuration file would look like this, forFreeBSD 4.X:</p><pre class="PROGRAMLISTING">device sio0 at isa? port IO_COM1 irq 4device sio1 at isa? port IO_COM2 irq 3device sio2 at isa? port IO_COM3 irq 5device sio3 at isa? port IO_COM4 irq 9</pre><p>and like this, for FreeBSD 5.X:</p><pre class="PROGRAMLISTING">device sio</pre><p>You can comment-out or completely remove lines for devices you do not have in the caseof FreeBSD 4.X; for FreeBSD 5.X you have to edit your <ttclass="FILENAME">/boot/device.hints</tt> file to configure your serial ports. Pleaserefer to the <a href="http://www.FreeBSD.org/cgi/man.cgi?query=sio&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sio</span>(4)</span></a> manual page formore information on serial ports and multiport boards configuration. Be careful if youare using a configuration file that was previously used for a different version ofFreeBSD because the device flags and the syntax have changed between versions.</p><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> <var class="LITERAL">port IO_COM1</var> is a substitution for <varclass="LITERAL">port 0x3f8</var>, <var class="LITERAL">IO_COM2</var> is <varclass="LITERAL">0x2f8</var>, <var class="LITERAL">IO_COM3</var> is <varclass="LITERAL">0x3e8</var>, and <var class="LITERAL">IO_COM4</var> is <varclass="LITERAL">0x2e8</var>, which are fairly common port addresses for their respectiveserial ports; interrupts 4, 3, 5, and 9 are fairly common interrupt request lines. Alsonote that regular serial ports <span class="emphasis"><iclass="EMPHASIS">cannot</i></span> share interrupts on ISA-bus PCs (multiport boards haveon-board electronics that allow all the 16550A's on the board to share one or twointerrupt request lines).</p></blockquote></div></div><div class="SECT2"><h2 class="SECT2"><a id="AEN28612" name="AEN28612">20.2.4 Device Special Files</a></h2><p>Most devices in the kernel are accessed through ``device special files'', which arelocated in the <tt class="FILENAME">/dev</tt> directory. The <ttclass="DEVICENAME">sio</tt> devices are accessed through the <ttclass="FILENAME">/dev/ttyd<var class="REPLACEABLE">N</var></tt> (dial-in) and <ttclass="FILENAME">/dev/cuaa<var class="REPLACEABLE">N</var></tt> (call-out) devices.FreeBSD also provides initialization devices (<tt class="FILENAME">/dev/ttyid<varclass="REPLACEABLE">N</var></tt> and <tt class="FILENAME">/dev/cuaia<varclass="REPLACEABLE">N</var></tt>) and locking devices (<ttclass="FILENAME">/dev/ttyld<var class="REPLACEABLE">N</var></tt> and <ttclass="FILENAME">/dev/cuala<var class="REPLACEABLE">N</var></tt>). The initializationdevices are used to initialize communications port parameters each time a port is opened,such as <var class="LITERAL">crtscts</var> for modems which use <varclass="LITERAL">RTS/CTS</var> signaling for flow control. The locking devices are used tolock flags on ports to prevent users or programs changing certain parameters; see themanual pages <a href="http://www.FreeBSD.org/cgi/man.cgi?query=termios&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">termios</span>(4)</span></a>, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=sio&sektion=4"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">sio</span>(4)</span></a>, and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=stty&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">stty</span>(1)</span></a> forinformation on the terminal settings, locking and initializing devices, and settingterminal options, respectively.</p><div class="SECT3"><h3 class="SECT3"><a id="AEN28641" name="AEN28641">20.2.4.1 Making Device SpecialFiles</a></h3><div class="NOTE"><blockquote class="NOTE"><p><b>Note:</b> FreeBSD 5.0 includes the <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=devfs&sektion=5&manpath=FreeBSD+6-current"><span class="CITEREFENTRY"><span class="REFENTRYTITLE">devfs</span>(5)</span></a>filesystem which automatically creates device nodes as needed. If you are running aversion of FreeBSD with <var class="LITERAL">devfs</var> enabled then you can safely skipthis section.</p></blockquote></div><p>A shell script called <tt class="COMMAND">MAKEDEV</tt> in the <ttclass="FILENAME">/dev</tt> directory manages the device special files. To use <ttclass="COMMAND">MAKEDEV</tt> to make dial-up device special files for <ttclass="DEVICENAME">COM1</tt> (port 0), <tt class="COMMAND">cd</tt> to <ttclass="FILENAME">/dev</tt> and issue the command <tt class="COMMAND">MAKEDEV ttyd0</tt>.Likewise, to make dial-up device special files for <tt class="DEVICENAME">COM2</tt> (port1), use <tt class="COMMAND">MAKEDEV ttyd1</tt>.</p><p><tt class="COMMAND">MAKEDEV</tt> not only creates the <ttclass="FILENAME">/dev/ttyd<var class="REPLACEABLE">N</var></tt> device special files, butalso the <tt class="FILENAME">/dev/cuaa<var class="REPLACEABLE">N</var></tt>, <ttclass="FILENAME">/dev/cuaia<var class="REPLACEABLE">N</var></tt>, <ttclass="FILENAME">/dev/cuala<var class="REPLACEABLE">N</var></tt>, <ttclass="FILENAME">/dev/ttyld<var class="REPLACEABLE">N</var></tt>, and <ttclass="FILENAME">/dev/ttyid<var class="REPLACEABLE">N</var></tt> nodes.</p><p>After making new device special files, be sure to check the permissions on the files(especially the <tt class="FILENAME">/dev/cua*</tt> files) to make sure that only userswho should have access to those device special files can read and write on them -- youprobably do not want to allow your average user to use your modems to dial-out. Thedefault permissions on the <tt class="FILENAME">/dev/cua*</tt> files should besufficient:</p><pre class="SCREEN">crw-rw---- 1 uucp dialer 28, 129 Feb 15 14:38 /dev/cuaa1crw-rw---- 1 uucp dialer 28, 161 Feb 15 14:38 /dev/cuaia1crw-rw---- 1 uucp dialer 28, 193 Feb 15 14:38 /dev/cuala1</pre><p>These permissions allow the user <tt class="USERNAME">uucp</tt> and users in the group<tt class="USERNAME">dialer</tt> to use the call-out devices.</p></div></div><div class="SECT2"><h2 class="SECT2"><a id="SERIAL-HW-CONFIG" name="SERIAL-HW-CONFIG">20.2.5 Serial PortConfiguration</a></h2><p>The <tt class="DEVICENAME">ttyd<var class="REPLACEABLE">N</var></tt> (or <ttclass="DEVICENAME">cuaa<var class="REPLACEABLE">N</var></tt>) device is the regulardevice you will want to open for your applications. When a process opens the device, itwill have a default set of terminal I/O settings. You can see these settings with thecommand</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">stty -a -f /dev/ttyd1</kbd></pre><p>When you change the settings to this device, the settings are in effect until thedevice is closed. When it is reopened, it goes back to the default set. To make changesto the default set, you can open and adjust the settings of the ``initial state'' device.For example, to turn on <var class="OPTION">CLOCAL</var> mode, 8 bit communication, and<var class="OPTION">XON/XOFF</var> flow control by default for <ttclass="DEVICENAME">ttyd5</tt>, type:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbdclass="USERINPUT">stty -f /dev/ttyid5 clocal cs8 ixon ixoff</kbd></pre><p>System-wide initialization of the serial devices is controlled in <ttclass="FILENAME">/etc/rc.serial</tt>. This file affects the default settings of serialdevices.</p><p>To prevent certain settings from being changed by an application, make adjustments tothe ``lock state'' device. For example, to lock the speed of <ttclass="DEVICENAME">ttyd5</tt> to 57600 bps, type:</p><pre class="SCREEN"><samp class="PROMPT">#</samp> <kbd class="USERINPUT">stty -f /dev/ttyld5 57600</kbd></pre><p>Now, an application that opens <tt class="DEVICENAME">ttyd5</tt> and tries to changethe speed of the port will be stuck with 57600 bps.</p><p>Naturally, you should make the initial state and lock state devices writable only bythe <tt class="USERNAME">root</tt> account.</p></div></div><div class="NAVFOOTER"><hr align="LEFT" width="100%" /><table summary="Footer navigation table" width="100%" border="0" cellpadding="0"cellspacing="0"><tr><td width="33%" align="left" valign="top"><a href="serialcomms.html"accesskey="P">Prev</a></td><td width="34%" align="center" valign="top"><a href="index.html"accesskey="H">Home</a></td><td width="33%" align="right" valign="top"><a href="term.html"accesskey="N">Next</a></td></tr><tr><td width="33%" align="left" valign="top">Serial Communications</td><td width="34%" align="center" valign="top"><a href="serialcomms.html"accesskey="U">Up</a></td><td width="33%" align="right" valign="top">Terminals</td></tr></table></div><p align="center"><small>This, and other documents, can be downloaded from <ahref="ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/">ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/</a>.</small></p><p align="center"><small>For questions about FreeBSD, read the <ahref="http://www.FreeBSD.org/docs.html">documentation</a> before contacting <<ahref="mailto:questions@FreeBSD.org">questions@FreeBSD.org</a>>.<br />For questions about this documentation, e-mail <<ahref="mailto:doc@FreeBSD.org">doc@FreeBSD.org</a>>.</small></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -