944,120 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 10105
  • Java RSS
Oct 5th, 2007
0

serial Port programming

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  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?
Similar Threads
Reputation Points: 12
Solved Threads: 5
Posting Pro
Acidburn is offline Offline
510 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: JSP vs PHP
Next Thread in Java Forum Timeline: remove the path when printing





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC