Re: [javacint] TC65i read serial

210 views
Skip to first unread message

Nikita Kapitonov

unread,
Jan 18, 2013, 6:57:00 AM1/18/13
to java...@googlegroups.com
Yes, I think you can, why not.



2013/1/18 Luís Felipe de Andrade <luis.felipe...@gmail.com>
Hi everyone,


I'm a newbie developing to TC65i. I created a program that had run perfect, it sends a SMS to a number in a loop  and  i feel that's a good  beginning.
So, now i need that my terminal read data from my serial ASC1 port,  the data is sent by a datalogger. Would be possible connect pc-to-terminal using the port ASC0 to debug this data?while the datalogger is working in ASC1 port.

Thanks! 

--
javacint group - http://www.javacint.com/
 
 

Luís Felipe de Andrade

unread,
Jan 19, 2013, 5:42:52 AM1/19/13
to java...@googlegroups.com
Here is my code, for some reason, never enter inside the while.
Even if my CR200X(the ASC1 connection print something).


package hello;

import java.io.IOException;  
import java.io.InputStream;  
import java.io.OutputStream;  

import javax.microedition.midlet.*;
import com.siemens.icm.io.*;
import javax.microedition.io.CommConnection;  
import javax.microedition.io.Connector;  
public class Core implements Runnable {
    private int ch;
    

    private Thread _thread = new Thread( this, "core" );
    private boolean _loop;
    private ATCommand _ATC;
    
    public InputStream in;  
    public OutputStream out;  
    CommConnection con;  
    
    public void start(ATCommand atCommand) {
        _loop = true;
        _ATC = atCommand;
        _thread.start();
    }
    
    public void stop() throws InterruptedException {
        _loop = false;
        _thread.join();
    }
    
    public void run() {
        while (_loop) {
            try {
                System.out.println("Running core...");
                /*this.teste(_ATC);*/
                con = (CommConnection) Connector.open("comm:COM1;baudrate=115200;blocking=off;autocts=off;autorts=off");
                in = con.openInputStream();
                StringBuffer sb;
                sb = new StringBuffer();
                System.out.println("Before the loop");
                while((ch = in.read()) != -1)
                {
                    sb.append((char) ch);
                    System.out.println("In loop:" + ch);
                }
                System.out.println("After");
                in.close();
                con.close();
                Thread.sleep(60000);
            } 
            catch (Exception ex) {
                System.err.println("Exception " + ex.getClass() + " : " +
                ex.getMessage());
            }
        }
    }
    
    public void teste(ATCommand atCommand) {
        System.out.println("Running test...");
        
        try {
           
            String response = "";
            String phone = "04799318285";
            String message = "Oioioioi!";
            response = atCommand.send("AT+CMGF=1\r");
            System.out.println(response);
            response = "";
            
            synchronized (atCommand) {
                response = atCommand.send("AT+CMGS=04799318285,\r");
                if (response.indexOf('>') >= 0) {
                    try {
                        Thread.sleep(2000);
                    } 
                    catch (InterruptedException ex) {
               
                    }
                    response = atCommand.send(message + "\032" + "\r");
                    
                     System.out.println("entrou no if:"+ response);
                }
                else {
                     System.out.println("entrou no else");
                }
            }
            
            String URL, cc;
            /*
            URL = "comm:COM0;baudrate=115200;bitsperchar=8;stopbits=1;parity=none;blocking=off;autocts=off;autorts=off";
            cc = (CommConnection) Connector.open(URL, Connector.READ_WRITE);
            sb = new StringBuffer();
            int ch;
            doPause(20);  //waiting for the stick (break between found 3 and displaying the addresses)
            is = cc.openInputStream();
            while((ch = is.read()) != -1)
            {
                sb.append((char) ch);
            }
            is.close();
            cc.close();
*/
      
  
         
                
        } catch (ATCommandFailedException ex) {
            ex.printStackTrace();
        } catch (IllegalStateException ex) {
            ex.printStackTrace();
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();

Luís Felipe de Andrade

unread,
Jan 19, 2013, 8:20:01 AM1/19/13
to java...@googlegroups.com
After Nikita tips ("Try to open your connections before "while (_loop)" and close only after the block."), i finally read the data.
Now i'm working in the way that the data is showing up. Here it repeat with problem, i'll try to clean the buffer or something.

Thanks a lot, Nikita

public void run() {
        
        try {
            con = (CommConnection) Connector.open("comm:COM1;baudrate=9600;blocking=off;autocts=off;autorts=off");
            in = con.openInputStream();
            StringBuffer sb;
            sb = new StringBuffer();
                    
            while (_loop) {
                try {
                    //System.out.println("Running core...");
                    //this.teste(_ATC);
                    while ((ch = in.read()) != -1) {
                        sb.append((char) ch);
                        System.out.println("In loop:" + sb);
                        //_loop = false;
                        
                    }
                    

                    Thread.sleep(1000);
                } catch (Exception ex) {
                    System.err.println("Exception " + ex.getClass() + " : " + ex.getMessage());
                }
            }
            in.close();
            con.close();
        } catch (IOException ex) {
Reply all
Reply to author
Forward
0 new messages