| Author |
Help needed in accessing com port(Urgent)
|
shuba karthik
Greenhorn
Joined: Sep 03, 2004
Posts: 14
|
|
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
|
 |
Nidheesh Puthalath
Ranch Hand
Joined: Sep 08, 2004
Posts: 30
|
|
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
|
-------------------------<br />Thanks & Regards<br />Nidheesh.P(SCJP)
|
 |
shuba karthik
Greenhorn
Joined: Sep 03, 2004
Posts: 14
|
|
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
Joined: Sep 03, 2004
Posts: 14
|
|
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
Joined: Sep 08, 2004
Posts: 30
|
|
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
|
 |
 |
|
|
subject: Help needed in accessing com port(Urgent)
|
|
|