コード例 #1
0
bool NIDAQDevice::initialize() {
    if (!(haveAnalogInputChannels() ||
          haveAnalogOutputChannels() ||
          haveDigitalInputChannels() ||
          haveDigitalOutputChannels() ||
          haveCounterInputCountEdgesChannels()))
    {
        throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN, "NIDAQ device must have at least one channel");
    }
    
    if (haveAnalogOutputVoltageChannels() && haveAnalogOutputVoltageWaveformChannels()) {
        throw SimpleException(M_IODEVICE_MESSAGE_DOMAIN,
                              "NIDAQ device cannot use static and waveform analog output voltage channels simultaneously");
    }
    
    analogInputSampleBufferSize = analogInputChannels.size() * std::size_t(updateInterval / analogInputDataInterval);
    analogOutputSampleBufferSize = analogOutputVoltageChannels.size();
    digitalInputSampleBufferSize = digitalInputChannels.size();
    digitalOutputSampleBufferSize = (digitalOutputChannels.empty() ? 0 : 1);
    
    sharedMemory.setSize(HelperControlMessage::sizeWithSamples(std::max(analogInputSampleBufferSize,
                                                                        analogOutputSampleBufferSize),
                                                               std::max(digitalInputSampleBufferSize,
                                                                        digitalOutputSampleBufferSize)));
    controlMessage = sharedMemory.getMessagePtr();
    
    spawnHelper();
    
    mprintf(M_IODEVICE_MESSAGE_DOMAIN, "Configuring NIDAQ device \"%s\"...", deviceName.c_str());
    
    if (haveAnalogInputChannels() && !createAnalogInputTask()) {
        return false;
    }
    if (haveAnalogOutputChannels() && !createAnalogOutputTask()) {
        return false;
    }
    if (haveDigitalInputChannels() && !createDigitalInputTask()) {
        return false;
    }
    if (haveDigitalOutputChannels() && !createDigitalOutputTasks()) {
        return false;
    }
    if (haveCounterInputCountEdgesChannels() && !createCounterInputCountEdgesTasks()) {
        return false;
    }
    
    mprintf(M_IODEVICE_MESSAGE_DOMAIN, "NIDAQ device \"%s\" is ready", deviceName.c_str());
    
    if (haveAnalogOutputChannels()) {
        auto sharedThis = component_shared_from_this<NIDAQDevice>();
        auto notification = boost::make_shared<AnalogOutputEnabledNotification>(sharedThis);
        analogOutputEnabled->addNotification(notification);
    }
    
    return true;
}
コード例 #2
0
bool NIDAQDevice::createTasks() {
    if (haveAnalogInputChannels() && !createAnalogInputTask()) {
        return false;
    }
    if (haveAnalogOutputChannels() && !createAnalogOutputTask()) {
        return false;
    }
    if (haveDigitalInputChannels() && !createDigitalInputTask()) {
        return false;
    }
    if (haveDigitalOutputChannels() && !createDigitalOutputTasks()) {
        return false;
    }
    if (haveCounterInputCountEdgesChannels() && !createCounterInputCountEdgesTasks()) {
        return false;
    }
    
    return true;
}