serial Port programming

Reply

Join Date: Dec 2004
Posts: 489
Reputation: Acidburn is an unknown quantity at this point 
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

serial Port programming

 
0
  #1
Oct 5th, 2007
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:

  1. package btserver1;
  2.  
  3. import gnu.io.CommDriver;
  4. import gnu.io.CommPort;
  5. import gnu.io.CommPortIdentifier;
  6. import gnu.io.SerialPort;
  7. import java.io.*;
  8.  
  9. public class Main {
  10. static String dataFile =null;
  11. /** Creates a new instance of Main */
  12. public Main() {
  13. }
  14.  
  15. /**
  16.   * @param args the command line arguments
  17.   */
  18. public static void main(String[] args) {
  19. try {
  20. CommPortIdentifier pid=CommPortIdentifier.getPortIdentifier("COM4");
  21. SerialPort sPort=(SerialPort) pid.open("Serial Comm Testing",100);
  22.  
  23. sPort.disableReceiveFraming();
  24. sPort.disableReceiveThreshold();
  25.  
  26. sPort.setSerialPortParams(115200 , SerialPort.DATABITS_8, SerialPort.STOPBITS_1,SerialPort.PARITY_NONE);
  27.  
  28. sPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
  29.  
  30. //sPort.enableReceiveTimeout(1000);
  31.  
  32. InputStream is= sPort.getInputStream();
  33. OutputStream os= sPort.getOutputStream();
  34.  
  35. String str="11A41";
  36. int i =13; //char(13) is used for carriage return
  37. char extChar=(char) i;
  38. str=str + extChar;
  39. byte[] outByte=str.getBytes();
  40.  
  41. os.write(outByte);
  42.  
  43. sPort.close();
  44.  
  45.  
  46. } catch (Exception ex){ex.printStackTrace();}
  47. }
  48. }

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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC