Click here to Skip to main content
15,887,302 members
Home / Discussions / Java
   

Java

 
GeneralRe: JChomboBox Pin
Kokkula9-May-14 19:27
Kokkula9-May-14 19:27 
GeneralRe: JChomboBox Pin
Richard MacCutchan9-May-14 21:41
mveRichard MacCutchan9-May-14 21:41 
QuestionHELP Pin
Member 107983016-May-14 1:40
Member 107983016-May-14 1:40 
SuggestionRe: HELP Pin
Richard MacCutchan6-May-14 6:00
mveRichard MacCutchan6-May-14 6:00 
GeneralRe: HELP Pin
Member 107983016-May-14 7:08
Member 107983016-May-14 7:08 
GeneralRe: HELP Pin
Richard MacCutchan6-May-14 9:06
mveRichard MacCutchan6-May-14 9:06 
AnswerRe: HELP Pin
TorstenH.6-May-14 21:26
TorstenH.6-May-14 21:26 
QuestionHow to Pin
mtouxx5-May-14 19:49
mtouxx5-May-14 19:49 
Hi guys i get code named Txmodem,that sends sms and i'd like to add that code to a previous code made by someone else, using a MVC model,and makes it work like actionlistener, so that the USER just press button to send...but IT GENERATE ERROR when i add this field on previous code..(Note:it works cause i received sms on my phone)
package opti;
import java.io.*;
import java.util.*;
import javax.comm.*;
/*
 * ===============================UVHC==========================================
 */
public class Txmodem implements  SerialPortEventListener, 
  CommPortOwnershipListener {
  static String comPort = "COM1"; // Port COM connecté au Modem 
 
  private CommPortIdentifier portId = null;
  private Enumeration portList;
  private InputStream inputStream = null;
  private OutputStream outputStream = null;
  private SerialPort serialPort;
  /**  instance  Txmodem */
  public Txmodem(String comm) {
    this.comPort = comm;
  }

  public boolean init() {
    portList = CommPortIdentifier.getPortIdentifiers();
    while (portList.hasMoreElements()) {
      portId = (CommPortIdentifier) portList.nextElement();
      if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
        if (portId.getName().equals(comPort)) {
          return true;
        }
      }
    }
    return false;
  }

 
  public void send(String cmd) {
    try {
      outputStream.write(cmd.getBytes());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  public void sendMessage(String phoneNumber, String message) {
    send("AT+CMGS=\"" + phoneNumber + "\"\r\n");// envoie la commande AT
  
    send(message);//envoie contenu du message 
    send("\032");// envoie du CtrlZ
  }

  public void connect() throws NullPointerException {
    if (portId != null) {
      try {
        portId.addPortOwnershipListener(this);
        serialPort = (SerialPort) portId.open("Txmodem", 2000);//ouverture du portSeri
      } catch (PortInUseException e) {
        e.printStackTrace();
      }
      try {
        inputStream = serialPort.getInputStream();
        outputStream = serialPort.getOutputStream();
      } catch (IOException e) {
        e.printStackTrace();
      }
      try {
        /** evenements sur le port*/
        serialPort.addEventListener(this);
        serialPort.notifyOnDataAvailable(true);
      } catch (TooManyListenersException e) {
        e.printStackTrace();
      }

    } else {
      throw new NullPointerException("COM Port non trouvé!!");
    }
  }
   
  public void serialEvent(javax.comm.SerialPortEvent serialPortEvent) {
    switch (serialPortEvent.getEventType()) {
      case SerialPortEvent.BI:
      case SerialPortEvent.OE:
      case SerialPortEvent.FE:
      case SerialPortEvent.PE:
      case SerialPortEvent.CD:
      case SerialPortEvent.CTS:
      case SerialPortEvent.DSR:
      case SerialPortEvent.RI:
      case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
      case SerialPortEvent.DATA_AVAILABLE:
        byte[] readBuffer = new byte[2048];
        try {
          while (inputStream.available() >
          0) 
          {
            int numBytes = inputStream.read(readBuffer);
          }
// response message
          System.out.print(new String(readBuffer));
        } catch (IOException e) {
        }
        break;
    }
  }
  
  public void ownershipChange(int type) {
    switch (type) {
      case CommPortOwnershipListener.PORT_UNOWNED:
        System.out.println(portId.getName() + ": PORT_UNOWNED");
        break;
      case CommPortOwnershipListener.PORT_OWNED:
        System.out.println(portId.getName() + ": PORT_OWNED");
        break;
      case CommPortOwnershipListener.PORT_OWNERSHIP_REQUESTED:
        System.out.println(portId.getName() + ": PORT_INUSED");
        break;
    }
  }
  public static void main(String args[]) {
    Txmodem gsm = new Txmodem(comPort);
    if (gsm.init()) {
      try {
        gsm.connect();
      
        Thread.sleep(5000);
        
        gsm.sendMessage("PHONENUMBER", "HERETEHMESSAGE");
        Thread.sleep(20000);
       
      } catch (Exception e) {
        e.printStackTrace();
      }
    } else {
      System.out.println("ne peut initialiser la carte");
    }
  }
}

QuestionRe: How to Pin
Richard MacCutchan5-May-14 20:39
mveRichard MacCutchan5-May-14 20:39 
Questionjava Pin
Member 107878361-May-14 2:14
Member 107878361-May-14 2:14 
AnswerRe: java Pin
Richard MacCutchan1-May-14 5:34
mveRichard MacCutchan1-May-14 5:34 
Questionplease reply as soon as possible Pin
Member 107875691-May-14 0:36
Member 107875691-May-14 0:36 
AnswerRe: please reply as soon as possible Pin
Richard MacCutchan1-May-14 0:50
mveRichard MacCutchan1-May-14 0:50 
GeneralRe: please reply as soon as possible Pin
Member 107875691-May-14 17:59
Member 107875691-May-14 17:59 
GeneralRe: please reply as soon as possible Pin
thatraja1-May-14 21:00
professionalthatraja1-May-14 21:00 
AnswerRe: please reply as soon as possible Pin
Member 1026233013-May-14 21:41
Member 1026233013-May-14 21:41 
QuestionIE not getting refresh to show the latest changes--spring MVC,jsp Pin
swarjava30-Apr-14 8:06
swarjava30-Apr-14 8:06 
AnswerRe: IE not getting refresh to show the latest changes--spring MVC,jsp Pin
Prasad Khandekar14-May-14 3:13
professionalPrasad Khandekar14-May-14 3:13 
QuestionGet data from database Pin
Ravi900kumar29-Apr-14 8:48
Ravi900kumar29-Apr-14 8:48 
QuestionRe: Get data from database Pin
Richard MacCutchan29-Apr-14 20:32
mveRichard MacCutchan29-Apr-14 20:32 
AnswerRe: Get data from database Pin
Tom Marvolo Riddle29-Apr-14 23:07
professionalTom Marvolo Riddle29-Apr-14 23:07 
QuestionNeed help on "Competition Scheduling" Algorithm Pin
N.Wang29-Apr-14 7:11
professionalN.Wang29-Apr-14 7:11 
SuggestionRe: Need help on "Competition Scheduling" Algorithm Pin
Richard MacCutchan29-Apr-14 20:31
mveRichard MacCutchan29-Apr-14 20:31 
QuestionHSQL where clause Pin
Nico Haegens29-Apr-14 6:43
professionalNico Haegens29-Apr-14 6:43 
AnswerRe: HSQL where clause Pin
Richard MacCutchan29-Apr-14 20:29
mveRichard MacCutchan29-Apr-14 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.