Acidburn 0 Posting Pro

Hello there,

I'm trying to emulate a Bluetooth connection via coding the serial port. COM6 on my machine is an outgoing connection over bluetooth... So I'm mocked up the following code:

package btserver1;

import gnu.io.CommDriver;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.SerialPort;
import java.io.*;

public class Main {
    static String dataFile =null;
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            CommPortIdentifier pid=CommPortIdentifier.getPortIdentifier("COM4");
            SerialPort sPort=(SerialPort) pid.open("Serial Comm Testing",100);
 
            sPort.disableReceiveFraming();
            sPort.disableReceiveThreshold();
            
            sPort.setSerialPortParams(115200 , SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
            
            sPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
            
            //sPort.enableReceiveTimeout(1000);
            
            InputStream is= sPort.getInputStream();
            OutputStream os= sPort.getOutputStream();
            
            String str="11A41";
            int i =13; //char(13) is used for carriage return
            char extChar=(char) i;
            str=str + extChar;
            byte[] outByte=str.getBytes();
            
            os.write(outByte);
            
            sPort.close();
            
            
        } catch (Exception ex){ex.printStackTrace();}
    }
}

however the phone notices the connection and establishes it, but only for a second or 2... it doesn't get as far as sending the data.... Can anyone point me in a direction as to whats wrong and why?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.