KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know that in J2ME CommConnection is the connection to use when working with serial port . I know there are the openInputStream and openOutputStream methods , but in fact I don't know how to transfer data from my MIDLet to the COM port ( the USB port into which the phone's cable is inserted , the phone is Alcatel OT-806D ). For example I want to send the text "Hello world". How to achieve that ? Here are codes : J2ME : import java.io.IOException; import java.io.OutputStream; import javax.microedition.io.CommConnection; import javax.microedition.io.Connector; import javax.microedition.lcdui.Command; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.lcdui.Form; import javax.microedition.midlet.*; public class SerialPortMidlet extends MIDlet implements CommandListener, Runnable { private Command upload = new Command("upload", Command.SCREEN, 0); private Command exit = new Command("exit", Command.SCREEN, 1); private Form f = new Form("test serial port"); private Thread uploadThread; private CommConnection com; private OutputStream os; public SerialPortMidlet() { f.addCommand(upload); f.addCommand(exit); f.setCommandListener(this); uploadThread = new Thread(this); } public void startApp() { Display.getDisplay(this).setCurrent(f); } public void pauseApp() { } public void destroyApp(boolean unconditional) { notifyDestroyed(); } public void commandAction(Command c, Displayable d) { if (c == upload) { uploadThread.start(); f.removeCommand(upload); } else if (c == exit) { if (uploadThread.isAlive()) { uploadThread.interrupt(); try {
Tags (comma-separated)
Save Edits
Cancel