# XBEE_GETPACKET

Section: Linux Programmer's Manual (3)
Updated: 2009-11-01
Index Return to Main Contents

## NAME

xbee_hasanalog, xbee_getanalog

## SYNOPSIS

#include <xbee.h>

int xbee_hasanalog(xbee_pkt *pkt,int sample, int input);

double xbee_getanalog(xbee_pkt *pkt,int sample, int input, double Vref);

## DESCRIPTION

The xbee_hasanalog() function will check the packet for the presence of an analog sample on the specified input.

The xbee_getanalog() function will read the packet and return the sample value for the specified analog input.

They both take 3 arguments, with the same purposes.

The argument pkt points to a packet that was previously retrieved with xbee_getpacket()

The argument sample selects the sample within the packet to use.

The argument input specifies which input you are interested in testing.

xbee_getanalog() also takes a fourth argument that allows you to provide a Vref value. This allows the function to convert the raw ADC value into a voltage for you.

## RETURN VALUE

The xbee_hasanalog() function will return 1 if the provided packet has sample data for the specified input, otherwise 0.

The xbee_getanalog() function will return the raw ADC value (0 - 1023) if the provided packet has sample data for the specified input and Vref was given as zero. If Vref was non-zero, then the return value will be the voltage read. A -1 will be returned if the packet does not contain sample data.

## EXAMPLE

To read sample data from previously made connection:

    #include <xbee.h>
    xbee_pkt *pkt;
    double Vref = 3.3;
    if ((pkt = xbee_getpacket(con)) != NULL) {
      if (xbee_hasanalog(pkt,0,0)) {
        printf("A0 read %fv,xbee_getanalog(pkt,0,0,Vref));
      } else {
        printf("No A0 data);
      }
      free(pkt);
    }

## AUTHOR

Attie Grande <attie@attie.co.uk>

## SEE ALSO

libxbee(3), xbee_pkt(3), xbee_getpacket(3), xbee_hasdigital(3), xbee_getdigital(3)

## Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
AUTHOR
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 00:08:23 GMT, March 30, 2011