/* * Copyright (C) Siemens AG 2005. All Rights reserved. * * In addition and subject to the terms and conditions of the License Agreement * Siemens grants Licensee a non-exclusive, non-transferable, limited license * to transmit, reproduce, disseminate, utililize and/or edit the binary content * of this Software (IMlet) for the sole purpose of designing, developping and * testing Licensee's applications only in connection with Siemens TC65 wireless * module. Offenders will be held liable for payment of damages. * All rights created by patent grant or registration of a utility model or * design patent are reserved. * */ /* * @(#)RS232Demo.java 0.1 02/07/02 */ package example.rs232demo; import javax.microedition.midlet.*; import java.io.*; import java.util.*; import java.lang.String; import java.lang.Integer; import java.lang.Thread; import javax.microedition.io.*; import com.siemens.icm.io.*; import com.siemens.icm.io.file.*; import com.siemens.icm.io.ATCommand; import com.siemens.icm.io.ATCommandFailedException; import com.siemens.icm.io.ATStringConverter; import javax.microedition.io.Datagram; import javax.microedition.io.*; import java.util.Date; public class RS232Demo extends MIDlet implements Runnable { CommConnection commConn; InputStream inStream; OutputStream outStream; //End Files Names /** * RS232Demo - default constructor */ public RS232Demo() { try { atc = new ATCommand(false); ATListenerB card_listener = new ATListenerB(); atc.addListener(card_listener); InitComPort(); // outStream.write("HelloWorld".getBytes()); } catch (Exception e) { System.out.println(e); try { outStream.write(e.getMessage().getBytes()); outStream.flush(); } catch (Exception r) { //Std.println("Exception: " + e.getMessage()); } notifyDestroyed(); } } class ATListenerB implements ATCommandListener { public void ATEvent(String Event) { Date Time; try { Time = new Date(); if (Event.indexOf(incomming_call) >= 0) { GetCall(Event); } } } catch (Exception e) { } } public void RINGChanged(boolean SignalState) { /* take some action when the RING signal changes if you want to */ } public void DCDChanged(boolean SignalState) { /* take some action when the DCD signal changes if you want to */ } public void DSRChanged(boolean SignalState) {} /* take some action when the DSR signal changes if you want to */ public void CONNChanged(boolean SignalState) {} /* take some action when the state of a connection changes if you want to */ } public void InitComPort() { try { String strCOM = "comm:com0;blocking=off;baudrate=115200"; commConn = (CommConnection) Connector.open(strCOM); inStream = commConn.openInputStream(); outStream = commConn.openOutputStream(); } catch (Exception e) { } } public void CloseComPort() { try { inStream.close(); outStream.close(); commConn.close(); } catch (Exception e) { } } /** * startApp() */ public void startApp() throws MIDletStateChangeException { try { try { int ch = -1; while (ch != 'Q') { ch = inStream.read(); if (ch >= 0) { outStream.write(ch); System.out.print( (char) ch); } } destroyApp(true); } catch (IOException e) { System.out.println(e); try { outStream.write(e.getMessage().getBytes()); } catch (Exception r) { //Std.println("Exception: " + e.getMessage()); } } } /** * pauseApp() */ public void pauseApp() { System.out.println("RS232Demo: pauseApp()"); } public void destroyApp(boolean cond) { try { outStream.write( (new String("The END")).getBytes()); CloseComPort(); atc.release(); } catch (Exception e) { try { outStream.write(e.getMessage().getBytes()); } catch (Exception r) { //Std.println("Exception: " + e.getMessage()); } System.out.println(e); } notifyDestroyed(); } }