DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   serial Port programming (http://www.daniweb.com/forums/thread91807.html)

Acidburn Oct 5th, 2007 8:15 am
serial Port programming
 
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?


All times are GMT -4. The time now is 9:08 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC