/** * Reads an accelerometer value from a single register. Reading from * the accelerometer is common for all directions. * * @param[in] reg The register address to read from * @param[in] scale_weight The weight for the accelerometer values * @return the acceleration value in g's */ double Accel_ReadImpl(uint32_t reg, double scale_weight) { NiFpga_Status status; uint16_t value; double scaledValue; /* * Get the value of the acceleration value register. * * The returned NiFpga_Status value is stored for error checking. */ status = NiFpga_ReadU16(myrio_session, reg, &value); /* * Check if there was an error reading from the read register. * * If there was an error then the rest of the function cannot complete * correctly so print an error message to stdout and return from the * function early. */ MyRio_ReturnValueIfNotSuccess(status, 0.0, "Could not read from the accelerometer value register!") /* * The value is always stored in an unsigned 16-bit register, but the value * is actually a signed 16-bit value. Cast this value directly to a signed * 16-bit value. */ scaledValue = ((int16_t) value) * scale_weight; return scaledValue; }
uint16_t FPGA_GetRCCH3() { uint16_t retval; NiFpga_MergeStatus(&FPGA_Status,NiFpga_ReadU16(FPGA_Session,NiFpga_mainFPGA_IndicatorU16_C3Mode,&retval)); if (NiFpga_IsError(FPGA_Status)) { LOG.ERR("Get RC CH3 Read Failed."); } return retval; }
/** * Reads a voltage value to from single channel. The channel structure must * previously been initialized with the appropriate scale factors with * AnalogScaling. * * @param[in] channel A struct containing the registers for the AIO * channel to be read from * @return the voltage value in volts */ double Aio_Read(MyRio_Aio* channel) { NiFpga_Status status; uint16_t value = 0; double scaledValue; /* * Get the value of the value register. * * The returned NiFpga_Status value is stored for error checking. */ status = NiFpga_ReadU16(myrio_session, channel->val, &value); /* * Check if there was an error reading from the read register. * * If there was an error then the rest of the function cannot complete * correctly so print an error message to stdout and return from the * function early. Return 0.0 as the read input value. */ MyRio_ReturnValueIfNotSuccess(status, 0.0, "Could not read from the AI value registers!"); /* * The value is always stored in an unsigned 16-bit register. For a signed * channel, cast this value directly to a signed 16-bit value. */ if (channel->is_signed) { scaledValue = (int16_t)value * channel->scale_weight + channel->scale_offset; } else { scaledValue = value * channel->scale_weight + channel->scale_offset; } return scaledValue; }
bool nifpga::ReadU16(uint32_t indicator, uint16_t* value) { if (sessionOpen) return HandleStatus(NiFpga_ReadU16(sessionHandle, indicator, value)); return false; }