Thread: read com-port
View Single Post
Old 03-31-2008, 01:56 AM   #1
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default read com-port

Please Login to Remove!

hi,
i would like to read incomming data from the com port (Bluetooth) of my BlackBerry (8707).
how many com ports are there?
i've tried this example here:
Code:
 private class InputThread extends Thread {
        public void run() {
            try {
                BluetoothSerialPortInfo[] info = BluetoothSerialPort.getSerialPortInfo();
                if (info == null /*|| info.length == 0*/) {
                    invokeAndWait( new Runnable() {
                        public void run() {
                            Dialog.alert("Kein Bluetooth Port für die Verbindung verfügbar!");
                            closePort();
                            System.exit(1);
                        }
                    });
                }
                System.out.println("Infostring: "+info[0].toString());
                _bluetoothConnection = (StreamConnection)Connector.open(info[0].toString(),Connector.READ_WRITE);
                _din = _bluetoothConnection.openDataInputStream();
                _dout = _bluetoothConnection.openDataOutputStream();
            } catch(IOException e) {
                invokeAndWait(new Runnable() {
                    public void run() {
                        Dialog.alert("Serieller Port konnte nicht geöffnet werden!");
                        closePort();
                        System.exit(1);
                    }
                });
            } catch (Exception e) {
                System.out.println("Keine Bluetooth unterstützung: "+e);
                invokeAndWait(new Runnable() {
                    public void run() {
                        Dialog.alert("Dieses BlackBerry Gerät unterstützt kein Bluetooth! ");
                        closePort();
                        System.exit(1);
                    }
                });
            }
            
            try {
                int type, offset, count;
                String value;
                for(;;) {
                    type = _din.readInt();
                    if (type == CONTENTS) {
                        String contents = _din.readUTF();
                        synchronized(Application.getEventLock()) {
                            myLabel.setText(contents);
                        }
                    } else if(type == NO_CONTENTS) {
                    } else {
                        throw new RuntimeException();
                    }
                }
            } catch(IOException ioe) {
                invokeLater(new Runnable() {
                    public void run() {
                        Dialog.alert("Probleme beim lesen vom Seriellen Port!");
                        closePort();
                        System.exit(1);
                    }
                });
            }
        }
    }
but this don't works, i always get the message
Quote:
Dialog.alert("Dieses BlackBerry Gerät unterstützt kein Bluetooth! ");
so is there a good way to read the data?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline   Reply With Quote