Java MTCBA-G-EN-F4

Home Forums General Java MTCBA-G-EN-F4

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #7831
    James Lewis
    Participant

    Hello,

    I am trying to write a java program to connect to a MTCBA-G-EN-F4 however when connecting I only receive the following characters from the device

    65533,65533,65533,24,65533,32,65533,65533

    Any attempt at further communication fails. Please see my code below.

    I have no issues when using telnet through putty successfully sending text messages.

    Any help is much appreciated

    package smscommunicator;

    import ProcessSystems.global.PSGlobal;
    import java.io.BufferedReader;
    import java.io.BufferedWriter;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.net.SocketTimeoutException;

    /**
    *
    * @author lewisj
    */
    public class MultiTechModem {

    private final String ipAddress;
    private final int port;

    private Socket smsSock;
    private BufferedReader dataIn;
    private BufferedWriter dataOut;

    private boolean connected;

    public MultiTechModem(String anIpAddress, int aPort)
    {
    ipAddress = anIpAddress;
    port = aPort;

    connected = false;
    }

    public void sendMessage(SMSMessage aMessage)
    {
    try
    {
    connectToModem();

    dataOut.write(“at+cmgs=123456789\r\n”);
    dataOut.flush();
    dataOut.write(“This is a test026”);
    dataOut.flush();

    String str = dataIn.readLine();

    System.out.println(“Got data “+str);
    }
    catch(IOException e)
    {
    //If we have timed out don’t reset the connection as theres nothing wrong with it
    if(!e.getMessage().toUpperCase().contains(“READ TIMED OUT”))
    {
    PSGlobal.errorOut(“Unable to get information from device “+ipAddress+”/”+port+” “+e.getMessage());
    }

    resetConnection();
    }
    }

    private void connectToModem()
    {
    while(!connected)
    {
    try
    {
    smsSock = new Socket();
    smsSock.connect(new InetSocketAddress(ipAddress,port),10000);
    smsSock.setSoTimeout(10000);

    dataIn = new BufferedReader(new InputStreamReader(smsSock.getInputStream()));
    dataOut = new BufferedWriter(new OutputStreamWriter(smsSock.getOutputStream()));

    connected = true;

    }
    catch(SocketTimeoutException e)
    {
    PSGlobal.diagOut(“Timeout occured “+ipAddress+”/”+port);
    resetConnection();
    }
    catch(IOException e)
    {
    PSGlobal.errorOut(“connect to device failure “+ipAddress+”/”+port+” “+e.getMessage());
    resetConnection();
    }
    }
    }

    private void resetConnection()
    {
    //Close the data reader
    if(dataIn != null)
    {
    try
    {
    dataIn.close();
    }
    catch(IOException e)
    {
    PSGlobal.errorOut(“Unable to close reader “+ipAddress+”/”+port+
    ” “+e.getMessage());
    }
    }

    //Close the data writer
    if(dataOut != null)
    {
    try
    {
    dataOut.close();
    }
    catch(IOException e)
    {
    PSGlobal.errorOut(“Unable to close the data writer “+ipAddress+”/”+port+
    ” “+e.getMessage());
    }
    }

    //Close the writer
    if(smsSock != null)
    {
    try
    {
    smsSock.close();
    }
    catch(IOException e)
    {
    PSGlobal.errorOut(“Unable to close socket “+ipAddress+”/”+port+
    ” “+e.getMessage());
    }
    }

    connected=false;
    }
    }

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.