private void initEventListenersAndIO() {
    try {
      input = serialPort.getInputStream();
      output = serialPort.getOutputStream();
      serialPort.addEventListener(new SerialRxEvent(input, deviceRx));
      serialPort.notifyOnDataAvailable(true);

    } catch (TooManyListenersException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
 /**
  * Send a simple invite request from the RI and check whether it is properly delivered by the TI
  * SipProvider
  */
 public void testReceiveRequest() {
   try {
     // create an empty invite request.
     Request invite = createRiInviteRequest(null, null, null);
     RequestEvent receivedRequestEvent = null;
     try {
       // Send using RI and collect using TI
       eventCollector.collectRequestEvent(tiSipProvider);
       riSipProvider.sendRequest(invite);
       waitForMessage();
       receivedRequestEvent = eventCollector.extractCollectedRequestEvent();
       assertNotNull("The sent request was not received at the other end!", receivedRequestEvent);
       assertNotNull(
           "The sent request was not received at the other end!",
           receivedRequestEvent.getRequest());
     } catch (TooManyListenersException ex) {
       // This time adding the listener is (sort of) part of the test
       // so we fail instead of just "throwing on" the exc
       ex.printStackTrace();
       fail(
           "A TooManyListenersException was thrown while trying to add "
               + "a SipListener to a TI SipProvider.");
     } catch (SipException ex) {
       throw new TckInternalError("The RI failed to send the request!", ex);
     }
     // question: should we compare sent and received request?
     // my opinion: finding a discrepancy while comparing requests
     // would most probably mean a parse error and parsing is not what
     // we are currently testing
     // Transaction initiating requests should not have a server transaction
     // associated with them as the application might decide to handle the
     // request statelessly
     assertNull(
         "The Tested Implementation has implicitly created a ServerTransaction "
             + "for the received request. Transactions should only be created "
             + "explicitly using the SipProvider.getNewXxxTransaction() method.",
         receivedRequestEvent.getServerTransaction());
   } catch (Throwable exc) {
     exc.printStackTrace();
     fail(exc.getClass().getName() + ": " + exc.getMessage());
   }
   assertTrue(new Exception().getStackTrace()[0].toString(), true);
 }
Example #3
0
  // open a serial connection to a device.  We won't know it's the robot until
  public int OpenPort(String portName) {
    if (portOpened && portName.equals(recentPort)) return 0;

    ClosePort();

    Log("<font color='green'>Connecting to " + portName + "...</font>\n");

    // find the port
    try {
      portIdentifier = CommPortIdentifier.getPortIdentifier(portName);
    } catch (Exception e) {
      Log("<span style='color:red'>Ports could not be identified:" + e.getMessage() + "</span>\n");
      e.printStackTrace();
      return 1;
    }

    if (portIdentifier.isCurrentlyOwned()) {
      Log(
          "<span style='color:red'>Error: Another program is currently using this port."
              + "</span>\n");
      return 2;
    }

    // open the port
    try {
      commPort = portIdentifier.open("DrawbotGUI", 2000);
    } catch (Exception e) {
      Log("Port could not be opened:" + e.getMessage() + NL);
      e.printStackTrace();
      return 3;
    }

    if ((commPort instanceof SerialPort) == false) {
      Log("<span style='color:red'>Only serial ports are handled by this example." + "</span>\n");
      return 4;
    }

    // set the port parameters (like baud rate)
    serialPort = (SerialPort) commPort;
    try {
      serialPort.setSerialPortParams(
          BAUD_RATE, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);
    } catch (Exception e) {
      Log("<span style='color:red'>Port could not be configured:" + e.getMessage() + "</span>\n");
      return 5;
    }

    try {
      in = serialPort.getInputStream();
      out = serialPort.getOutputStream();
    } catch (Exception e) {
      Log("<span style='color:red'>Streams could not be opened:" + e.getMessage() + "</span>\n");
      return 6;
    }

    try {
      serialPort.addEventListener(this);
      serialPort.notifyOnDataAvailable(true);
    } catch (TooManyListenersException e) {
      Log("<span style='color:red'>Streams could not be opened:" + e.getMessage() + "</span>\n");
      return 7;
    }

    Log("<span style='green'>Opened.</span>\n");
    SetRecentPort(portName);
    portOpened = true;
    UpdateMenuBar();

    return 0;
  }