Java Doc for CommConnection.java in  » 6.0-JDK-Modules » j2me » javax » microedition » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.io 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


javax.microedition.io.CommConnection

All known Subclasses:   com.sun.cdc.io.j2me.comm.Protocol,
CommConnection
public interface CommConnection extends StreamConnection(Code)
This interface defines a logical serial port connection. A "logical" serial port is defined as a logical connection through which bytes are transferring serially. The logical serial port is defined within the underlying operating system and may not necessarily correspond to a physical RS-232 serial port. For instance, IrDA IRCOMM ports can commonly be configured as a logical serial port within the operating system so that it can act as a "logical" serial port.

A comm port is accessed using a Generic Connection Framework string with an explicit port identifier and embedded configuration parameters, each separated with a semi-colon (;).

Only one application may be connected to a particular serial port at a given time. An java.io.IOException is thrown, if an attempt is made to open the serial port with Connector.open() and the connection is already open.

A URI with the type and parameters is used to open the connection. The scheme (defined in RFC 2396) must be:
comm:<port identifier>[<optional parameters>]

The first parameter must be a port identifier, which is a logical device name. These identifiers are most likely device specific and should be used with care.

The valid identifiers for a particular device and OS can be queried through the method System.getProperty() using the key "microedition.commports". A comma separated list of ports is returned which can be combined with a comm: prefix as the URL string to be used to open a serial port connection. (See port naming convention below.)

Any additional parameters must be separated by a semi-colon (;) and spaces are not allowed in the string. If a particular optional parameter is not applicable to a particular port, the parameter MAY be ignored. The port identifier MUST NOT contain a semi-colon (;).

Legal parameters are defined by the definition of the parameters below. Illegal or unrecognized parameters cause an IllegalArgumentException. If the value of a parameter is supported by the device, it must be honored. If the value of a parameter is not supported a java.io.IOException is thrown. If a baudrate parameter is requested, it is treated in the same way that the setBaudRate method handles baudrates. e.g., if the baudrate requested is not supported the system MAY substitute a valid baudrate, which can be discovered using the getBaudRate method.

Optional Parameters

Parameter Default Description
baudrate platform dependent The speed of the port.
bitsperchar 8 The number bits per character(7 or 8).
stopbits 1 The number of stop bits per char(1 or 2)
parity none The parity can be odd, even, or none.
blocking on If on, wait for a full buffer when reading.
autocts on If on, wait for the CTS line to be on before writing.
autorts on If on, turn on the RTS line when the input buffer is not full. If off, the RTS line is always on.

BNF Format for Connector.open() string

The URI must conform to the BNF syntax specified below. If the URI does not conform to this syntax, an IllegalArgumentException is thrown.

<comm_connection_string> ::= "comm:"<port_id>[<options_list>] ;
<port_id> ::= string of alphanumeric characters
<options_list> ::= *(<baud_rate_string>| <bitsperchar>| <stopbits>| <parity>| <blocking>| <autocts>| <autorts>) ;
; if an option duplicates a previous option in the
; option list, that option overrides the previous
; option
<baud_rate_string> ::= ";baudrate="<baud_rate>
<baud_rate> ::= string of digits
<bitsperchar> ::= ";bitsperchar="<bit_value>
<bit_value> ::= "7" | "8"
<stopbits> ::= ";stopbits="<stop_value>
<stop_value> ::= "1" | "2"
<parity> ::= ";parity="<parity_value>
<parity_value> ::= "even" | "odd" | "none"
<blocking> ::= ";blocking="<on_off>
<autocts> ::= ";autocts="<on_off>
<autorts> ::= ";autorts="<on_off>
<on_off> ::= "on" | "off"

Security

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 Connector.open() 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 java.lang.SecurityException will be thrown from the Connector.open() method. The security model MAY also be applied during execution, specifically when the methods openInputStream(), openDataInputStream(), openOutputStream(), and openDataOutputStream() are invoked.

Examples

The following example shows how a CommConnection would be used to access a simple loopback program.

 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();
 

The following example shows how a CommConnection would be used to discover available comm ports.

 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;
 }
 

Recommended Port Naming Convention

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:
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:

  • COM#, where COM is for RS-232 ports and # is a number assigned to the port
  • IR#, where IR is for IrDA IRCOMM ports and # is a number assigned to the port

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.


since:
   MIDP 2.0




Method Summary
public  intgetBaudRate()
     Gets the baudrate for the serial port connection.
public  intsetBaudRate(int baudrate)
     Sets the baudrate for the serial port connection.



Method Detail
getBaudRate
public int getBaudRate()(Code)
Gets the baudrate for the serial port connection. the baudrate of the connection
See Also:   CommConnection.setBaudRate



setBaudRate
public int setBaudRate(int baudrate)(Code)
Sets the baudrate for the serial port connection. If the requested baudrate is not supported on the platform, then the system MAY use an alternate valid setting. The alternate value can be accessed using the getBaudRate method.
Parameters:
  baudrate - the baudrate for the connection the previous baudrate of the connection
See Also:   CommConnection.getBaudRate



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.