void Sender::send( const QByteArray &data ) throw( PortError ) { if ( !m_serialPort.isOpen() ) { throw PortError( "Error: unable to send to the port \"" + m_serialPort.portName().toStdString() + "\"" " because it is not opened"); } // Write data to the port if ( m_serialPort.write( data ) == -1 ) { throw PortError( "Error: unable to send to the port \"" + m_serialPort.portName().toStdString() + "\"" ); } }
void DigitalPort::setMode(uint8_t mode, ChangeSource changeSource) { if (mode > 3) throw PortError(this->ID() + ": Digital port mode not supported: " + this->to_string((int)mode)); int8_t newMode = -1; // validate mode if (!strcmp(this->caps, OPDI_PORTDIRCAP_INPUT) || !strcmp(this->caps, OPDI_PORTDIRCAP_BIDI)) { switch (mode) { case 0: // Input // if "Input" is requested, map it to the allowed pullup/pulldown input mode if specified if ((flags & OPDI_DIGITAL_PORT_PULLUP_ALWAYS) == OPDI_DIGITAL_PORT_PULLUP_ALWAYS) newMode = 1; else if ((flags & OPDI_DIGITAL_PORT_PULLDN_ALWAYS) == OPDI_DIGITAL_PORT_PULLDN_ALWAYS) newMode = 2; else newMode = 0; break; case 1: if ((flags & OPDI_DIGITAL_PORT_PULLUP_ALWAYS) != OPDI_DIGITAL_PORT_PULLUP_ALWAYS) throw PortError(this->ID() + ": Digital port mode not supported; use mode 'Input with pullup': " + this->to_string((int)mode)); newMode = 1; break; case 2: if ((flags & OPDI_DIGITAL_PORT_PULLDN_ALWAYS) != OPDI_DIGITAL_PORT_PULLDN_ALWAYS) throw PortError(this->ID() + ": Digital port mode not supported; use mode 'Input with pulldown': " + this->to_string((int)mode)); newMode = 2; break; case 3: if (!strcmp(this->caps, OPDI_PORTDIRCAP_INPUT)) throw PortError(this->ID() + ": Cannot set input only digital port mode to 'Output'"); newMode = 3; } } else { // direction is output only if (mode < 3) throw PortError(this->ID() + ": Cannot set output only digital port mode to input"); newMode = 3; } if (newMode > -1) { if (newMode != this->mode) { this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->mode = newMode; this->logDebug("DigitalPort Mode changed to: " + this->to_string((int)this->mode) + " by: " + this->getChangeSourceText(changeSource)); } if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); } }
void AnalogPort::setReference(uint8_t reference, ChangeSource changeSource) { if (reference > 2) throw PortError(this->ID() + ": Analog port reference not supported: " + this->to_string((int)reference)); if (reference != this->reference) { this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->reference = reference; this->logDebug("AnalogPort Reference changed to: " + this->to_string((int)this->reference) + " by: " + this->getChangeSourceText(changeSource)); } if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); }
void DialPort::setPosition(int64_t position, ChangeSource changeSource) { if (position < this->minValue) throw PortError(this->ID() + ": Position must not be less than the minimum: " + to_string(this->minValue)); if (position > this->maxValue) throw PortError(this->ID() + ": Position must not be greater than the maximum: " + to_string(this->maxValue)); // correct position to next possible step int64_t newPosition = ((position - this->minValue) / this->step) * this->step + this->minValue; if (this->error != Error::VALUE_OK) this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO); bool changed = (newPosition != this->position); if (changed) { this->refreshRequired |= (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->position = position; this->logDebug("DialPort Position changed to: " + this->to_string(this->position) + " by: " + this->getChangeSourceText(changeSource)); } this->error = Error::VALUE_OK; if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); if (changed) this->handleStateChange(changeSource); }
void AnalogPort::setResolution(uint8_t resolution, ChangeSource changeSource) { if (resolution < 8 || resolution > 12) throw PortError(this->ID() + ": Analog port resolution not supported; allowed values are 8..12 (bits): " + this->to_string((int)resolution)); // check whether the resolution is supported if (((resolution == 8) && ((this->flags & OPDI_ANALOG_PORT_RESOLUTION_8) != OPDI_ANALOG_PORT_RESOLUTION_8)) || ((resolution == 9) && ((this->flags & OPDI_ANALOG_PORT_RESOLUTION_9) != OPDI_ANALOG_PORT_RESOLUTION_9)) || ((resolution == 10) && ((this->flags & OPDI_ANALOG_PORT_RESOLUTION_10) != OPDI_ANALOG_PORT_RESOLUTION_10)) || ((resolution == 11) && ((this->flags & OPDI_ANALOG_PORT_RESOLUTION_11) != OPDI_ANALOG_PORT_RESOLUTION_11)) || ((resolution == 12) && ((this->flags & OPDI_ANALOG_PORT_RESOLUTION_12) != OPDI_ANALOG_PORT_RESOLUTION_12))) throw PortError(this->ID() + ": Analog port resolution not supported (port flags): " + this->to_string((int)resolution)); if (resolution != this->resolution) { this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->resolution = resolution; this->logDebug("AnalogPort Resolution changed to: " + this->to_string((int)this->resolution) + " by: " + this->getChangeSourceText(changeSource)); } if (this->mode != 0) this->setValue(this->value); else if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); }
void Sender::open() throw( PortError ) { m_serialPort.setPortName( m_portName ); // Open the port if ( !m_serialPort.open( QIODevice::WriteOnly ) ) { throw PortError( "Error: unable to open the port \"" + m_serialPort.portName().toStdString() + "\"" ); } m_serialPort.setBaudRate( m_baudRate ); m_serialPort.setDataBits( m_dataBits ); m_serialPort.setParity( m_parity ); m_serialPort.setStopBits( m_stopBits ); m_serialPort.setFlowControl( m_flowControl ); }
void SelectPort::setPosition(uint16_t position, ChangeSource changeSource) { if (position > count) throw PortError(this->ID() + ": Position must not exceed the number of items: " + to_string((int)this->count)); if (this->error != Error::VALUE_OK) this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO); bool changed = (position != this->position); if (changed) { this->refreshRequired |= (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->position = position; this->logDebug("SelectPort Position changed to: " + this->to_string(this->position) + " by: " + this->getChangeSourceText(changeSource)); } this->error = Error::VALUE_OK; if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); if (changed) this->handleStateChange(changeSource); }
void DigitalPort::setLine(uint8_t line, ChangeSource changeSource) { if (line > 1) throw PortError(this->ID() + ": Digital port line not supported: " + this->to_string((int)line)); if (this->error != Error::VALUE_OK) this->refreshRequired = (this->refreshMode == RefreshMode::REFRESH_AUTO); bool changed = (line != this->line); if (changed) { this->refreshRequired |= (this->refreshMode == RefreshMode::REFRESH_AUTO) && (changeSource != ChangeSource::CHANGESOURCE_USER); this->line = line; this->logDebug("DigitalPort Line changed to: " + this->to_string((int)this->line) + " by: " + this->getChangeSourceText(changeSource)); } this->error = Error::VALUE_OK; if (persistent && (this->opdi != nullptr)) this->opdi->persist(this); if (changed) this->handleStateChange(changeSource); }
void ExecPort::setMode(uint8_t /*mode*/, ChangeSource /*changeSource*/) { throw PortError(this->ID() + ": The mode of an ExecPort cannot be changed"); }
void ExecPort::setDirCaps(const char* /*dirCaps*/) { throw PortError(this->ID() + ": The direction capabilities of an ExecPort cannot be changed"); }