Ejemplo n.º 1
0
  public HittPolling(String comport, int baudrate) {
    _baudrate = baudrate;
    try {
      CommPortIdentifier com = CommPortIdentifier.getPortIdentifier(comport);
      _comPortIdent = com;

      _usable = true;
    } catch (NoSuchPortException e) {
      _usable = false;
      PLog.error("There is no COM-Port called: " + comport, e);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void startPolling() {
    if (!_usable || !_isQuestionSupported) {
      return;
    }

    _votingStartTime = Calendar.getInstance().getTimeInMillis();
    try {
      _comPort = _comPortIdent.open(this.getClass().getName(), 2000);

      if (_comPort instanceof SerialPort) {
        _serialPort = (SerialPort) _comPort;
        _serialPort.setSerialPortParams(
            _baudrate, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE);

        InputStream in = _serialPort.getInputStream();

        _serialReader = new SerialReader(in, _injectable, _votingStartTime);

        _serialPort.addEventListener(_serialReader);
        _serialPort.notifyOnDataAvailable(true);
      }
    } catch (PortInUseException e) {
      reportToDelegate(e);
      PLog.error("Port is alreay in use by " + e.currentOwner, e);
    } catch (UnsupportedCommOperationException e) {
      reportToDelegate(e);
      PLog.error("Error on setting SerialPort params", e);
    } catch (IOException e) {
      reportToDelegate(e);
      PLog.error("Error while getting Inputstream", e);
    } catch (TooManyListenersException e) {
      reportToDelegate(e);
      PLog.error("Error trying to add new EventListener", e);
    }
  }