E
Eta
Hi all,
I'm trying to make a Java class to connect my Laptop with a Phone (Nokia
6600) by Bluetooth Device(on Laptop I use a USB Bluetooth Dongle bridge
as COM Port) and send a String Message to the Phone. For Serial Device
connection and managing I use java COM API from Sun. When I try to run
the attached example code, the connection between phone and PC comes
activate (I see the message on Phone Diplay), but when I try to write
the String to Output Stream , it
does not transmit to the phone, and the class execution seems like being
in standby (doesn't stop or exit). You can find the follow line code
at the end of the example code :
outputStream.write(messageString.getBytes());
Does somebody help me??
Best regards,
Eta
PS:
Have a nice 2005 ... and sorry for my bad english!
/*
* Bluetooth Example
*
*/
package com.eta.blue.util;
import java.io.*;
import java.util.*;
import javax.comm.*;
public class COMAdapter {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
System.out.println(portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM10")) {
try {
serialPort = (SerialPort)
portId.open("text", 2000);
} catch (PortInUseException e) {
System.out.println("ERRORE GRAVE!!! : Porta in
uso!!");
serialPort.close();
}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
serialPort.close();
}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
serialPort.close();
}
try {
System.out.println("Trasferimento in corso!!");
outputStream.write(messageString.getBytes());
System.out.println("Fine trasferimento");
outputStream.flush();
} catch (IOException e) {
serialPort.close();
}
}
}
}
}
}
I'm trying to make a Java class to connect my Laptop with a Phone (Nokia
6600) by Bluetooth Device(on Laptop I use a USB Bluetooth Dongle bridge
as COM Port) and send a String Message to the Phone. For Serial Device
connection and managing I use java COM API from Sun. When I try to run
the attached example code, the connection between phone and PC comes
activate (I see the message on Phone Diplay), but when I try to write
the String to Output Stream , it
does not transmit to the phone, and the class execution seems like being
in standby (doesn't stop or exit). You can find the follow line code
at the end of the example code :
outputStream.write(messageString.getBytes());
Does somebody help me??
Best regards,
Eta
PS:
Have a nice 2005 ... and sorry for my bad english!
/*
* Bluetooth Example
*
*/
package com.eta.blue.util;
import java.io.*;
import java.util.*;
import javax.comm.*;
public class COMAdapter {
static Enumeration portList;
static CommPortIdentifier portId;
static String messageString = "Hello, world!\n";
static SerialPort serialPort;
static OutputStream outputStream;
public static void main(String[] args) {
portList = CommPortIdentifier.getPortIdentifiers();
while (portList.hasMoreElements()) {
portId = (CommPortIdentifier) portList.nextElement();
System.out.println(portId.getName());
if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
if (portId.getName().equals("COM10")) {
try {
serialPort = (SerialPort)
portId.open("text", 2000);
} catch (PortInUseException e) {
System.out.println("ERRORE GRAVE!!! : Porta in
uso!!");
serialPort.close();
}
try {
serialPort.setSerialPortParams(9600,
SerialPort.DATABITS_8,
SerialPort.STOPBITS_1,
SerialPort.PARITY_NONE);
} catch (UnsupportedCommOperationException e) {
serialPort.close();
}
try {
outputStream = serialPort.getOutputStream();
} catch (IOException e) {
serialPort.close();
}
try {
System.out.println("Trasferimento in corso!!");
outputStream.write(messageString.getBytes());
System.out.println("Fine trasferimento");
outputStream.flush();
} catch (IOException e) {
serialPort.close();
}
}
}
}
}
}