×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    Nokia LD-3W with 3230

    Hello,

    i'm trying to connect Nokia 3230 to GPS Receiver ld-3w via the java bluetooth api.

    I have no problems with finding the device and open spp connection. When the device is connected, the application reads NMEA sentences line by line. If the interval between successive reads is short (50-200ms), receiver stops sending data after 40secs. If the interval is longer, the same happens after 45-60secs.

    I tried every possible code combination but this behaviour doesn't change.

    I can only close the connection and open it again, but closing the input stream takes almost 20seconds and if i try to open a connection immediatly after closing it, i get an exception (or no device is found). I have to wait another 40secs until the receiver is really disconnected and the open the connection.

    For every 40secs of data reading, i have more than 60secs of reconnecting.

    The inputstream available() method returns 0 after connecting, then 512. After 30seconds returns 300-350, after 35secs returns 0.

    Does anybody know a solution for this?

    thanks for you help

  2. #2
    Registered User
    Join Date
    May 2005
    Posts
    76

    Re: Nokia LD-3W with 3230

    Well I do not have 3230, sorry; all I can say is that I have had absolutely no problem with 6230i and LD-3W, I read data from the receiver byte by byte... could you post a code snippet, perhaps?

    Regards,
    hnipak

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    8

    Re: Nokia LD-3W with 3230

    I think it's a bug in 3230 because I tried it also on my sony-ericsson w800 and i had no problems.


    BluetoothConnection class:
    Code:
    public class BluetoothConnection {
        private StreamConnection stream;
        private DataInputStream in;
        private OutputStream out;
        
        private String url;
        
        public BluetoothConnection(String url) throws IOException {        
            this.url = url;        
            
            stream = (StreamConnection) Connector.open(url);
            
            in = stream.openDataInputStream();
            //out = stream.openOutputStream();
        }
            
        public synchronized void close() {
            /*
            try {
                out.close();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            /**/
            
            try {
                in.close();
            }
            catch(IOException e) {
                e.printStackTrace();
            }
            
            try {
                if (stream != null) {
                    stream.close();
                    stream = null;
                }
            }
            catch(IOException e) {
                e.printStackTrace();
            }
            
        }
        
        public DataInputStream getInputStream() {
            return in;
        }
        
        public OutputStream getOutputStream() {
            return out;
        }
        
        public boolean isClosed() {
            return (stream == null);        
        }    
        
        private StringBuffer lineBuffer = new StringBuffer();
        
        public String readLine() throws IOException {
            lineBuffer.setLength(0);
            
            int current;
            char c;
            
            while (true) {
                current = in.read();
                
                if (current == -1) {                
                    return null;                
                }
                
                c = (char)current;
                
                if (c == '\n') {
                    return lineBuffer.toString();
                }
                
                lineBuffer.append(c);            
            }
        }
    run method of the reading thread
    Code:
    public void run() {            
    
        boolean justConnected;
    
        while (true) {                
            Thread thread = this.thread;
    
            if (thread != Thread.currentThread()) break;
    
            justConnected = false;
    
            if (!connected) {
                closeConnection();
    
                connect();
    
                justConnected = true;
    
            }                
    
            if (!connected) {
                try {
                    Thread.sleep(5000);
                }
                catch (Exception e) {
                    e.printStackTrace();
                }
    
                continue;
            }
    
            try {
                String line = connection.readLine();
    
    
                if (line == null) {       
    
                    //the first line is misteriously null
                    if (!justConnected) {
                        connected = false;
    
                    }
    
                    continue;
                }
    
                Sentence sentence = Sentence.parse(line);
    
                if (sentence != null) {
                    handleSentence(sentence);
                }
    
            }
            catch (Exception e) {
                handler.error(e);
                connected = false;                    
            }
    
            try {                    
                thread.sleep(800);
                thread.yield();
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        closeConnection();
     
    }

Similar Threads

  1. Replies: 2
    Last Post: 2008-04-03, 19:02
  2. Nokia Mobile VPN Client
    By marcyl in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2003-12-01, 14:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×