• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Help needed in accessing com port(Urgent)  RSS feed

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to send some instructions to a device which is connected to com port.
The method that I use is
public void enableReader() {
try {
OutputConnection outConnection = (OutputConnection)
Connector.open("comm:0;baudrate=8400");
OutputStream out = outConnection.openOutputStream();
PrintStream output = new PrintStream (out);
output.print("wp0b00") ;
output.flush () ;
output.print("X") ;
output.flush () ;
output.print("C") ;
output.flush () ;
output.close();
out.close();
outConnection.close();
} catch (ConnectionNotFoundException error) {

} catch (IOException error) {

}
}
I am getting 'The requested protocol does not exist'.
Please let me know what is wrong with this code or else please give me some code or links that explains communicating with com port.

TIA,
Subhakarthik
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shubha,

We have a seperate Comm Communication class available in MIDP2 onwards.
this class would allow you to write and read some data streams to the comm port.
following is a the sample code for the same

private CommConnection commConn = null;
private String CommURL;
private byte[] byPacketData;
private java.io.OutputStream oStream;

public void sendRequest(String strURL,byte[] packetData) {
CommURL = strURL;
byPacketData = packetData;
(new Thread(this)).start();
}

public void run() {
try {
commConn = (CommConnection) Connector.open(CommURL);
oStream = commConn.openOutputStream();
oStream.write(byPacketData);
oStream.flush();
} catch (Exception e) {
System.out.println("Error in connection");
}
}

Hope this helps
Nidheesh
 
shuba karthik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nidheesh,

Thanks for the effort.
We are trying to run this in PDA which has CREME JVM installed.
Our version of creme supports CDC 1.0 and MIDP 1.0 only.
Any pointers to APIs to access com port which use the limited features of CDC 1.0 and MIDP 1.0 will also be helpful.

TIA,
Subhakarthik
 
shuba karthik
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nidheesh,

Creme supports Personal Profile 1.0 and I do not know about the MIDP version it is supporting. I am trying your code snippet and it will be of great help if you send me the valid format of URL string that can be passed as parameter for com port connection object.

TIA,
Subhakarthik
 
Nidheesh Puthalath
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shubha,

I am not sure abt the CREME JVM.
check if it has any Comm Communication API avaiilable in it because MIDP 1.0 doesn't have a CommConnection interface.
Some vendors has their own Comm API for MIDP1.0 mobiles.

URL format for CommConnection in MIDP1.0 is like this
Protocol ort_number;baudrate;bitsperchar;stopbits;parity;autocts;autorts

Example : comm:0;baudrate=38400;bitsperchar=8;stopbits=1;parity=none;autocts=off;autorts=off

Besh of Luck
Nidheesh
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!