0

I'm trying to read/write some data from a COM port. The program sets up the serial port parameter values as follows:

serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE).

However, the program gets stuck at the above line of code. Before that line it executes sucessfully.

The full code is below:

public SendMsg(String className) throws NoSuchPortException, IOException, TooManyListenersException, UnsupportedCommOperationException
{
    this.className=className;
    //portList =  CommPortIdentifier.getPortIdentifiers();
    ports = CommPortIdentifier.getPortIdentifiers();
    System.out.println("ports name"+ports);
    while(ports.hasMoreElements())
    {
        pID = (CommPortIdentifier)ports.nextElement();
        System.out.println("Port Name " + pID.getName());

        if (pID.getPortType() == CommPortIdentifier.PORT_SERIAL)
        {
            System.out.println("Port Name 1 " + pID.getName());
            if (pID.getName().equals("COM1"))
            {
                try {
                    System.out.println("Port Name 2 " + pID.getName());
                    System.out.println("COM1 found");
                    serialPort=(SerialPort)pID.open(className, 1000);

                     outputStream=serialPort.getOutputStream();
                     inputStream=serialPort.getInputStream();
                     //f.serialEvent1(inputStream);
                     serialPort.setSerialPortParams(9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
                     System.out.println("hai");

                     serialPort.addEventListener(this);

                     break;
                } catch (PortInUseException ex) {
                    Logger.getLogger(SendMsg.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    }
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
Naresh
  • 51
  • 1
  • 6
  • It sounds like the code just stops at that point? Can you run it in the debugger and then interrupt it and get a stack trace where it stops? That will tell you more information. – Francis Upton IV Dec 27 '11 at 10:25
  • It is not getting stopped and remain struck ed in the below line : serialPort.setSerialPortParams(9600,SerialPort.DATABITS_8,SerialPort.STOPBITS_1,SerialPort.PARITY_NONE); – Naresh Dec 27 '11 at 10:28
  • See if the [this answer helps.][1] [1]: http://stackoverflow.com/questions/2745214/arduino-not-able-to-send-serial-data-back – Francis Upton IV Dec 27 '11 at 10:33

0 Answers0