Ejemplo n.º 1
0
/**
 * 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;
	}
}
Ejemplo n.º 2
0
/**
 * Get a sample from the output of the oversample and average engine for the channel.
 * 
 * The sample is 12-bit + the value configured in SetOversampleBits().
 * The value configured in SetAverageBits() will cause this value to be averaged 2**bits number of samples.
 * This is not a sliding window.  The sample will not change until 2**(OversamplBits + AverageBits) samples
 * have been acquired from the module on this channel.
 * Use GetAverageVoltage() to get the analog value in calibrated units.
 * 
 * @param channel Channel number to read.
 * @return A sample from the oversample and average engine for the channel.
 */
INT32 AnalogModule::GetAverageValue(UINT32 channel)
{
	INT32 value;
	CheckAnalogChannel(channel);

	tAI::tReadSelect readSelect;
	readSelect.Channel = channel - 1;
	readSelect.Module = SlotToIndex(m_slot);
	readSelect.Averaged = true;

	{
		Synchronized sync(m_registerWindowSemaphore);
		m_module->writeReadSelect(readSelect, &status);
		m_module->strobeLatchOutput(&status);
		value = m_module->readOutput(&status);
	}

	wpi_assertCleanStatus(status);
	return value;
}
Ejemplo n.º 3
0
/**
 * Get a sample from the output of the oversample and average engine for the channel.
 * 
 * The sample is 12-bit + the value configured in SetOversampleBits().
 * The value configured in SetAverageBits() will cause this value to be averaged 2**bits number of samples.
 * This is not a sliding window.  The sample will not change until 2**(OversamplBits + AverageBits) samples
 * have been acquired from the module on this channel.
 * Use GetAverageVoltage() to get the analog value in calibrated units.
 * 
 * @param channel Channel number to read.
 * @return A sample from the oversample and average engine for the channel.
 */
INT32 AnalogModule::GetAverageValue(UINT32 channel)
{
	INT32 value;
	CheckAnalogChannel(channel);

	tAI::tReadSelect readSelect;
	readSelect.Channel = channel - 1;
	readSelect.Module = m_moduleNumber - 1;
	readSelect.Averaged = true;
	tRioStatusCode localStatus = NiFpga_Status_Success;

	{
		Synchronized sync(m_registerWindowSemaphore);
		m_module->writeReadSelect(readSelect, &localStatus);
		m_module->strobeLatchOutput(&localStatus);
		value = m_module->readOutput(&localStatus);
	}

	wpi_setError(localStatus);
	return value;
}
Ejemplo n.º 4
0
/**
 * 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);
}