📄 commconnection.html
字号:
<H2> Security </H2> <P> Access to serial ports is restricted to prevent unauthorized transmission or reception of data. The security model applied to the serial port connection is defined in the implementing profile. The security model may be applied on the invocation of the <code>Connector.open()</code> method with a valid serial port connection string. Should the application not be granted access to the serial port through the profile authorization scheme, a <code>java.lang.SecurityException</code> will be thrown from the <code>Connector.open()</code> method. The security model MAY also be applied during execution, specifically when the methods <code>openInputStream()</code>, <code>openDataInputStream()</code>, <code>openOutputStream()</code>, and <code>openDataOutputStream()</code> are invoked. </P> <H2> Examples </H2> <P> The following example shows how a <code>CommConnection</code> would be used to access a simple loopback program. </P> <PRE> CommConnection cc = (CommConnection) Connector.open("comm:com0;baudrate=19200"); int baudrate = cc.getBaudRate(); InputStream is = cc.openInputStream(); OutputStream os = cc.openOutputStream(); int ch = 0; while(ch != 'Z') { os.write(ch); ch = is.read(); ch++; } is.close(); os.close(); cc.close(); </PRE> <P> The following example shows how a <code>CommConnection</code> would be used to discover available comm ports. </P> <PRE> String port1; String ports = System.getProperty("microedition.commports"); int comma = ports.indexOf(','); if (comma > 0) { // Parse the first port from the available ports list. port1 = ports.substring(0, comma); } else { // Only one serial port available. port1 =ports; } </PRE> <H2>Recommended Port Naming Convention</H2> <P> Logical port names can be defined to match platform naming conventions using any combination of alphanumeric characters. However, it is recommended that ports be named consistently among the implementations of this class according to a proposed convention. VM implementations should follow the following convention:<BR> Port names contain a text abbreviation indicating port capabilities followed by a sequential number for the port. The following device name types should be used: </P> <UL> <LI>COM#, where COM is for RS-232 ports and # is a number assigned to the port</LI> <LI>IR#, where IR is for IrDA IRCOMM ports and # is a number assigned to the port </LI> </UL> <P> This naming scheme allows API users to generally determine the type of port that they would like to use. For instance, if a application desires to "beam" a piece of data, the app could look for "IR#" ports for opening the connection. The alternative is a trial and error approach with all available ports. </P>
<P>
<DL>
<DT><B>Since: </B><DD>MIDP 2.0</DD>
</DL>
<HR>
<P>
<!-- ======== INNER CLASS SUMMARY ======== -->
<!-- =========== FIELD SUMMARY =========== -->
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=2><FONT SIZE="+2">
<B>Method Summary</B></FONT></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/microedition/io/CommConnection.html#getBaudRate()">getBaudRate</A></B>()</CODE>
<BR>
Gets the baudrate for the serial port connection.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> int</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../javax/microedition/io/CommConnection.html#setBaudRate(int)">setBaudRate</A></B>(int baudrate)</CODE>
<BR>
Sets the baudrate for the serial port connection.</TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_javax.microedition.io.InputConnection"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from interface javax.microedition.io.<A HREF="../../../javax/microedition/io/InputConnection.html">InputConnection</A></B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../../javax/microedition/io/InputConnection.html#openDataInputStream()">openDataInputStream</A>, <A HREF="../../../javax/microedition/io/InputConnection.html#openInputStream()">openInputStream</A></CODE></TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_javax.microedition.io.Connection"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from interface javax.microedition.io.<A HREF="../../../javax/microedition/io/Connection.html">Connection</A></B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../../javax/microedition/io/Connection.html#close()">close</A></CODE></TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_javax.microedition.io.OutputConnection"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TD><B>Methods inherited from interface javax.microedition.io.<A HREF="../../../javax/microedition/io/OutputConnection.html">OutputConnection</A></B></TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><A HREF="../../../javax/microedition/io/OutputConnection.html#openDataOutputStream()">openDataOutputStream</A>, <A HREF="../../../javax/microedition/io/OutputConnection.html#openOutputStream()">openOutputStream</A></CODE></TD>
</TR>
</TABLE>
<P>
<!-- ============ FIELD DETAIL =========== -->
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A><TABLE BORDER="1" CELLPADDING="3" CELLSPACING="0" WIDTH="100%">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TD COLSPAN=1><FONT SIZE="+2">
<B>Method Detail</B></FONT></TD>
</TR>
</TABLE>
<A NAME="getBaudRate()"><!-- --></A><H3>
getBaudRate</H3>
<PRE>
public int <B>getBaudRate</B>()</PRE>
<DL>
<DD>Gets the baudrate for the serial port connection.<DD><DL>
</DL>
</DD>
<DD><DL>
<DT><B>Returns:</B><DD>the baudrate of the connection<DT><B>See Also: </B><DD><A HREF="../../../javax/microedition/io/CommConnection.html#setBaudRate(int)"><CODE>setBaudRate(int)</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="setBaudRate(int)"><!-- --></A><H3>
setBaudRate</H3>
<PRE>
public int <B>setBaudRate</B>(int baudrate)</PRE>
<DL>
<DD>Sets the baudrate for the serial port connection. If the requested <code>baudrate</code> is not supported on the platform, then the system MAY use an alternate valid setting. The alternate value can be accessed using the <code>getBaudRate</code> method.<DD><DL>
</DL>
</DD>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>baudrate</CODE> - the baudrate for the connection<DT><B>Returns:</B><DD>the previous baudrate of the connection<DT><B>See Also: </B><DD><A HREF="../../../javax/microedition/io/CommConnection.html#getBaudRate()"><CODE>getBaudRate()</CODE></A></DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ========== START OF NAVBAR ========== -->
<A NAME="navbar_bottom"><!-- --></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/CommConnection.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
<strong>MID Profile</strong></EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
PREV CLASS
<A HREF="../../../javax/microedition/io/Connection.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html" TARGET="_top"><B>FRAMES</B></A>
<A HREF="CommConnection.html" TARGET="_top"><B>NO FRAMES</B></A></FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: INNER | FIELD | CONSTR | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: FIELD | CONSTR | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<!-- =========== END OF NAVBAR =========== -->
<HR>
<font size="-1"><a href="mailto:midp-feedback@risc.sps.mot.com">Submit a comment or suggestion</a> Version 2.0 of MID Profile Specification<br>Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries. Copyright (c) 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road,Palo Alto, California, 94303, U.S.A. All Rights Reserved.</font>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -