/** * Get an instance of an Analog Module. * * Singleton analog module creation where a module is allocated on the first use * and the same module is returned on subsequent uses. * * @param slot The physical slot in the cRIO chassis where this analog module is installed. * @return A pointer to the AnalogModule. */ AnalogModule* AnalogModule::GetInstance(UINT32 slot) { CheckAnalogModule(slot); if (m_modules[slot] == NULL) { m_modules[slot] = new AnalogModule(slot); } return (AnalogModule*)m_modules[slot]; }
/** * Get an instance of an Analog Module. * * Singleton analog module creation where a module is allocated on the first use * and the same module is returned on subsequent uses. * * @param moduleNumber The analog module to get (1 or 2). * @return A pointer to the AnalogModule. */ AnalogModule* AnalogModule::GetInstance(UINT8 moduleNumber) { if (CheckAnalogModule(moduleNumber)) { return (AnalogModule*)GetModule(nLoadOut::kModuleType_Analog, moduleNumber); } // If this wasn't caught before now, make sure we say what's wrong before we crash char buf[64]; snprintf(buf, 64, "Analog Module %d", moduleNumber); wpi_setGlobalWPIErrorWithContext(ModuleIndexOutOfRange, buf); return NULL; }
/** * Common initialization. */ void AnalogChannel::InitChannel(UINT32 slot, UINT32 channel) { Resource::CreateResourceObject(&channels, kAnalogModules * kAnalogChannels); CheckAnalogModule(slot); CheckAnalogChannel(slot); channels->Allocate(AnalogModule::SlotToIndex(slot) * kAnalogModules + channel - 1); m_channel = channel; m_module = AnalogModule::GetInstance(slot); if (IsAccumulatorChannel()) { m_accumulator = new tAccumulator(channel - 1, &status); m_accumulatorOffset=0; } else { m_accumulator = NULL; } }
/** * Common initialization. */ void AnalogChannel::InitChannel(UINT8 moduleNumber, UINT32 channel) { char buf[64]; Resource::CreateResourceObject(&channels, kAnalogModules * kAnalogChannels); if (!CheckAnalogModule(moduleNumber)) { snprintf(buf, 64, "Analog Module %d", moduleNumber); wpi_setWPIErrorWithContext(ModuleIndexOutOfRange, buf); return; } if (!CheckAnalogChannel(channel)) { snprintf(buf, 64, "Analog Channel %d", channel); wpi_setWPIErrorWithContext(ChannelIndexOutOfRange, buf); return; } snprintf(buf, 64, "Analog Input %d (Module: %d)", channel, moduleNumber); if (channels->Allocate((moduleNumber - 1) * kAnalogChannels + channel - 1, buf) == ~0ul) { CloneError(channels); return; } m_channel = channel; m_module = AnalogModule::GetInstance(moduleNumber); if (IsAccumulatorChannel()) { tRioStatusCode localStatus = NiFpga_Status_Success; m_accumulator = tAccumulator::create(channel - 1, &localStatus); wpi_setError(localStatus); m_accumulatorOffset=0; } else { m_accumulator = NULL; } LiveWindow::GetInstance()->AddActuator("AnalogChannel",channel, GetModuleNumber(), this); nUsageReporting::report(nUsageReporting::kResourceType_AnalogChannel, channel, GetModuleNumber() - 1); }