Commit 0cc9c313 authored by Dan Gebhardt's avatar Dan Gebhardt

Dataq SDK for linux

parent ba9fa722
This diff is collapsed.
# author : Ioan S. Popescu
#
# Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
CC = g++
# unless you are using a version of gcc >=3.5, don't use optimization
CFLAGS = -Wall -c -O0 -o
#CFLAGS = -Wall -g -c -O0 -o
TEMP_OBJ_FILES = dsdk/dsdk.o \
di_serial_io/di_serial_io.o \
di194/di194.o \
di194/di194_commands.o \
di154/di154.o
OBJ_FILES = dataqsdk.o \
$(TEMP_OBJ_FILES)
DATAQSDK_DEPS = dataqsdk.h \
dataqsdk.cpp \
$(TEMP_OBJ_FILES)
INS_PATH = /usr/local/lib/
default : $(OBJ_FILES)
shared : $(OBJ_FILES)
g++ -shared -Wl,-soname,libdataqsdk.so.0 -o libdataqsdk.so.0.0 \
$(OBJ_FILES)
static : $(OBJ_FILES)
ar crsu libdataqsdk.a $(OBJ_FILES)
dataqsdk.o : $(DATAQSDK_DEPS)
$(CC) $(CFLAGS) dataqsdk.o dataqsdk.cpp
dsdk/dsdk.o : dsdk/dsdk.h dsdk/dsdk.cpp
$(CC) $(CFLAGS) dsdk/dsdk.o dsdk/dsdk.cpp
di_serial_io/di_serial_io.o : di_serial_io/di_serial_io.h di_serial_io/di_serial_io.cpp
$(CC) $(CFLAGS) di_serial_io/di_serial_io.o di_serial_io/di_serial_io.cpp
di194/di194.o : di194/di194.h di194/di194.cpp di194/di194_commands.o di_serial_io/di_serial_io.o
$(CC) $(CFLAGS) di194/di194.o di194/di194.cpp
di194/di194_commands.o : di194/di194_commands.h di194/di194_commands.cpp di_serial_io/di_serial_io.o
$(CC) $(CFLAGS) di194/di194_commands.o di194/di194_commands.cpp
di154/di154.o : di154/di154.h di154/di154.cpp di194/di194.o di194/di194_commands.o di_serial_io/di_serial_io.o
$(CC) $(CFLAGS) di154/di154.o di154/di154.cpp
clean :
rm -f dataqsdk.o libdataqsdk.*
clean-all :
rm -f libdataqsdk.*
rm -f $(OBJ_FILES)
install : libdataqsdk.so.0.0
mv -f libdataqsdk.so.0.0 $(INS_PATH)
chown root.root $(INS_PATH)libdataqsdk.so.0.0
chmod og-w $(INS_PATH)libdataqsdk.so.0.0
/sbin/ldconfig
ln -sf $(INS_PATH)libdataqsdk.so.0 $(INS_PATH)libdataqsdk.so
uninstall :
rm -f $(INS_PATH)libdataqsdk.*
/***************************************************************************
constants.h - Constants used for the entire
library. All constants go here.
-------------------
begin : Thu Jun 3 2004
author : Ioan S. Popescu
Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#ifndef MYCONSTANTS_H
#define MYCONSTANTS_H
#include <errno.h>
#include <sys/types.h>
#define DI194
/// Global error variable for the library.
extern int my_errno;
/// Integer to ASCII hex conversion table.
const u_int8_t asciihex[] = "0123456789ABCDEF";
/// ASCII hex to integer conversion table.
const u_int8_t inthex[128] =
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
2, 3, 4, 5, 6, 7, 8, 9, 0, 0,
0, 0, 0, 0, 0,10,11,12,13,14,
15,0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0,10,11,12,
13,14,15,0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0};
/// Max size for some string (just to have a max).
const int BIG_STR = 1024;
/// Max size for some small string.
const int SMALL_STR = 32;
/// Max path and filename length for a device file.
const int DEV_PATH = 64;
/**
* Max serial port buffer size in bytes, could be different if someone
* recompiled the kernel with a different size buffer.
*/
const int DI_SERIAL_BUFFER_SIZE = 4096;
/** @addtogroup SN_LENGTH
* Serial Number length, in characters.
* @{
*/
#ifdef DI194
const int DI194_SN_LENGTH = 10;
#endif
/** @} */
/// Key size, in characters.
#ifdef DI194
const int DI194_KEY_SIZE = 10;
#endif
/** @addtogroup CHANNELS
* Max channels per device.
* @{
*/
#ifdef DI194
const int DI194_CHANNELS = 5;
#endif
/** @} */
/** @addtogroup CHAN_SIZE
* Channel size (in bytes).
* @{
*/
#ifdef DI194
const int DI194_CHAN_SIZE = 2;
#endif
/** @} */
/** @addtogroup BURST_RATES
* Min/Max burst rates, throughput, min/max divisors.
* @{
*/
#ifdef DI194
const double DI194_MAXBURSTRATE = 240.00*4;
const double DI194_MINBURSTRATE = DI194_MAXBURSTRATE / 32767;
#endif
/** @} */
/** @addtogroup IOS_CODES
* IOS (Intelligent Over Sampling) Codes
* @{
*/
const u_int8_t IOS_SMALLEST = 0;
const u_int8_t IOS_AVERAGE = 0;
const u_int8_t IOS_MAX = 1;
const u_int8_t IOS_MIN = 2;
const u_int8_t IOS_RMS = 3;
const u_int8_t IOS_FREQ = 4;
const u_int8_t IOS_LAST_POINT = 5;
const u_int8_t IOS_GREATEST = 5;
/** @} */
/** @addtogroup ADDITIONAL_CODES
* Additional error codes defined here.
* @{
*/
const int EBOUNDS = 200; ///< Argument out of bounds.
const int EBADRSVP = 201; ///< Device isn't responding properly.
/** @} */
#endif
This diff is collapsed.
/***************************************************************************
dataqsdk.h - DataqSDK for Linux, include file.
-------------------
begin : Wed Jun 9 2004
author : Ioan S. Popescu
Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#ifndef DATAQSDK_H
#define DATAQSDK_H
class dsdk;
/// DataqSDK library interface class.
class dataqsdk
{
public:
dataqsdk(); ///< Simple initialization.
~dataqsdk(); ///< Deletes allocated memory.
/** @addtogroup GetProperties
* @{
*/
/// Number of channels being scanned.
const int ADChannelCount();
const long int ADCounter();
/// Number of data points in input buffer.
const long int AvailableData();
const long int BurstCounter();
/// Device file path and name used to connect to the device.
const char *const DeviceFile();
/// Number of data points required before NewData() fires.
const long int EventPoint();
/// The device's model number.
const int InfoBoardID();
/// The device's input measurement setting.
// true = PGH, false = PGL
const bool InfoPGL();
/// The device's firmware revision.
const int InfoRev();
/// The device's serial number.
const char *const InfoSerial();
/// Maximum sampling rate of combined channels.
// (# channels) * (SampleRate)
const double MaxBurstRate();
// used to determine the device: properties, abilities, etc.
// if called before it's been set, it will return a list of devices,
// that can be handled by the library, separated by the '\0' character;
// the last entry is followed by 2 '\0' characters
const char *const ProductName();
/// Actual sample rate.
const double SampleRate();
// predefined levels of limits around the TrigLevel to be passed
// before the trigger goes off
const int TrigHysteresisIdx();
// the trigger point (in counts) at which the trigger will go off
const int TrigLevel();
const int TrigMode();
// trigger channel (zero-based)
const int TrigScnChnIdx();
// 0 = trigger on the rising slope (negative)
// 1 = trigger on the falling slope (positive)
const int TrigSlope();
// number of scans to acquire after trigger occurs, and stop
const int TrigPostLength();
// number of scans to acquire before trigger occurs, and stop
const int TrigPreLength();
/** @} */
/** @addtogroup SetProperties
* @{
*/
/// Number of channels to scan.
void ADChannelCount(const int ChannelCount);
void ADCounter(const long int Counter);
void BurstCounter(const long int BurstCounter);
/// Device file path and name used to connect to the device.
void DeviceFile(const char *const DeviceFile);
/// Number of data points required before NewData() fires.
void EventPoint(const long int EventPnt);
/// Maximum sampling rate of combined channels.
// (# channels) * (SampleRate)
void MaxBurstRate(const double MaxBurstRt);
// used to determine the device: properties, abilities, etc.
void ProductName(const char *const ProductName);
/// Requested sample rate.
void SampleRate(const double SampleRt);
// predefined levels of limits around the TrigLevel to be passed
// before the trigger goes off
void TrigHysteresisIdx(const int Hidx);
// the trigger point (in counts) at which the trigger will go off
void TrigLevel(const int Level);
void TrigMode(const int Mode);
// trigger channel (zero-based)
void TrigScnChnIdx(const int SCidx);
// 0 = trigger on the rising slope (negative)
// 1 = trigger on the falling slope (positive)
void TrigSlope(const int Slope);
// number of scans to acquire after trigger occurs, and stop
void TrigPostLength(const int PostLength);
// number of scans to acquire before trigger occurs, and stop
void TrigPreLength(const int PreLength);
/** @} */
/** @addtogroup Methods
* @{
*/
/// Map software channels and physical channels.
void ADChannelList(const int *const ChannelList);
// array index corresponds to physical channel (zero-based)
void ADDiffList(const int *const DiffList);
// assigns the gain index to supporting devices
// array index corresponds to physical channel (zero-based)
void ADGainList(const int *const GainList);
/// Change the IOS setting for each channel.
void ADMethodList(const int *const MethodList);
// sends 'value' to a DAC 'port'
void DAOutput(const int value, const int port);
// attempts to detect any currently connected devices and returns a
// pointer to a string of ProductIDs separated by the '\0' character
// with the last entry followed by 2 '\0' characters.
// will not detect devices that aren't automatically detected by the
// kernel (USB devices are most likely to be detected)
const char *const DetectedDevices();
const long int DigitalInput();
// sends 'value' to all digital ports
// which port depends on the bit position in value
// what value (0, 1) depends on the corresponding bit in 'value'
void DigitalOutput(const int value);
void GetData();
/// Get acquired data from device.
void GetDataEx(short int *iArray, const int Count);
void GetDataFrame();
void GetDataFrameEx(short int *iArray, const int Count);
/// Start acquisition.
void Start();
/// Stop acquisition.
void Stop();
/** @} */
/** @addtogroup EventOccurMethods
* Return true when the event occurs and update their arguments
* with the proper value.
* @{
*/
/// Determines the last library error.
const bool ControlError(long int &Code);
/// Determines whether new data is available according to the event point.
const bool NewData(long int &Count);
/// Determines whether the input buffer OR the device buffer overflowed.
const bool OverRun();
/** @} */
private:
/// Do not allow copying of this class.
dataqsdk(const dataqsdk &copy);
char *m_ProductName; ///< Identifies current device.
int m_last_error; ///< Interface class internal error variable.
dsdk *m_classID; ///< Pointer to appropriate device handling code.
};
#endif
/***************************************************************************
di154.cpp - Linux driver for DI-154 series
acquisition device manufactured by
DATAQ Instruments, Inc.
-------------------
begin : Mon Aug 2 2004
author : Ioan S. Popescu
Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#include "di154.h"
/**
* - Sets up the channel order array (1 channel)
* - Sets channel count to use 1 analog channel
* - Sets up 'connection' to use the DI-154RS settings
* - Creates the following lists:
* - m_ADChannelList\n
* Normal order
* - m_ADMethodList\n
* IOS Average
* - Disables the digital channel
* - Calls sample rate function passing it the default sample rate,
* as defined in the dsdk
*/
di154_dsdk::di154_dsdk()
{
chan_order[0] = 0;
m_ADChannelCount = 1;
// create new lists
m_ADChannelList = new int[m_ADChannelCount];
m_ADMethodList = new int[m_ADChannelCount];
for(int i=0; i<m_ADChannelCount; i++)
{
m_ADChannelList[i] = i;
m_ADMethodList[i] = IOS_AVERAGE;
chan_order[i] = i * DI194_CHAN_SIZE;
}
digital_chan = false;
m_MaxBurstRate = 240.00;
// set to default sample rate based on channels activated
SampleRate(m_SampleRate);
}
/**
* Converts 'di_data' into Counts.
*
* @param di_data Pointer to array of raw data.
* @param num_chan Channel list position to check for analog or digital.
*/
const short int di154_dsdk::convert(const u_int8_t *const di_data,
const u_int8_t num_chan)
{
short int temp = 0;
// extract and convert to counts
// find out whether it's an analog or digital channel
if(m_ADChannelList[num_chan] != -1) // analog channel
{
temp = static_cast<short int>(di_data[chan_order[m_ADChannelList[num_chan]]]
& 0xF7) >> 3;
temp |= (static_cast<short int>(di_data[chan_order[m_ADChannelList[num_chan]]+1]
& 0xFE) << 4);
temp <<= 4; // left justify the number
temp ^= 0x8000;
}
else // digital bits
temp = (di_data[0] & 0x06) >> 1;
return temp;
}
/***************************************************************************
di154.h - Linux driver for DI-154 series
acquisition device manufactured by
DATAQ Instruments, Inc.
-------------------
begin : Mon Aug 2 2004
author : Ioan S. Popescu
Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
***************************************************************************/
#ifndef DI154_H
#define DI154_H 1
#include "../di194/di194.h"
/// Main device class for the DI-154RS.
class di154_dsdk : public di194_dsdk
{
public:
di154_dsdk(); ///< Sets up device defaults for DI-154RS.
private:
/// Do not allow copying of this class.
/**
* @param copy Class to copy.
*/
di154_dsdk(const di154_dsdk &copy){};
/// Converts 'di_data' into counts.
const short int convert(const u_int8_t *const di_data,
const u_int8_t num_chan);
};
#endif
This diff is collapsed.
/***************************************************************************
di194.h - Linux driver for DI-194 series
acquisition device manufactured by
DATAQ Instruments, Inc.
-------------------
begin : Mon Jun 7 2004
author : Ioan S. Popescu
Copyright (C) 2004 DATAQ Instruments, Inc. <develop@dataq.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.