Ver 1.1.0 commit

This commit is contained in:
Saeid Bazazzadeh 2018-12-03 13:40:46 -05:00
parent 7568a411ed
commit 45ef9b9ff9
172 changed files with 9929 additions and 510 deletions

View File

@ -34,6 +34,13 @@ Building the **uldaq** package requires C/C++ compilers, make tool, and the deve
$ sudo zypper install gcc gcc-c++ make
$ sudo zypper install libusb-devel
```
- MacOS (Version 10.11 or later recommended)
```
$ xcode-select --install
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew install libusb
```
### Build Instructions
---------------------
@ -42,18 +49,21 @@ Building the **uldaq** package requires C/C++ compilers, make tool, and the deve
```
Linux
    $ wget https://github.com/mccdaq/uldaq/releases/download/v1.0.0/libuldaq-1.0.0.tar.bz2
    $ wget https://github.com/mccdaq/uldaq/releases/download/v1.1.0/libuldaq-1.1.0.tar.bz2
MacOS
    $ curl -L -O https://github.com/mccdaq/uldaq/releases/download/v1.1.0/libuldaq-1.1.0.tar.bz2
```
2. Extract the tar file:
```
 $ tar -xvjf libuldaq-1.0.0.tar.bz2
 $ tar -xvjf libuldaq-1.1.0.tar.bz2
```
3. Run the following commands to build and install the library:
```
 $ cd libuldaq-1.0.0
 $ cd libuldaq-1.1.0
 $ ./configure && make
$ sudo make install
```
@ -120,7 +130,7 @@ int main(void)
}
```
### Support/Feedback
The **uldaq** package is supported by MCC. For support for uldaq, contact technical through [support page](https://www.mccdaq.com/support/support_form.aspx). Please include detailed steps on how to reproduce the problem in your request.
The **uldaq** package is supported by MCC. For support for uldaq, contact technical support through [support page](https://www.mccdaq.com/support/support_form.aspx). Please include detailed steps on how to reproduce the problem in your request.
### Documentation
Online help for the Universal Library for Linux is available for [C/C++](https://www.mccdaq.com/PDFs/Manuals/UL-Linux/c/index.html) and [Python](https://www.mccdaq.com/PDFs/Manuals/UL-Linux/python/index.html).

View File

@ -1,5 +1,5 @@
m4_define([LIBUL_MAJOR], 1)
m4_define([LIBUL_MINOR], 0)
m4_define([LIBUL_MINOR], 1)
m4_define([LIBUL_MICRO], 0)
m4_define([LIBUL_RC],)
@ -9,9 +9,9 @@ AC_INIT([libuldaq],[LIBUL_MAJOR[.]LIBUL_MINOR[.]LIBUL_MICRO[]LIBUL_RC],[info@mcc
# These numbers should be tweaked on every release. Read carefully:
# http://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
# http://sourceware.org/autobook/autobook/autobook_91.html
lt_current=1
lt_current=2
lt_revision=0
lt_age=0
lt_age=1
LTLDFLAGS="-version-info ${lt_current}:${lt_revision}:${lt_age}"
CFLAGS='-O3'

View File

@ -38,8 +38,8 @@ int main(void)
int lowChan = 0;
int highChan = 3;
int chan = 0;
AiInputMode inputMode = AI_DIFFERENTIAL;
Range range = BIP10VOLTS;
AiInputMode inputMode;
Range range;
AInFlag flags = AIN_FF_DEFAULT;
int hasAI = 0;

View File

@ -42,8 +42,8 @@ int main(void)
// set some variables that are used to acquire data
int lowChan = 0;
int highChan = 3;
AiInputMode inputMode = AI_SINGLE_ENDED;
Range range = BIP10VOLTS;
AiInputMode inputMode;
Range range;
int samplesPerChannel = 10000;
double rate = 1000;
ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS);

View File

@ -54,8 +54,8 @@ int main(void)
// set some variables that are used to acquire data
int lowChan = 0;
int highChan = 3;
AiInputMode inputMode = AI_SINGLE_ENDED;
Range range = BIP10VOLTS;
AiInputMode inputMode;
Range range;
int samplesPerChannel = 10000;
AInScanFlag flags = AINSCAN_FF_DEFAULT;
DaqEventType eventTypes = (DaqEventType) (DE_ON_DATA_AVAILABLE | DE_ON_INPUT_SCAN_ERROR | DE_ON_END_OF_INPUT_SCAN);

View File

@ -32,7 +32,7 @@
#define MAX_RANGE_COUNT 8
#define MAX_STR_LENGTH 64
#define MAX_SCAN_OPTIONS_LENGTH 256
#define MAX_QUEUE_SIZE 8 // arbitrary limit for the size for the queue
#define MAX_QUEUE_SIZE 32 // arbitrary limit for the size for the queue
int main(void)
{
@ -46,8 +46,8 @@ int main(void)
// parameters are ignored since they are specified in queueArray
int lowChan = 0;
int highChan = 3;
AiInputMode inputMode = AI_SINGLE_ENDED;
Range range = BIP10VOLTS;
AiInputMode inputMode;
Range range;
// set some variables that are used to acquire data
int samplesPerChannel = 10000;
@ -121,9 +121,6 @@ int main(void)
goto end;
}
// get the analog input ranges
err = getAiInfoRanges(daqDeviceHandle, inputMode, &numRanges, ranges);
// get the queue types
err = getAiInfoQueueTypes(daqDeviceHandle, &queueTypes);
@ -133,9 +130,6 @@ int main(void)
if (highChan >= numberOfChannels)
highChan = numberOfChannels - 1;
if (highChan >= MAX_QUEUE_SIZE)
highChan = MAX_QUEUE_SIZE - 1;
chanCount = highChan - lowChan + 1;
// does the device support a queue
@ -145,6 +139,9 @@ int main(void)
goto end;
}
// get the analog input ranges
err = getAiInfoRanges(daqDeviceHandle, inputMode, &numRanges, ranges);
// assign each channel in the queue an input mode (SE/DIFF) and a range ... if
// multiple ranges are supported, we will cycle through them and repeat ranges if the
// number of channels exceeds the number of ranges
@ -199,6 +196,10 @@ int main(void)
// clear the display
ret = system("clear");
// the range argument of the ulAInScan function is ignored becasue the ragnes are set by the ulAInLoadQueue() function,
// however the range variable is initilized to an arbitrary range here to prevent compiler warnings
range = BIP10VOLTS;
// start the acquisition
//
// when using the queue, the lowChan, highChan, inputMode, and range

View File

@ -44,14 +44,15 @@ int main(void)
// set some variables that are used to acquire data
int lowChan = 0;
int highChan = 3;
AiInputMode inputMode = AI_SINGLE_ENDED;
Range range = BIP10VOLTS;
AiInputMode inputMode;
Range range;
int samplesPerChannel = 10000;
double rate = 1000;
ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS | SO_EXTTRIGGER);
AInScanFlag flags = AINSCAN_FF_DEFAULT;
int hasAI = 0;
int hasPacer = 0;
int numberOfChannels = 0;
TriggerType triggerType;
int index = 0;
@ -104,6 +105,14 @@ int main(void)
goto end;
}
// verify the specified device supports hardware pacing for analog input
err = getAiInfoHasPacer(daqDeviceHandle, &hasPacer);
if (!hasPacer)
{
printf("\nThe specified DAQ device does not support hardware paced analog input\n");
goto end;
}
printf("\nConnecting to device %s - please wait ...\n", devDescriptors[descriptorIndex].devString);
// establish a connection to the device

View File

@ -33,7 +33,7 @@ int main(void)
unsigned int numDevs = MAX_DEV_COUNT;
int channel = 0;
Range range = BIP10VOLTS;
Range range;
AOutFlag flags = AOUT_FF_DEFAULT;
int hasAO = 0;

View File

@ -45,7 +45,7 @@ int main(void)
int lowChan = 0;
int highChan = 0;
Range range = BIP10VOLTS;
Range range;
const int samplesPerChannel = 1000;
double rate = 1000;
ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS);

View File

@ -39,8 +39,8 @@ int main(void)
int hasDIO = 0;
int bitsPerPort = 0;
DigitalPortType portType = AUXPORT;
DigitalPortIoType portIoType = DPIOT_IN;
DigitalPortType portType;
DigitalPortIoType portIoType;
char portTypeStr[MAX_STR_LENGTH];
char portIoTypeStr[MAX_STR_LENGTH];
@ -95,11 +95,11 @@ int main(void)
if (err != ERR_NO_ERROR)
goto end;
// get the port types for the device (AUXPORT0, FIRSTPORTA, ...)
// get the first port type (AUXPORT0, FIRSTPORTA, ...)
err = getDioInfoFirstSupportedPortType(daqDeviceHandle, &portType, portTypeStr);
// get the port IO type
err = getDioInfoPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
// get the I/O type for the fisrt port
err = getDioInfoFirstSupportedPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
// get the number of bits for the first port (port index = 0)
err = getDioInfoNumberOfBitsForFirstPort(daqDeviceHandle, &bitsPerPort);
@ -116,7 +116,7 @@ int main(void)
break;
}
}
else
else if (portIoType == DPIOT_IO)
{
// configure the entire port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);

View File

@ -39,8 +39,8 @@ int main(void)
int hasDIO = 0;
int bitsPerPort = 0;
DigitalPortType portType = AUXPORT;
DigitalPortIoType portIoType = DPIOT_IN;
DigitalPortType portType;
DigitalPortIoType portIoType;
int maxPortValue = 0;
@ -99,11 +99,11 @@ int main(void)
if (err != ERR_NO_ERROR)
goto end;
// get the port types for the device (AUXPORT0, FIRSTPORTA, ...)
// get the first port type (AUXPORT0, FIRSTPORTA, ...)
err = getDioInfoFirstSupportedPortType(daqDeviceHandle, &portType, portTypeStr);
// get the port IO type
err = getDioInfoPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
// get the I/O type for the fisrt port
err = getDioInfoFirstSupportedPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
// get the number of bits for the first port (port index = 0)
err = getDioInfoNumberOfBitsForFirstPort(daqDeviceHandle, &bitsPerPort);
@ -120,7 +120,7 @@ int main(void)
break;
}
}
else
else if (portIoType == DPIOT_IO)
{
// configure the entire port for output
err = ulDConfigPort(daqDeviceHandle, portType, DD_OUTPUT);
@ -140,7 +140,7 @@ int main(void)
ret = system("clear");
while(err == ERR_NO_ERROR && err == ERR_NO_ERROR)
while(err == ERR_NO_ERROR)
{
// reset the cursor to the top of the display and
// show the termination message
@ -166,8 +166,11 @@ int main(void)
usleep(100000);
}
// before leaving, configure the entire port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
if(portIoType == DPIOT_IO || portIoType == DPIOT_BITIO)
{
// before leaving, configure the entire port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
}
// disconnect from the DAQ device
ulDisconnectDaqDevice(daqDeviceHandle);

View File

@ -37,9 +37,11 @@ int main(void)
unsigned int numDevs = MAX_DEV_COUNT;
int hasDIO = 0;
DigitalPortType portType = AUXPORT;
DigitalPortType portType;
DigitalPortIoType portIoType;
char portTypeStr[MAX_STR_LENGTH];
char portIoTypeStr[MAX_STR_LENGTH];
unsigned long long data = 0;
UlError err = ERR_NO_ERROR;
@ -90,15 +92,22 @@ int main(void)
if (err != ERR_NO_ERROR)
goto end;
// get the port types for the device (AUXPORT0, FIRSTPORTA, ...)
// get the first port type (AUXPORT0, FIRSTPORTA, ...)
err = getDioInfoFirstSupportedPortType(daqDeviceHandle, &portType, portTypeStr);
// configure the first port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
// get the I/O type for the fisrt port
err = getDioInfoFirstSupportedPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
if(portIoType == DPIOT_IO || portIoType == DPIOT_BITIO)
{
// configure the first port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
}
printf("\n%s ready\n", devDescriptors[descriptorIndex].devString);
printf(" Function demonstrated: ulDIn()\n");
printf(" Port: %s\n", portTypeStr);
printf(" Port I/O type: %s\n", portIoTypeStr);
printf("\nHit ENTER to continue\n");
ret = scanf("%c", &c);

View File

@ -38,8 +38,8 @@ int main(void)
DaqDeviceHandle daqDeviceHandle = 0;
unsigned int numDevs = MAX_DEV_COUNT;
DigitalPortType lowPort = AUXPORT;
DigitalPortType highPort = AUXPORT;
DigitalPortType lowPort;
DigitalPortType highPort;
int samplesPerPort = 1000;
double rate = 100;
ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS);
@ -52,7 +52,7 @@ int main(void)
char portTypeStr[MAX_STR_LENGTH];
char scanOptionsStr[MAX_SCAN_OPTIONS_LENGTH];
DigitalPortType portType = AUXPORT;
DigitalPortType portType;
int chanCount = 1;
unsigned long long* buffer;

View File

@ -36,9 +36,11 @@ int main(void)
int hasDIO = 0;
int bitsPerPort = 0;
DigitalPortType portType = AUXPORT;
DigitalPortType portType;
DigitalPortIoType portIoType;
char portTypeStr[MAX_STR_LENGTH];
char portIoTypeStr[MAX_STR_LENGTH];
unsigned long long maxPortValue = 0;
@ -93,14 +95,20 @@ int main(void)
if (err != ERR_NO_ERROR)
goto end;
// get the port types for the device (AUXPORT0, FIRSTPORTA, ...)
// get the first port type (AUXPORT0, FIRSTPORTA, ...)
err = getDioInfoFirstSupportedPortType(daqDeviceHandle, &portType, portTypeStr);
// get the I/O type for the fisrt port
err = getDioInfoFirstSupportedPortIoType(daqDeviceHandle, &portIoType, portIoTypeStr);
// get the number of bits for the first port
err = getDioInfoNumberOfBitsForFirstPort(daqDeviceHandle, &bitsPerPort);
// configure the first port for output
err = ulDConfigPort(daqDeviceHandle, portType, DD_OUTPUT);
if(portIoType == DPIOT_IO || portIoType == DPIOT_BITIO)
{
// configure the first port for output
err = ulDConfigPort(daqDeviceHandle, portType, DD_OUTPUT);
}
// calculate the max value for the port
maxPortValue = (unsigned long long) pow(2.0, (double)bitsPerPort) - 1;
@ -108,6 +116,7 @@ int main(void)
printf("\n%s ready\n", devDescriptors[descriptorIndex].devString);
printf(" Function demonstrated: ulDOut()\n");
printf(" Port: %s\n", portTypeStr);
printf(" Port I/O type: %s\n", portIoTypeStr);
printf("\nHit ENTER to continue\n");
ret = scanf("%c", &c);
@ -142,8 +151,11 @@ int main(void)
usleep(100000);
}
// before leaving, configure the entire first port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
if(portIoType == DPIOT_IO || portIoType == DPIOT_BITIO)
{
// before leaving, configure the entire port for input
err = ulDConfigPort(daqDeviceHandle, portType, DD_INPUT);
}
// disconnect from the DAQ device
ulDisconnectDaqDevice(daqDeviceHandle);

View File

@ -42,8 +42,8 @@ int main(void)
DaqDeviceHandle daqDeviceHandle = 0;
unsigned int numDevs = MAX_DEV_COUNT;
DigitalPortType lowPort = AUXPORT;
DigitalPortType highPort = AUXPORT;
DigitalPortType lowPort;
DigitalPortType highPort;
const int samplesPerPort = 1000;
double rate = 1000;
ScanOption scanOptions = (ScanOption) (SO_DEFAULTIO | SO_CONTINUOUS);
@ -57,7 +57,7 @@ int main(void)
char portTypeStr[MAX_STR_LENGTH];
char scanOptionsStr[MAX_SCAN_OPTIONS_LENGTH];
DigitalPortType portType = AUXPORT;
DigitalPortType portType;
int chanCount = 1;
unsigned long long* buffer;

View File

@ -7,7 +7,8 @@ CIn CInScan CInScanWithEncoder\
DaqInScan DaqInScanWithTrigger\
DaqOutScan\
DIn DBitIn DInScan DOut DBitOut DOutScan\
TmrPulseOut
TmrPulseOut\
TIn
AIn_SOURCES = AIn.c utility.h
AInScan_SOURCES = AInScan.c
@ -34,6 +35,7 @@ DBitOut_SOURCES = DBitOut.c
DOutScan_LDADD = $(LDADD) -lm
DOutScan_SOURCES = DOutScan.c
TmrPulseOut_SOURCES = TmrPulseOut.c
TIn_SOURCES = TIn.c

165
examples/TIn.c Normal file
View File

@ -0,0 +1,165 @@
/*
UL call demonstrated: ulTIn()
Purpose: Reads the user-specified temperature input channels
Demonstration: Displays the temperature data for each of
the user-specified channels
Steps:
1. Call ulGetDaqDeviceInventory() to get the list of available DAQ devices
2. Call ulCreateDaqDevice() to to get a handle for the first DAQ device
3. Verify the DAQ device has an analog input subsystem
4. Verify the DAQ device supports temperature input
5. Call ulConnectDaqDevice() to establish a UL connection to the DAQ device
6. Call ulTIn() for each channel specified to read a value from the A/D input channel
7. Display the data for each channel
8. Call ulDisconnectDaqDevice() and ulReleaseDaqDevice() before exiting the process.
*/
#include <stdio.h>
#include <stdlib.h>
#include "uldaq.h"
#include "utility.h"
#define MAX_DEV_COUNT 100
#define MAX_STR_LENGTH 64
int main(void)
{
int descriptorIndex = 0;
DaqDeviceDescriptor devDescriptors[MAX_DEV_COUNT];
DaqDeviceInterface interfaceType = ANY_IFC;
DaqDeviceHandle daqDeviceHandle = 0;
unsigned int numDevs = MAX_DEV_COUNT;
// set some variables used to acquire data
int lowChan = 0;
int highChan = 3;
int chan = 0;
TempScale scale = TS_CELSIUS;
TInFlag flags = TIN_FF_DEFAULT;
int hasAI = 0;
int hasTempChan = 0;
char chanTypeStr[MAX_STR_LENGTH];
char sensorStr[MAX_STR_LENGTH];
int i = 0;
double data = 0;
UlError err = ERR_NO_ERROR;
int __attribute__((unused)) ret;
char c;
// Get descriptors for all of the available DAQ devices
err = ulGetDaqDeviceInventory(interfaceType, devDescriptors, &numDevs);
if (err != ERR_NO_ERROR)
goto end;
// verify at least one DAQ device is detected
if (numDevs == 0)
{
printf("No DAQ device is detected\n");
goto end;
}
printf("Found %d DAQ device(s)\n", numDevs);
for (i = 0; i < (int) numDevs; i++)
printf(" %s: (%s)\n", devDescriptors[i].productName, devDescriptors[i].uniqueId);
// get a handle to the DAQ device associated with the first descriptor
daqDeviceHandle = ulCreateDaqDevice(devDescriptors[descriptorIndex]);
if (daqDeviceHandle == 0)
{
printf ("\nUnable to create a handle to the specified DAQ device\n");
goto end;
}
// verify the specified DAQ device supports analog input
err = getDevInfoHasAi(daqDeviceHandle, &hasAI);
if (!hasAI)
{
printf("\nThe specified DAQ device does not support analog input\n");
goto end;
}
// verify the specified DAQ device has temperature channels
err = getAiInfoHasTempChan(daqDeviceHandle, &hasTempChan);
if (!hasTempChan)
{
printf("\nThe specified DAQ device does not have a temperature channel\n");
goto end;
}
printf("\nConnecting to device %s - please wait ...\n", devDescriptors[descriptorIndex].devString);
// establish a connection to the DAQ device
err = ulConnectDaqDevice(daqDeviceHandle);
if (err != ERR_NO_ERROR)
goto end;
printf("\n%s ready\n", devDescriptors[descriptorIndex].devString);
printf(" Function demonstrated: ulTIn()\n");
printf(" Channels: %d - %d\n", lowChan, highChan);
for (chan = lowChan; chan <= highChan; chan++)
{
getAiInfoTempChanConfig(daqDeviceHandle, chan, chanTypeStr, sensorStr);
printf(" Channel %d: type: %s (%s)\n", chan, chanTypeStr, sensorStr);
}
printf("\nHit ENTER to continue\n");
ret = scanf("%c", &c);
ret = system("clear");
while(err == ERR_NO_ERROR && !enter_press())
{
// reset the cursor to the top of the display and
// show the termination message
resetCursor();
printf("Hit 'Enter' to terminate the process\n\n");
// display data for the first 4 analog input channels
for (chan = lowChan; chan <= highChan; chan++)
{
err = ulTIn(daqDeviceHandle, chan, scale, flags, &data);
if(err == ERR_NO_ERROR)
printf("Channel(%d) Data: %10.6f %20s\n", chan, data, "");
else if(err == ERR_OPEN_CONNECTION)
{
printf("Channel(%d) Data: %10.6f (open connection)\n", chan, data);
err = ERR_NO_ERROR;
}
}
usleep(500000);
}
// disconnect from the DAQ device
ulDisconnectDaqDevice(daqDeviceHandle);
end:
// release the handle to the DAQ device
if(daqDeviceHandle)
ulReleaseDaqDevice(daqDeviceHandle);
if(err != ERR_NO_ERROR)
{
char errMsg[ERR_MSG_LEN];
ulGetErrMsg(err, errMsg);
printf("Error Code: %d \n", err);
printf("Error Message: %s \n", errMsg);
}
return 0;
}

View File

@ -166,6 +166,9 @@ void ConvertRangeToString(Range range, char* rangeStr)
case(UNIPT005VOLTS):
strcpy(rangeStr, "UNIPT005VOLTS");
break;
case(MA0TO20):
strcpy(rangeStr, "MA0TO20");
break;
}
}
@ -342,6 +345,10 @@ void ConvertRangeToMinMax(Range range, double* min, double* max)
*min = 0.0;
*max = 0.005;
break;
case(MA0TO20):
*min = 0.0;
*max = 20.0;
break;
}
}
@ -640,6 +647,56 @@ void ConvertDaqOChanTypeToString(DaqOutChanType daqoChanType, char* daqoChanType
}
}
void ConvertTCTypeToString(TcType type, char* typeStr)
{
switch(type)
{
case(TC_J):
strcpy(typeStr, "J");
break;
case(TC_K):
strcpy(typeStr, "K");
break;
case(TC_T):
strcpy(typeStr, "T");
break;
case(TC_E):
strcpy(typeStr, "E");
break;
case(TC_R):
strcpy(typeStr, "R");
break;
case(TC_S):
strcpy(typeStr, "S");
break;
case(TC_B):
strcpy(typeStr, "B");
break;
case(TC_N):
strcpy(typeStr, "N");
break;
}
}
void ConvertSensorConnectionTypeToString(SensorConnectionType type, char* typeStr)
{
switch(type)
{
case(SCT_2_WIRE_1):
strcpy(typeStr, "2-wire (1 sensor)");
break;
case(SCT_2_WIRE_2):
strcpy(typeStr, "2-wire (2 sensors)");
break;
case(SCT_3_WIRE):
strcpy(typeStr, "3-wire");
break;
case(SCT_4_WIRE):
strcpy(typeStr, "4-wire");
break;
}
}
/****************************************************************************
* Device Info Functions
****************************************************************************/
@ -752,7 +809,7 @@ UlError getAiInfoFirstTriggerType(DaqDeviceHandle daqDeviceHandle, TriggerType*
long long triggerTypes = 0;
err = ulAIGetInfo(daqDeviceHandle, AI_INFO_TRIG_TYPES, 0, &triggerTypes);
if (err == ERR_NO_ERROR)
if (err == ERR_NO_ERROR && triggerTypes != 0)
{
// use the first available trigger type
long long triggerMask = 1;
@ -810,9 +867,16 @@ UlError getAiInfoFirstSupportedInputMode(DaqDeviceHandle daqDeviceHandle, int* n
err = ulAIGetInfo(daqDeviceHandle, AI_INFO_NUM_CHANS_BY_MODE, AI_SINGLE_ENDED, &numChans);
if (numChans > 0)
{
*inputMode = AI_SINGLE_ENDED;
}
else
*inputMode = AI_DIFFERENTIAL;
{
err = ulAIGetInfo(daqDeviceHandle, AI_INFO_NUM_CHANS_BY_MODE, AI_DIFFERENTIAL, &numChans);
if (numChans > 0)
*inputMode = AI_DIFFERENTIAL;
}
ConvertInputModeToString(*inputMode, inputModeStr);
@ -854,6 +918,67 @@ UlError getAiInfoQueueTypes(DaqDeviceHandle daqDeviceHandle, int* queueTypes)
return err;
}
UlError getAiInfoHasTempChan(DaqDeviceHandle daqDeviceHandle, int* hasTempChan)
{
long long chanTypeMask = 0;
UlError err = ERR_NO_ERROR;
err = ulAIGetInfo(daqDeviceHandle, AI_INFO_CHAN_TYPES, 0, &chanTypeMask);
if(chanTypeMask & (AI_TC | AI_RTD | AI_THERMISTOR | AI_SEMICONDUCTOR))
*hasTempChan = 1;
else
*hasTempChan = 0;
return err;
}
UlError getAiInfoTempChanConfig(DaqDeviceHandle daqDeviceHandle, int chan, char* chanTypeStr, char* sensorStr)
{
UlError err = ERR_NO_ERROR;
long long chanType, cfg;
char typeStr[64] = "";
char cfgStr[64] = "N/A";
err = ulAIGetConfig(daqDeviceHandle, AI_CFG_CHAN_TYPE, chan, &chanType);
if(chanType == AI_TC)
{
strcpy(typeStr, "Thermocouple");
err = ulAIGetConfig(daqDeviceHandle, AI_CFG_CHAN_TC_TYPE, chan, &cfg);
ConvertTCTypeToString((TcType)cfg, cfgStr);
}
else if(chanType == AI_RTD || chanType == AI_THERMISTOR)
{
if(chanType == AI_RTD)
strcpy(typeStr, "RTD");
else
strcpy(typeStr, "Thermistor");
err = ulAIGetConfig(daqDeviceHandle, AI_CFG_CHAN_SENSOR_CONNECTION_TYPE, chan, &cfg);
ConvertSensorConnectionTypeToString((SensorConnectionType) cfg, cfgStr);
}
else if(chanType == AI_SEMICONDUCTOR)
{
strcpy(typeStr, "Semicoductor");
}
else if(chanType == AI_VOLTAGE)
{
strcpy(typeStr, "Voltage");
}
else if(chanType == AI_DISABLED)
strcpy(typeStr, "Disabled");
strcpy(chanTypeStr, typeStr);
strcpy(sensorStr, cfgStr);
return err;
}
/****************************************************************************
* Analog Output Info Functions
@ -926,7 +1051,7 @@ UlError getDioInfoNumberOfBitsForFirstPort(DaqDeviceHandle daqDeviceHandle, int*
return err;
}
UlError getDioInfoPortIoType(DaqDeviceHandle daqDeviceHandle, DigitalPortIoType* portIoType, char* portIoTypeStr)
UlError getDioInfoFirstSupportedPortIoType(DaqDeviceHandle daqDeviceHandle, DigitalPortIoType* portIoType, char* portIoTypeStr)
{
UlError err = ERR_NO_ERROR;
long long ioType;
@ -1062,7 +1187,7 @@ UlError getDaqiInfoFirstTriggerType(DaqDeviceHandle daqDeviceHandle, TriggerType
long long triggerTypes = 0;
err = ulDaqIGetInfo(daqDeviceHandle, DAQI_INFO_TRIG_TYPES, 0, &triggerTypes);
if (err == ERR_NO_ERROR)
if (err == ERR_NO_ERROR && triggerTypes != 0)
{
// use the first available trigger type
long long triggerMask = 1;

Binary file not shown.

View File

@ -1,4 +1,28 @@
# allow access to usb devices by non-root users
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0076", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="007f", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0085", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0086", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="008a", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="008b", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="008c", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="008d", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0090", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0092", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0093", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0094", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0095", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="0096", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009a", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009b", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009c", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009d", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009e", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="009f", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00a2", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00a3", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00a4", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00bb", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00bc", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00c4", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00c5", GROUP="adm", MODE="0666"
SUBSYSTEM=="usb", ATTR{idVendor}=="09db", ATTR{idProduct}=="00c6", GROUP="adm", MODE="0666"

View File

@ -37,19 +37,19 @@ TcType AiConfig::getChanTcType(int channel)
return mAiDevice.getCfg_ChanTcType(channel);
}
void AiConfig::setChanTempUnit(int channel, TempUnit unit)
void AiConfig::setScanChanTempUnit(int channel, TempUnit unit)
{
mAiDevice.setCfg_ChanTempUnit(channel, unit);
mAiDevice.setCfg_ScanChanTempUnit(channel, unit);
}
TempUnit AiConfig::getChanTempUnit(int channel)
TempUnit AiConfig::getScanChanTempUnit(int channel)
{
return mAiDevice.getCfg_ChanTempUnit(channel);
return mAiDevice.getCfg_ScanChanTempUnit(channel);
}
void AiConfig::setTempUnit(TempUnit unit)
void AiConfig::setScanTempUnit(TempUnit unit)
{
mAiDevice.setCfg_TempUnit(unit);
mAiDevice.setCfg_ScanTempUnit(unit);
}
void AiConfig::setAutoZeroMode(AutoZeroMode mode)
@ -131,4 +131,14 @@ void AiConfig::getCalDateStr(char* calDate, unsigned int* maxStrLen)
return mAiDevice.getCfg_CalDateStr(calDate, maxStrLen);
}
void AiConfig::getChanCoefsStr(int channel, char* coefs, unsigned int* maxStrLen)
{
return mAiDevice.getCfg_ChanCoefsStr(channel, coefs, maxStrLen);
}
SensorConnectionType AiConfig::getChanSensorConnectionType(int channel)
{
return mAiDevice.getCfg_SensorConnectionType(channel);
}
} /* namespace ul */

View File

@ -25,10 +25,10 @@ public:
virtual void setChanTcType(int channel, TcType tcType);
virtual TcType getChanTcType(int channel);
virtual void setChanTempUnit(int channel, TempUnit unit);
virtual TempUnit getChanTempUnit(int channel);
virtual void setScanChanTempUnit(int channel, TempUnit unit);
virtual TempUnit getScanChanTempUnit(int channel);
virtual void setTempUnit(TempUnit unit);
virtual void setScanTempUnit(TempUnit unit);
//virtual TempUnit getTempUnit();
virtual void setAutoZeroMode(AutoZeroMode mode);
@ -55,6 +55,9 @@ public:
virtual unsigned long long getCalDate(); // returns number of seconds since unix epoch
virtual void getCalDateStr(char* calDate, unsigned int* maxStrLen);
virtual void getChanCoefsStr(int channel, char* coefs, unsigned int* maxStrLen);
virtual SensorConnectionType getChanSensorConnectionType(int channel);
private:
AiDevice& mAiDevice;
};

View File

@ -20,6 +20,7 @@ AiDevice::AiDevice(const DaqDevice& daqDevice) : IoDevice(daqDevice), UlAiDevice
mAiConfig = new AiConfig(*this);
mCalDate = 0;
mCalModeEnabled = false;
mScanTempChanSupported = false;
}
AiDevice::~AiDevice()
@ -75,6 +76,15 @@ void AiDevice::stopBackground()
throw UlException(ERR_BAD_DEV_TYPE);
}
void AiDevice::tIn(int channel, TempScale scale, TInFlag flags, double* data)
{
throw UlException(ERR_BAD_DEV_TYPE);
}
void AiDevice::tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[])
{
throw UlException(ERR_BAD_DEV_TYPE);
}
void AiDevice::check_AIn_Args(int channel, AiInputMode inputMode, Range range, AInFlag flags) const
{
if(!mAiInfo.isInputModeSupported(inputMode))
@ -151,7 +161,7 @@ void AiDevice::check_AInScan_Args(int lowChan, int highChan, AiInputMode inputMo
if(samplesPerChan < mMinScanSampleCount)
throw UlException(ERR_BAD_SAMPLE_COUNT);
long long totalCount = samplesPerChan * numOfScanChan;
long long totalCount = (long long) samplesPerChan * numOfScanChan;
if(options & SO_BURSTIO)
{
@ -477,6 +487,58 @@ void AiDevice::initCustomScales()
}
}
void AiDevice::initTempUnits()
{
for(int i = 0; i < mAiInfo.getNumChans(); i++)
{
mScanChanTempUnit.push_back(TU_CELSIUS);
}
}
void AiDevice::check_TIn_Args(int channel, TempScale scale, TInFlag flags) const
{
if(channel < 0 || channel >= mAiInfo.getNumChans())
{
bool cjcChan = false;
if(channel > 0)
{
for(int i = 0; i < mAiInfo.getNumCjcChans(); i++)
{
if(channel == (0x80 + i))
{
cjcChan = true;
break;
}
}
}
if(!cjcChan)
throw UlException(ERR_BAD_AI_CHAN);
}
if(~mAiInfo.getTInFlags() & flags)
throw UlException(ERR_BAD_FLAG);
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void AiDevice::check_TInArray_Args(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[]) const
{
if(lowChan < 0 || highChan < 0 || lowChan >= mAiInfo.getNumChans() || highChan >= mAiInfo.getNumChans() || lowChan > highChan )
throw UlException(ERR_BAD_AI_CHAN);
if(~mAiInfo.getTInArrayFlags() & flags)
throw UlException(ERR_BAD_FLAG);
if(data == NULL)
throw UlException(ERR_BAD_BUFFER);
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
////////////////////// Configuration functions /////////////////////////////////
@ -498,31 +560,40 @@ TcType AiDevice::getCfg_ChanTcType(int channel) const
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
void AiDevice::setCfg_TempUnit(TempUnit unit)
void AiDevice::setCfg_ScanTempUnit(TempUnit unit)
{
if(!mScanTempChanSupported)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if( unit < TU_CELSIUS || unit > TU_KELVIN)
throw UlException(ERR_BAD_UNIT);
for(unsigned int i = 0; i < mChanTempUnit.size(); i++)
mChanTempUnit[i] = unit;
for(unsigned int i = 0; i < mScanChanTempUnit.size(); i++)
mScanChanTempUnit[i] = unit;
}
void AiDevice::setCfg_ChanTempUnit(int channel, TempUnit unit)
void AiDevice::setCfg_ScanChanTempUnit(int channel, TempUnit unit)
{
if(channel < 0 || channel >= (int) mChanTempUnit.size())
if(!mScanTempChanSupported)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= (int) mScanChanTempUnit.size())
throw UlException(ERR_BAD_AI_CHAN);
if( unit < TU_CELSIUS || unit > TU_KELVIN)
throw UlException(ERR_BAD_UNIT);
mChanTempUnit[channel] = unit;
mScanChanTempUnit[channel] = unit;
}
TempUnit AiDevice::getCfg_ChanTempUnit(int channel) const
TempUnit AiDevice::getCfg_ScanChanTempUnit(int channel) const
{
if(channel < 0 || channel >= (int) mChanTempUnit.size())
if(!mScanTempChanSupported)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= (int) mScanChanTempUnit.size())
throw UlException(ERR_BAD_AI_CHAN);
return mChanTempUnit[channel];
return mScanChanTempUnit[channel];
}
void AiDevice::setCfg_AutoZeroMode(AutoZeroMode mode)
@ -559,7 +630,7 @@ void AiDevice::setCfg_ChanCouplingMode(int channel, CouplingMode mode)
}
CouplingMode AiDevice::getCfg_ChanCouplingMode(int channel)
{
return CM_DC;
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
void AiDevice::setCfg_ChanSensorSensitivity(int channel, double sensitivity)
@ -636,8 +707,16 @@ void AiDevice::getCfg_CalDateStr(char* calDate, unsigned int* maxStrLen)
throw UlException(ERR_BAD_BUFFER_SIZE);
}
}
SensorConnectionType AiDevice::getCfg_SensorConnectionType(int channel) const
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
void AiDevice::getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}

View File

@ -32,6 +32,9 @@ public:
virtual UlError getStatus(ScanStatus* status, TransferStatus* xferStatus);
virtual void stopBackground();
virtual void tIn(int channel, TempScale scale, TInFlag flags, double* data);
virtual void tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[]);
double convertTempUnit(double tempC, TempUnit unit);
////////////////////// Configuration functions /////////////////////////////////
@ -41,11 +44,11 @@ public:
virtual void setCfg_ChanTcType(int channel, TcType tcType);
virtual TcType getCfg_ChanTcType(int channel) const;
virtual void setCfg_TempUnit(TempUnit unit);
virtual void setCfg_ScanTempUnit(TempUnit unit);
//virtual TempUnit getCfg_TempUnit() const;
virtual void setCfg_ChanTempUnit(int channel, TempUnit unit);
virtual TempUnit getCfg_ChanTempUnit(int channel) const;
virtual void setCfg_ScanChanTempUnit(int channel, TempUnit unit);
virtual TempUnit getCfg_ScanChanTempUnit(int channel) const;
virtual void setCfg_AutoZeroMode(AutoZeroMode mode);
virtual AutoZeroMode getCfg_AutoZeroMode() const;
@ -70,6 +73,10 @@ public:
virtual unsigned long long getCfg_CalDate();
virtual void getCfg_CalDateStr(char* calDate, unsigned int* maxStrLen);
virtual SensorConnectionType getCfg_SensorConnectionType(int channel) const;
virtual void getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const;
protected:
virtual void loadAdcCoefficients() = 0;
virtual int getCalCoefIndex(int channel, AiInputMode inputMode, Range range) const = 0;
@ -80,10 +87,12 @@ protected:
bool queueEnabled() const;
int queueLength() const;
void check_AIn_Args(int channel, AiInputMode inputMode, Range range, AInFlag flags) const;
void check_AInScan_Args(int lowChan, int highChan, AiInputMode inputMode, Range range, int samplesPerChan, double rate, ScanOption options, AInScanFlag flags, double data[]) const;
void check_AInLoadQueue_Args(const AiQueueElement queue[], unsigned int numElements) const;
void check_AInSetTrigger_Args(TriggerType trigtype, int trigChan, double level, double variance, unsigned int retriggerCount) const;
virtual void check_AIn_Args(int channel, AiInputMode inputMode, Range range, AInFlag flags) const;
virtual void check_AInScan_Args(int lowChan, int highChan, AiInputMode inputMode, Range range, int samplesPerChan, double rate, ScanOption options, AInScanFlag flags, double data[]) const;
virtual void check_AInLoadQueue_Args(const AiQueueElement queue[], unsigned int numElements) const;
virtual void check_AInSetTrigger_Args(TriggerType trigtype, int trigChan, double level, double variance, unsigned int retriggerCount) const;
virtual void check_TIn_Args(int channel, TempScale scale, TInFlag flags) const;
virtual void check_TInArray_Args(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[]) const;
bool isValidChanQueue(const AiQueueElement queue[], unsigned int numElements) const;
bool isValidGainQueue(const AiQueueElement queue[], unsigned int numElements) const;
@ -92,6 +101,8 @@ protected:
void initCustomScales();
std::vector<CustomScale> getCustomScales(int lowChan, int highChan) const;
void initTempUnits();
void enableCalMode(bool enable) { mCalModeEnabled = enable;}
bool calModeEnabled() const { return mCalModeEnabled;}
@ -104,7 +115,8 @@ protected:
std::vector<CustomScale> mCustomScales;
std::vector<AiQueueElement> mAQueue;
std::vector<TempUnit> mChanTempUnit;
bool mScanTempChanSupported;
std::vector<TempUnit> mScanChanTempUnit;
unsigned long long mCalDate; // cal date in sec

View File

@ -37,6 +37,9 @@ AiInfo::AiInfo()
mChanQueueLimitations = (AiChanQueueLimitation) 0;
mTriggerTypes = TRIG_NONE;
mTypes = (AiChanType) 0;
mTInFlags = 0;
mTInArrayFlags = 0;
mNumCjcChans = 0;
}
AiInfo::~AiInfo()
@ -210,9 +213,38 @@ long long AiInfo::getAInScanFlags() const
return mAInScanFlags;
}
void AiInfo::setTInFlags(long long flags)
{
mTInFlags = flags;
}
long long AiInfo::getTInFlags() const
{
return mTInFlags;
}
void AiInfo::setTInArrayFlags(long long flags)
{
mTInArrayFlags = flags;
}
long long AiInfo::getTInArrayFlags() const
{
return mTInArrayFlags;
}
void AiInfo::setNumCjcChans(int numChans)
{
mNumCjcChans = numChans;
}
int AiInfo::getNumCjcChans() const
{
return mNumCjcChans;
}
void AiInfo::addRange(AiInputMode mode, Range range)
{
if(mode == AI_SINGLE_ENDED)
{
mSERanges.push_back(range);

View File

@ -54,6 +54,10 @@ public:
long long getAInFlags() const;
void setAInScanFlags(long long flags);
long long getAInScanFlags() const;
void setTInFlags(long long flags);
long long getTInFlags() const;
void setTInArrayFlags(long long flags);
long long getTInArrayFlags() const;
void addInputMode(AiInputMode mode);
std::vector<AiInputMode> getInputModes() const;
@ -93,6 +97,9 @@ public:
bool isInputModeSupported(AiInputMode inputMode) const;
bool isRangeSupported(AiInputMode inputMode, Range range) const;
void setNumCjcChans(int numChans);
int getNumCjcChans() const;
private:
std::vector<AiChanInfo> mAiChanInfo;
std::vector<Range> mSERanges;
@ -125,6 +132,11 @@ private:
long long mAInFlags;
long long mAInScanFlags;
long long mTInFlags;
long long mTInArrayFlags;
int mNumCjcChans;
};
} /* namespace ul */

View File

@ -3,7 +3,7 @@
*
* Author: Measurement Computing Corporation
*/
#include "AoDevice.h"
#include "AoConfig.h"
namespace ul
@ -20,4 +20,14 @@ AoConfig::~AoConfig()
}
void AoConfig::setSyncMode(AOutSyncMode mode)
{
mAoDevice.setCfg_SyncMode(mode);
}
AOutSyncMode AoConfig::getSyncMode()
{
return mAoDevice.getCfg_SyncMode();
}
} /* namespace ul */

View File

@ -20,6 +20,9 @@ public:
AoConfig(AoDevice& aoDevice);
virtual ~AoConfig();
virtual void setSyncMode(AOutSyncMode mode);
virtual AOutSyncMode getSyncMode();
private:
AoDevice& mAoDevice;
};

View File

@ -34,6 +34,18 @@ void AoDevice::aOut(int channel, Range range, AOutFlag flags, double dataValue)
throw UlException(ERR_BAD_DEV_TYPE);
}
void AoDevice::aOutArray(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[])
{
check_AOutArray_Args(lowChan, highChan, range, flags, data);
int i;
for(int chan = lowChan; chan <= highChan; chan++)
{
i = chan - lowChan;
aOut(chan, range[i], (AOutFlag) flags, data[i]);
}
}
double AoDevice::aOutScan(int lowChan, int highChan, Range range, int samplesPerChan, double rate, ScanOption options, AOutScanFlag flags, double data[])
{
throw UlException(ERR_BAD_DEV_TYPE);
@ -274,6 +286,59 @@ void AoDevice::check_AOut_Args(int channel, Range range, AOutFlag flags, double
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void AoDevice::check_AOutArray_Args(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[]) const
{
int numOfScanChan = 0;
double maxDataValue;
bool scaled = true;
if(flags & NOSCALEDATA)
scaled = false;
if(getScanState() == SS_RUNNING)
throw UlException(ERR_ALREADY_ACTIVE);
if(lowChan < 0 || highChan < 0 || lowChan > mAoInfo.getNumChans() || highChan >= mAoInfo.getNumChans() || lowChan > highChan )
throw UlException(ERR_BAD_AO_CHAN);
if(data == NULL || range == NULL)
throw UlException(ERR_BAD_BUFFER);
if(~mAoInfo.getAOutArrayFlags() & flags)
throw UlException(ERR_BAD_FLAG);
numOfScanChan = highChan - lowChan + 1;
for(int i = 0; i < numOfScanChan; i++)
{
if(!mAoInfo.isRangeSupported(range[i]))
throw UlException(ERR_BAD_RANGE);
maxDataValue = getMaxOutputValue(range[i], scaled);
if (data[i] > maxDataValue)
throw UlException(ERR_BAD_DA_VAL);
if(flags & NOSCALEDATA)
{
if(data[0] < 0)
throw UlException(ERR_BAD_DA_VAL);
}
else
{
double offset = 0;
double scale = 0;
mDaqDevice.getEuScaling(range[i], scale, offset);
if(data[i] < offset)
throw UlException(ERR_BAD_DA_VAL);
}
}
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void AoDevice::check_AOutScan_Args(int lowChan, int highChan, Range range, int samplesPerChan, double rate, ScanOption options, AOutScanFlag flags, double data[]) const
{
int numOfScanChan = 0;
@ -342,4 +407,16 @@ void AoDevice::check_AOutSetTrigger_Args(TriggerType trigType, int trigChan, do
}
////////////////////// Configuration functions /////////////////////////////////
void AoDevice::setCfg_SyncMode(AOutSyncMode mode)
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
AOutSyncMode AoDevice::getCfg_SyncMode() const
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
} /* namespace ul */

View File

@ -28,12 +28,17 @@ public:
virtual UlAoConfig& getAoConfig() { return *mAoConfig;}
virtual void aOut(int channel, Range range, AOutFlag flags, double dataValue);
virtual void aOutArray(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[]);
virtual double aOutScan(int lowChan, int highChan, Range range, int samplesPerChan, double rate, ScanOption options, AOutScanFlag flags, double data[]);
virtual void setTrigger(TriggerType type, int trigChan, double level, double variance, unsigned int retriggerCount);
virtual UlError getStatus(ScanStatus* status, TransferStatus* xferStatus);
virtual void stopBackground();
////////////////////// Configuration functions /////////////////////////////////
virtual void setCfg_SyncMode(AOutSyncMode mode);
virtual AOutSyncMode getCfg_SyncMode() const;
protected:
virtual void loadDacCoefficients() = 0;
virtual int getCalCoefIndex(int channel, Range range) const = 0;
@ -49,6 +54,7 @@ protected:
double toEngUnits(unsigned int counts, Range range) const;
void check_AOut_Args(int channel, Range range, AOutFlag flags, double dataValue) const;
void check_AOutArray_Args(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[]) const;
void check_AOutScan_Args(int lowChan, int highChan, Range range, int samplesPerChan, double rate, ScanOption options, AOutScanFlag flags, double data[]) const;
void check_AOutSetTrigger_Args(TriggerType trigType, int trigChan, double level, double variance, unsigned int retriggerCount) const;

View File

@ -25,6 +25,7 @@ AoInfo::AoInfo()
mCalDateAddr = -1;
mSampleSize = 0;
mAOutFlags = 0;
mAOutArrayFlags = 0;
mAOutScanFlags = 0;
mTriggerTypes = TRIG_NONE;
}
@ -114,6 +115,16 @@ long long AoInfo::getAOutFlags() const
return mAOutFlags;
}
void AoInfo::setAOutArrayFlags(long long flags)
{
mAOutArrayFlags = flags;
}
long long AoInfo::getAOutArrayFlags() const
{
return mAOutArrayFlags;
}
void AoInfo::setAOutScanFlags(long long flags)
{
mAOutScanFlags = flags;

View File

@ -41,6 +41,8 @@ public:
void setAOutFlags(long long flags);
long long getAOutFlags() const;
void setAOutArrayFlags(long long flags);
long long getAOutArrayFlags() const;
void setAOutScanFlags(long long flags);
long long getAOutScanFlags() const;
@ -88,6 +90,7 @@ private:
int mSampleSize;
long long mAOutFlags;
long long mAOutArrayFlags;
long long mAOutScanFlags;
};

View File

@ -189,11 +189,21 @@ void CtrDevice::check_CInScan_Args(int lowCtrNum, int highCtrNum, int samplesPer
throw UlException(ERR_BAD_FLAG);
if(((flags & CINSCAN_FF_CTR16_BIT) && (flags & CINSCAN_FF_CTR32_BIT)) ||
((flags & CINSCAN_FF_CTR16_BIT) && (flags & CINSCAN_FF_CTR48_BIT)) ||
((flags & CINSCAN_FF_CTR16_BIT) && (flags & CINSCAN_FF_CTR64_BIT)) ||
((flags & CINSCAN_FF_CTR32_BIT) && (flags & CINSCAN_FF_CTR48_BIT)) ||
((flags & CINSCAN_FF_CTR32_BIT) && (flags & CINSCAN_FF_CTR64_BIT)))
throw UlException(ERR_BAD_FLAG);
double throughput = rate * numOfScanCtr;
int sampleSize = 2;
if(flags & CINSCAN_FF_CTR32_BIT)
sampleSize = 4;
else if ((flags & CINSCAN_FF_CTR48_BIT) || (flags & CINSCAN_FF_CTR64_BIT))
sampleSize = 8;
double throughput = rate * numOfScanCtr * (sampleSize / 2);
if(!(options & SO_EXTCLOCK))
{

View File

@ -26,7 +26,7 @@ namespace ul
pthread_mutex_t DaqDevice::mDeviceNumberMutex = PTHREAD_MUTEX_INITIALIZER;
unsigned long long DaqDevice::mNextAvailableDeviceNumber = 1;
DaqDevice::DaqDevice(DaqDeviceDescriptor daqDeviceDescriptor): mDaqDeviceDescriptor(daqDeviceDescriptor), mConnected(false),
DaqDevice::DaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor): mDaqDeviceDescriptor(daqDeviceDescriptor), mConnected(false),
mAiDevice(NULL), mAoDevice(NULL), mDioDevice(NULL), mCtrDevice(NULL), mTmrDevice(NULL), mDaqIDevice(NULL), mDaqODevice(NULL)
{
mEventHandler = new DaqEventHandler(*this);
@ -477,7 +477,7 @@ IoDevice* DaqDevice::getIoDevice(FunctionType functionType) const
TriggerConfig DaqDevice::getTriggerConfig(FunctionType functionType) const
{
TriggerConfig trigCfg;
TriggerConfig trigCfg = {(TriggerType) 0, 0, 0, 0, 0};
if(functionType == FT_AI && mAiDevice)
trigCfg = mAiDevice->getTrigConfig();

View File

@ -8,6 +8,7 @@
#ifndef DAQDEVICE_H_
#define DAQDEVICE_H_
#include "DaqDeviceId.h"
#include "DaqDeviceInfo.h"
#include "DaqDeviceConfig.h"
#include "interfaces/UlDaqDevice.h"
@ -30,7 +31,7 @@ class DaqEventHandler;
class UL_LOCAL DaqDevice: public UlDaqDevice
{
public:
DaqDevice(DaqDeviceDescriptor daqDeviceDescriptor);
DaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~DaqDevice();
virtual void connect()= 0;
@ -98,6 +99,8 @@ public:
virtual void setCalOutput (unsigned int index) const { };
unsigned short getRawFwVer() const { return mRawFwVersion;}
// public interface functions
UlAiDevice& getAiDevice() const;
UlAoDevice& getAoDevice() const;

View File

@ -19,7 +19,32 @@ class DaqDeviceId
public:
enum
{
USB_1024LS = 0x76,
USB_1024HLS = 0x7f,
USB_SSR24 = 0x85,
USB_SSR08 = 0x86,
USB_ERB24 = 0x8a,
USB_ERB08 = 0x8b,
USB_PDISO8 = 0x8c,
USB_TEMP = 0x8d,
USB_TC = 0x90,
USB_DIO96H = 0x92,
USB_DIO24 = 0x93,
USB_DIO24H = 0x94,
USB_DIO96H_50 = 0x95,
USB_PDISO8_40 = 0x96,
USB_3101 = 0x9a,
USB_3102 = 0x9b,
USB_3103 = 0x9c,
USB_3104 = 0x9d,
USB_3105 = 0x9e,
USB_3106 = 0x9f,
USB_3110 = 0xa2,
USB_3112 = 0xa3,
USB_3114 = 0xa4,
USB_TC_AI = 0xbb,
USB_TEMP_AI = 0xbc,
USB_1208FS_PLUS = 0xe8,
USB_1408FS_PLUS = 0xe9,
USB_1608FS_PLUS = 0xea,

View File

@ -6,7 +6,6 @@
*/
#include "DaqDeviceManager.h"
#include "DaqDeviceId.h"
#include "./utility/FnLog.h"
#include <algorithm>
@ -57,7 +56,31 @@ void DaqDeviceManager::addSupportedDaqDevice()
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_CTR08, "USB-CTR08"));
// HID devices
//mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_TC, "USB-TC"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_DIO96H, "USB-DIO96H"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_DIO96H_50, "USB-DIO96H/50"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_1024LS, "USB-1024LS"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_1024HLS, "USB-1024HLS"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_DIO24, "USB-DIO24/37"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_DIO24H, "USB-DIO24H/37"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_PDISO8, "USB-PDISO8"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_PDISO8_40, "USB-PDISO8/40"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_SSR24, "USB-SSR24"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_SSR08, "USB-SSR08"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_ERB24, "USB-ERB24"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_ERB08, "USB-ERB08"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3101, "USB-3101"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3102, "USB-3102"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3103, "USB-3103"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3104, "USB-3104"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3105, "USB-3105"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3106, "USB-3106"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3110, "USB-3110"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3112, "USB-3112"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_3114, "USB-3114"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_TEMP, "USB-TEMP"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_TC, "USB-TC"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_TEMP_AI, "USB-TEMP_AI"));
mSupportedDevices.insert(std::pair<int, std::string>(DaqDeviceId::USB_TC_AI, "USB-TC_AI"));
}
bool DaqDeviceManager::isDaqDeviceSupported(int productId)
@ -132,7 +155,7 @@ DaqDevice* DaqDeviceManager::getActualDeviceHandle(long long deviceNumber)
return daqDevice;
}
DaqDevice* DaqDeviceManager::getDaqDevice(DaqDeviceDescriptor daqDeviceDescriptor)
DaqDevice* DaqDeviceManager::getDaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor)
{
DaqDevice *daqDevice = NULL;

View File

@ -31,7 +31,7 @@ public:
static void releaseDevice(long long deviceNumber);
static void releaseDevices();
static DaqDevice* getActualDeviceHandle(long long deviceNumber);
static DaqDevice* getDaqDevice(DaqDeviceDescriptor daqDeviceDescriptor);
static DaqDevice* getDaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor);
private:
static void addSupportedDaqDevice();

View File

@ -286,9 +286,9 @@ void DaqEventHandler::check_DisableEvent_Args(DaqEventType eventTypes)
// throw UlException(ERR_BAD_EVENT_TYPE);
}
int DaqEventHandler::getEventIndex(DaqEventType eventType)
unsigned int DaqEventHandler::getEventIndex(DaqEventType eventType)
{
int index = -1;
int index = 0;
switch(eventType)
{
case DE_ON_DATA_AVAILABLE:
@ -307,8 +307,8 @@ int DaqEventHandler::getEventIndex(DaqEventType eventType)
index = 4;
break;
default:
std::cout << "**** getEventIndex(), Invalid event type specified";
break;
}
return index;
}

View File

@ -44,7 +44,7 @@ private:
static void* eventThread(void* arg);
void waitForEvent();
int getEventIndex(DaqEventType eventType);
unsigned int getEventIndex(DaqEventType eventType);
void addEnabledEvents(DaqEventType eventTypes, unsigned long long eventParameter, DaqEventCallback eventCalbackFunc, void* userData);
void getCurrentEventsAndData(DaqEvent* daqEvents, int& eventCount);

View File

@ -26,4 +26,24 @@ unsigned long long DioConfig::getPortDirectionMask(int portNum)
return mDioDevice.getCfg_PortDirectionMask(portNum);
}
void DioConfig::setPortInitialOutputVal(int portNum, unsigned long long val)
{
mDioDevice.setCfg_PortInitialOutputVal(portNum, val);
}
void DioConfig::setPortIsoMask(int portNum, unsigned long long mask)
{
mDioDevice.setCfg_PortIsoMask(portNum, mask);
}
unsigned long long DioConfig::getPortIsoMask(int portNum)
{
return mDioDevice.getCfg_PortIsoMask(portNum);
}
unsigned long long DioConfig::getPortLogic(int portNum)
{
return mDioDevice.getCfg_PortLogic(portNum);
}
} /* namespace ul */

View File

@ -21,6 +21,12 @@ public:
virtual unsigned long long getPortDirectionMask(int portNum);
virtual void setPortInitialOutputVal(int portNum, unsigned long long val);
virtual void setPortIsoMask(int portNum, unsigned long long mask);
virtual unsigned long long getPortIsoMask(int portNum);
virtual unsigned long long getPortLogic(int portNum);
private:
DioDevice& mDioDevice;
};

View File

@ -25,7 +25,6 @@ DioDevice::DioDevice(const DaqDevice& daqDevice) : IoDevice(daqDevice), UlDioDev
memset(&mDoTrigCfg, 0, sizeof(mDoTrigCfg));
mDoTrigCfg.type = TRIG_POS_EDGE;
}
DioDevice::~DioDevice()
@ -58,6 +57,37 @@ void DioDevice::dOut(DigitalPortType portType, unsigned long long data)
throw UlException(ERR_BAD_DEV_TYPE);
}
void DioDevice::dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DInArray_Args(lowPort, highPort, data);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <=highPortNum; portNum++)
{
data[i] = dIn(mDioInfo.getPortType(portNum));
i++;
}
}
void DioDevice::dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DOutArray_Args(lowPort, highPort, data);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
dOut(mDioInfo.getPortType(portNum), data[i]);
i++;
}
}
bool DioDevice::dBitIn(DigitalPortType portType, int bitNum)
{
throw UlException(ERR_BAD_DEV_TYPE);
@ -181,7 +211,7 @@ void DioDevice::check_DConfigBit_Args(DigitalPortType portType, int bitNum, Digi
if(mDioInfo.isPortSupported(portType) == false)
throw UlException(ERR_BAD_PORT_TYPE);
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
int bitCount = mDioInfo.getNumBits(portNum);
if(bitCount <= bitNum)
@ -196,7 +226,7 @@ void DioDevice::check_DIn_Args(DigitalPortType portType)
if(mDioInfo.isPortSupported(portType) == false)
throw UlException(ERR_BAD_PORT_TYPE);
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
DigitalPortIoType ioType = mDioInfo.getPortIoType(portNum);
if(ioType == DPIOT_OUT)
@ -211,13 +241,13 @@ void DioDevice::check_DOut_Args(DigitalPortType portType, unsigned long long dat
if(mDioInfo.isPortSupported(portType) == false)
throw UlException(ERR_BAD_PORT_TYPE);
int portNum = mDioInfo.getPortNum(portType);
int bitCount = mDioInfo.getNumBits(portNum);
unsigned int portNum = mDioInfo.getPortNum(portType);
unsigned int bitCount = mDioInfo.getNumBits(portNum);
DigitalPortIoType ioType = mDioInfo.getPortIoType(portNum);
if(ioType == DPIOT_IN)
throw UlException(ERR_WRONG_DIG_CONFIG);
throw UlException(ERR_BAD_DIG_OPERATION);
else if((ioType == DPIOT_IO || ioType == DPIOT_BITIO) && !mDisableCheckDirection)
{
if(mPortDirectionMask[portNum].any())
@ -233,16 +263,84 @@ void DioDevice::check_DOut_Args(DigitalPortType portType, unsigned long long dat
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void DioDevice::check_DInArray_Args(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
if(!mDioInfo.isPortSupported(lowPort) || !mDioInfo.isPortSupported(highPort))
throw UlException(ERR_BAD_PORT_TYPE);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
if(lowPortNum > highPortNum )
throw UlException(ERR_BAD_PORT_TYPE);
for(unsigned int portNum = lowPortNum; portNum <=highPortNum; portNum++)
{
if(mDioInfo.getPortIoType(portNum) == DPIOT_OUT)
throw UlException(ERR_WRONG_DIG_CONFIG);
}
if(data == NULL)
throw UlException(ERR_BAD_BUFFER);
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void DioDevice::check_DOutArray_Args(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
if(!mDioInfo.isPortSupported(lowPort) || !mDioInfo.isPortSupported(highPort))
throw UlException(ERR_BAD_PORT_TYPE);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
if(lowPortNum > highPortNum )
throw UlException(ERR_BAD_PORT_TYPE);
if(data == NULL)
throw UlException(ERR_BAD_BUFFER);
DigitalPortIoType ioType;
int bitCount;
unsigned long maxVal;
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <=highPortNum; portNum++)
{
ioType = mDioInfo.getPortIoType(portNum);
bitCount = mDioInfo.getNumBits(portNum);
if(ioType == DPIOT_IN)
throw UlException(ERR_BAD_DIG_OPERATION);
else if((ioType == DPIOT_IO || ioType == DPIOT_BITIO) && !mDisableCheckDirection)
{
if(mPortDirectionMask[portNum].any())
throw UlException(ERR_WRONG_DIG_CONFIG);
}
maxVal = (1 << bitCount) - 1;
if(data[i] > maxVal)
throw UlException(ERR_BAD_PORT_VAL);
i++;
}
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
}
void DioDevice::check_DBitIn_Args(DigitalPortType portType, int bitNum)
{
if(mDioInfo.isPortSupported(portType) == false)
throw UlException(ERR_BAD_PORT_TYPE);
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
int bitCount = mDioInfo.getNumBits(portNum);
if(bitNum < 0 || bitNum >= bitCount)
if(bitNum >= bitCount)
throw UlException(ERR_BAD_BIT_NUM);
if(!mDaqDevice.isConnected())
@ -254,16 +352,16 @@ void DioDevice::check_DBitOut_Args(DigitalPortType portType, int bitNum)
if(mDioInfo.isPortSupported(portType) == false)
throw UlException(ERR_BAD_PORT_TYPE);
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
int bitCount = mDioInfo.getNumBits(portNum);
if(bitNum < 0 || bitNum >= bitCount)
if(bitNum >= bitCount)
throw UlException(ERR_BAD_BIT_NUM);
DigitalPortIoType ioType = mDioInfo.getPortIoType(portNum);
if(ioType == DPIOT_IN)
throw UlException(ERR_WRONG_DIG_CONFIG);
throw UlException(ERR_BAD_DIG_OPERATION);
else if((ioType == DPIOT_IO || ioType == DPIOT_BITIO) && !mDisableCheckDirection)
{
if(mPortDirectionMask[portNum][bitNum])
@ -279,8 +377,8 @@ void DioDevice::check_DInScan_Args(DigitalPortType lowPort, DigitalPortType high
if(!mDioInfo.isPortSupported(lowPort) || !mDioInfo.isPortSupported(highPort))
throw UlException(ERR_BAD_PORT_TYPE);
int lowPortNum = mDioInfo.getPortNum(lowPort);
int highPortNum = mDioInfo.getPortNum(highPort);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int numOfScanPorts = highPortNum - lowPortNum + 1;
@ -296,7 +394,7 @@ void DioDevice::check_DInScan_Args(DigitalPortType lowPort, DigitalPortType high
if(lowPortNum > highPortNum )
throw UlException(ERR_BAD_PORT_TYPE);
for(int portNum = lowPortNum; portNum <=highPortNum; portNum++)
for(unsigned int portNum = lowPortNum; portNum <=highPortNum; portNum++)
{
if(mDioInfo.getPortIoType(portNum) == DPIOT_OUT)
throw UlException(ERR_WRONG_DIG_CONFIG);
@ -334,8 +432,8 @@ void DioDevice::check_DOutScan_Args(DigitalPortType lowPort, DigitalPortType hig
if(!mDioInfo.isPortSupported(lowPort) || !mDioInfo.isPortSupported(highPort))
throw UlException(ERR_BAD_PORT_TYPE);
int lowPortNum = mDioInfo.getPortNum(lowPort);
int highPortNum = mDioInfo.getPortNum(highPort);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int numOfScanPorts = highPortNum - lowPortNum + 1;
@ -352,12 +450,12 @@ void DioDevice::check_DOutScan_Args(DigitalPortType lowPort, DigitalPortType hig
throw UlException(ERR_BAD_PORT_TYPE);
DigitalPortIoType ioType;
for(int portNum = lowPortNum; portNum <=highPortNum; portNum++)
for(unsigned int portNum = lowPortNum; portNum <=highPortNum; portNum++)
{
ioType = mDioInfo.getPortIoType(portNum);
if(ioType == DPIOT_IN)
throw UlException(ERR_WRONG_DIG_CONFIG);
throw UlException(ERR_BAD_DIG_OPERATION);
else if((ioType == DPIOT_IO || ioType == DPIOT_BITIO) && !mDisableCheckDirection)
{
if(mPortDirectionMask[portNum].any())
@ -417,14 +515,14 @@ void DioDevice::check_SetTrigger_Args(ScanDirection direction, TriggerType trigT
std::bitset<32> DioDevice::getPortDirection(DigitalPortType portType) const
{
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
return mPortDirectionMask[portNum];
}
void DioDevice::setPortDirection(DigitalPortType portType, DigitalDirection direction)
{
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
unsigned int bitCount = mDioInfo.getNumBits(portNum);
if(direction == DD_OUTPUT)
@ -438,7 +536,7 @@ void DioDevice::setPortDirection(DigitalPortType portType, DigitalDirection dire
void DioDevice::setBitDirection(DigitalPortType portType, int bitNum, DigitalDirection direction)
{
int portNum = mDioInfo.getPortNum(portType);
unsigned int portNum = mDioInfo.getPortNum(portType);
if(direction == DD_OUTPUT)
mPortDirectionMask[portNum].reset(bitNum);
@ -512,14 +610,62 @@ unsigned long long DioDevice::getCfg_PortDirectionMask(unsigned int portNum) con
DigitalPortType portType = mDioInfo.getPortType(portNum);
std::bitset<32> bitsetMask = getPortDirection(portType);
int portNum = mDioInfo.getPortNum(portType);
int bitCount = mDioInfo.getNumBits(portNum);
unsigned int portNum = mDioInfo.getPortNum(portType);
unsigned int bitCount = mDioInfo.getNumBits(portNum);
unsigned long long bits = (1ULL << bitCount) - 1;
dirMask = bitsetMask.flip().to_ulong() & bits;
}
else
throw UlException(ERR_BAD_PORT_INDEX);
return dirMask;
}
void DioDevice::setCfg_PortInitialOutputVal(unsigned int portNum, unsigned long long val)
{
DigitalPortType portType = mDioInfo.getPortType(portNum);
if(portType)
{
DigitalPortIoType portIoType = mDioInfo.getPortIoType(portNum);
if(portIoType == DPIOT_IO || portIoType == DPIOT_BITIO)
{
bool currenState = mDisableCheckDirection;
mDisableCheckDirection = true;
try
{
dOut(portType, val);
}
catch(UlException& e)
{
throw UlException(e.getError());
}
mDisableCheckDirection = currenState;
}
else
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
else
throw UlException(ERR_BAD_PORT_INDEX);
}
void DioDevice::setCfg_PortIsoMask(unsigned int portNum, unsigned long long mask)
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
unsigned long long DioDevice::getCfg_PortIsoMask(unsigned int portNum)
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
unsigned long long DioDevice::getCfg_PortLogic(unsigned int portNum)
{
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
}
} /* namespace ul */

View File

@ -32,6 +32,8 @@ public:
virtual void dConfigBit(DigitalPortType portType, int bitNum, DigitalDirection direction);
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual void dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual void dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
@ -59,8 +61,14 @@ public:
virtual UlError dOutGetStatus(ScanStatus* status, TransferStatus* xferStatus);
virtual void dInStopBackground();
virtual void dOutStopBackground();
////////////////////// Configuration functions /////////////////////////////////
virtual unsigned long long getCfg_PortDirectionMask(unsigned int portNum) const;
virtual void setCfg_PortInitialOutputVal(unsigned int portNum, unsigned long long val);
virtual void setCfg_PortIsoMask(unsigned int portNum, unsigned long long mask);
virtual unsigned long long getCfg_PortIsoMask(unsigned int portNum);
virtual unsigned long long getCfg_PortLogic(unsigned int portNum);
protected:
void initPortsDirectionMask();
@ -70,6 +78,8 @@ protected:
void check_DConfigBit_Args(DigitalPortType portType, int bitNum, DigitalDirection direction);
void check_DIn_Args(DigitalPortType portType);
void check_DOut_Args(DigitalPortType portType, unsigned long long data);
void check_DInArray_Args(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
void check_DOutArray_Args(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
void check_DBitIn_Args(DigitalPortType portType, int bitNum);
void check_DBitOut_Args(DigitalPortType portType, int bitNum);
void check_DInScan_Args(DigitalPortType lowPort, DigitalPortType highPort, int samplesPerPort, double rate, ScanOption options, DInScanFlag flags, unsigned long long data[]) const;

View File

@ -301,15 +301,25 @@ bool DioInfo::isPortSupported(DigitalPortType portType) const
{
bool supported = false;
if(getPortNum(portType) != -1)
supported = true;
DigitalPortType type;
for(unsigned int i = 0; i < getNumPorts(); i++)
{
type = getPortType(i);
if(type == portType)
{
supported = true;
break;
}
}
return supported;
}
int DioInfo::getPortNum(DigitalPortType portType) const
unsigned int DioInfo::getPortNum(DigitalPortType portType) const
{
int portIndex = -1;
unsigned int portIndex = 0;
DigitalPortType type;
for(unsigned int i = 0; i < getNumPorts(); i++)

View File

@ -55,7 +55,7 @@ public:
bool supportsTrigger(DigitalDirection direction) const;
bool isPortSupported(DigitalPortType portType) const;
int getPortNum(DigitalPortType portType) const;
unsigned int getPortNum(DigitalPortType portType) const;
private:
std::vector<DioPortInfo> mPortInfo;

View File

@ -84,14 +84,16 @@ void IoDevice::setScanInfo(FunctionType functionType, int chanCount, int samples
mScanInfo.dataBuffer = dataBuffer;
mScanInfo.dataBufferType = dataBufferType;
mScanInfo.fullScale = (1ULL << analogResolution) - 1;
mScanInfo.currentCalCoefIdx = 0;
mScanInfo.currentDataBufferIdx = 0;
mScanInfo.totalSampleTransferred = 0;
mScanInfo.allSamplesTransferred = false;
mScanInfo.dataBufferSize = mScanInfo.chanCount * mScanInfo.samplesPerChanCount;
mScanInfo.stoppingScan = false;
mScanDoneWaitEvent.reset();
UlLock lock(mProcessScanDataMutex);
mScanInfo.currentCalCoefIdx = 0;
mScanInfo.currentDataBufferIdx = 0;
mScanInfo.totalSampleTransferred = 0;
mScanInfo.allSamplesTransferred = false;
}
void IoDevice::setScanInfo(FunctionType functionType, int chanCount, int samplesPerChanCount, int sampleSize, unsigned int analogResolution, ScanOption options, long long flags, std::vector<CalCoef> calCoefs, void* dataBuffer)
{
@ -112,23 +114,26 @@ void IoDevice::getXferStatus(TransferStatus* xferStatus) const
}
else
{
unsigned long long count = mScanInfo.totalSampleTransferred; // return current sample count
unsigned long long idx = -1;
//unsigned long long count = mScanInfo.totalSampleTransferred; // return current sample count
//unsigned long long idx = -1;
if(mScanInfo.chanCount > 0 && count >= mScanInfo.chanCount)
if(mScanInfo.chanCount > 0 && mScanInfo.totalSampleTransferred >= mScanInfo.chanCount)
{
idx = count;
unsigned long long idx = mScanInfo.totalSampleTransferred;
idx -= (idx % mScanInfo.chanCount);
idx -= mScanInfo.chanCount;
idx = idx % mScanInfo.dataBufferSize;
}
xferStatus->currentIndex = idx;
xferStatus->currentTotalCount = count;
xferStatus->currentScanCount = count / mScanInfo.chanCount;
xferStatus->currentIndex = idx;
xferStatus->currentTotalCount = mScanInfo.totalSampleTransferred;
xferStatus->currentScanCount = mScanInfo.totalSampleTransferred / mScanInfo.chanCount;
}
else
{
xferStatus->currentIndex = -1;
xferStatus->currentTotalCount = mScanInfo.totalSampleTransferred;
xferStatus->currentScanCount = 0;
}
}
}
/*

View File

@ -5,7 +5,7 @@ AM_CPPFLAGS = -DDEBUG
endif
lib_LTLIBRARIES = libuldaq.la
libuldaq_la_SOURCES = CtrInfo.cpp DaqODevice.h TmrDevice.h DioPortInfo.cpp UlDaqDeviceManager.cpp AoInfo.h ulc.cpp DaqEventHandler.h UlException.cpp CtrDevice.cpp DaqDevice.h main.cpp DaqDevice.cpp TmrInfo.cpp DaqDeviceManager.h TmrInfo.h AiConfig.cpp AoInfo.cpp UlException.h DaqODevice.cpp AoConfig.cpp DaqEvent.h AiDevice.h AiInfo.cpp DaqIInfo.cpp DaqEventHandler.cpp DaqDeviceConfig.cpp CtrDevice.h DaqDeviceConfig.h DaqIDevice.cpp AiChanInfo.cpp DaqDeviceManager.cpp AiInfo.h AoDevice.h DioPortInfo.h DioInfo.h UlDaqDeviceManager.h AoConfig.h AiChanInfo.h DioDevice.h DaqDeviceInfo.cpp CtrInfo.h DaqOInfo.cpp DaqOInfo.h DioInfo.cpp MemRegionInfo.h DaqIInfo.h AiDevice.cpp DevMemInfo.h DaqDeviceInfo.h DioConfig.cpp DaqDeviceId.h IoDevice.cpp interfaces/UlAiConfig.h interfaces/UlDioPortInfo.h interfaces/UlAiInfo.h interfaces/UlDioConfig.h interfaces/UlDaqDevice.h interfaces/UlTmrDevice.h interfaces/UlDaqODevice.h interfaces/UlDaqDeviceInfo.h interfaces/UlDaqDeviceConfig.h interfaces/UlCtrDevice.h interfaces/UlDevMemInfo.h interfaces/UlDioDevice.h interfaces/UlDaqOInfo.h interfaces/UlTmrInfo.h interfaces/UlDaqIDevice.h interfaces/UlAiDevice.h interfaces/UlAoDevice.h interfaces/UlMemRegionInfo.h interfaces/UlDaqIInfo.h interfaces/UlAoInfo.h interfaces/UlAoConfig.h interfaces/UlDioInfo.h interfaces/UlCtrInfo.h interfaces/UlAiChanInfo.h DevMemInfo.cpp AoDevice.cpp ul_internal.h DioConfig.h DioDevice.cpp usb/Usb1608g.cpp usb/UsbFpgaDevice.h usb/ctr/CtrUsbCtrx.cpp usb/ctr/CtrUsb1208hs.h usb/ctr/CtrUsbCtrx.h usb/ctr/CtrUsb1208hs.cpp usb/ctr/CtrUsbBase.cpp usb/ctr/CtrUsb1808.cpp usb/ctr/CtrUsb1808.h usb/ctr/CtrUsbBase.h usb/Usb1608fsPlus.cpp usb/tmr/TmrUsb1208hs.cpp usb/tmr/TmrUsb1208hs.h usb/tmr/TmrUsbBase.cpp usb/tmr/TmrUsbBase.h usb/tmr/TmrUsb1808.h usb/tmr/TmrUsb1808.cpp usb/UsbDio32hs.h usb/UsbDio32hs.cpp usb/Usb20x.h usb/UsbDaqDevice.h usb/dio/DioUsb1608g.cpp usb/dio/DioUsb1208fsPlus.cpp usb/dio/DioUsb1608g.h usb/dio/DioUsbDio32hs.h usb/dio/UsbDOutScan.h usb/dio/DioUsbBase.cpp usb/dio/DioUsbDio32hs.cpp usb/dio/DioUsb26xx.cpp usb/dio/DioUsbBase.h usb/dio/DioUsb1208hs.cpp usb/dio/UsbDOutScan.cpp usb/dio/UsbDInScan.h usb/dio/DioUsbCtrx.cpp usb/dio/DioUsb1208fsPlus.h usb/dio/DioUsb1208hs.h usb/dio/UsbDInScan.cpp usb/dio/DioUsbCtrx.h usb/dio/DioUsb1808.h usb/dio/DioUsb1808.cpp usb/dio/DioUsb26xx.h usb/Usb1608fsPlus.h usb/Usb1208fsPlus.cpp usb/daqi/DaqIUsb1808.cpp usb/daqi/DaqIUsbBase.h usb/daqi/DaqIUsb1808.h usb/daqi/DaqIUsbCtrx.cpp usb/daqi/DaqIUsbBase.cpp usb/daqi/DaqIUsbCtrx.h usb/Usb1808.h usb/Usb26xx.h usb/ai/AiUsb1208hs.h usb/ai/AiUsb1608g.cpp usb/ai/AiUsb1808.h usb/ai/AiUsb1608fsPlus.h usb/ai/AiUsb1808.cpp usb/ai/AiUsbBase.cpp usb/ai/AiUsb26xx.cpp usb/ai/AiUsb1208hs.cpp usb/ai/AiUsb1608g.h usb/ai/AiUsb1608fsPlus.cpp usb/ai/AiUsbBase.h usb/ai/AiUsb1208fsPlus.h usb/ai/AiUsb1208fsPlus.cpp usb/ai/AiUsb20x.cpp usb/ai/AiUsb20x.h usb/ai/AiUsb26xx.h usb/UsbEndpoint.h usb/ao/AoUsb26xx.h usb/ao/AoUsb20x.cpp usb/ao/AoUsb1608g.cpp usb/ao/AoUsb1208hs.h usb/ao/AoUsb1808.h usb/ao/AoUsb26xx.cpp usb/ao/AoUsbBase.h usb/ao/AoUsb1208fsPlus.h usb/ao/AoUsbBase.cpp usb/ao/AoUsb1808.cpp usb/ao/AoUsb20x.h usb/ao/AoUsb1208fsPlus.cpp usb/ao/AoUsb1208hs.cpp usb/ao/AoUsb1608g.h usb/daqo/DaqOUsbBase.h usb/daqo/DaqOUsb1808.h usb/daqo/DaqOUsb1808.cpp usb/daqo/DaqOUsbBase.cpp usb/Usb1608g.h usb/Usb1208hs.h usb/Usb20x.cpp usb/UsbEndpoint.cpp usb/UsbScanTransferOut.cpp usb/UsbScanTransferIn.h usb/Usb1208fsPlus.h usb/Usb1208hs.cpp usb/Usb1808.cpp usb/UsbDaqDevice.cpp usb/UsbScanTransferIn.cpp usb/UsbCtrx.cpp usb/UsbCtrx.h usb/Usb26xx.cpp usb/UsbScanTransferOut.h usb/UsbFpgaDevice.cpp utility/ErrorMap.cpp utility/ThreadEvent.cpp utility/UlLock.cpp utility/Endian.cpp utility/EuScale.h utility/FnLog.h utility/Nist.cpp utility/Endian.h utility/EuScale.cpp utility/ErrorMap.h utility/Nist.h utility/SuspendMonitor.cpp utility/FnLog.cpp utility/ThreadEvent.h utility/SuspendMonitor.h utility/UlLock.h IoDevice.h uldaq.h TmrDevice.cpp AiConfig.h DaqIDevice.h
libuldaq_la_SOURCES = CtrInfo.cpp DaqODevice.h TmrDevice.h DioPortInfo.cpp UlDaqDeviceManager.cpp AoInfo.h ulc.cpp DaqEventHandler.h UlException.cpp CtrDevice.cpp DaqDevice.h main.cpp DaqDevice.cpp TmrInfo.cpp DaqDeviceManager.h TmrInfo.h AiConfig.cpp AoInfo.cpp UlException.h DaqODevice.cpp AoConfig.cpp hid/hid_mac.cpp hid/HidDaqDevice.cpp hid/ctr/CtrHid.h hid/ctr/CtrUsbDio24.cpp hid/ctr/CtrHid.cpp hid/ctr/CtrHidBase.h hid/ctr/CtrUsbDio24.h hid/ctr/CtrHidBase.cpp hid/UsbDio96h.cpp hid/dio/DioUsbDio96h.h hid/dio/DioHidBase.cpp hid/dio/DioHidAux.h hid/dio/DioHidAux.cpp hid/dio/DioUsbSsrxx.h hid/dio/DioUsbDio24.h hid/dio/DioUsbDio96h.cpp hid/dio/DioUsbSsrxx.cpp hid/dio/DioUsbErbxx.cpp hid/dio/DioUsbPdiso8.cpp hid/dio/DioUsbDio24.cpp hid/dio/DioUsbPdiso8.h hid/dio/DioHidBase.h hid/dio/DioUsbErbxx.h hid/UsbDio24.h hid/UsbTempAi.cpp hid/UsbTemp.h hid/UsbDio96h.h hid/Usb3100.cpp hid/ai/AiUsbTempAi.h hid/ai/AiUsbTemp.h hid/ai/AiUsbTemp.cpp hid/ai/AiUsbTempAi.cpp hid/ai/AiHidBase.cpp hid/ai/AiHidBase.h hid/hidapi.h hid/UsbSsrxx.h hid/ao/AoHidBase.h hid/ao/AoHidBase.cpp hid/ao/AoUsb3100.h hid/ao/AoUsb3100.cpp hid/UsbTemp.cpp hid/UsbPdiso8.cpp hid/hid_linux.cpp hid/UsbSsrxx.cpp hid/UsbErbxx.cpp hid/UsbErbxx.h hid/UsbPdiso8.h hid/UsbTempAi.h hid/UsbDio24.cpp hid/Usb3100.h hid/HidDaqDevice.h DaqEvent.h AiDevice.h AiInfo.cpp DaqIInfo.cpp DaqEventHandler.cpp DaqDeviceConfig.cpp CtrDevice.h DaqDeviceConfig.h DaqIDevice.cpp AiChanInfo.cpp DaqDeviceManager.cpp AiInfo.h AoDevice.h DioPortInfo.h DioInfo.h UlDaqDeviceManager.h AoConfig.h AiChanInfo.h DioDevice.h DaqDeviceInfo.cpp CtrInfo.h DaqOInfo.cpp DaqOInfo.h DioInfo.cpp MemRegionInfo.h DaqIInfo.h AiDevice.cpp DevMemInfo.h DaqDeviceInfo.h DioConfig.cpp DaqDeviceId.h IoDevice.cpp interfaces/UlAiConfig.h interfaces/UlDioPortInfo.h interfaces/UlAiInfo.h interfaces/UlDioConfig.h interfaces/UlDaqDevice.h interfaces/UlTmrDevice.h interfaces/UlDaqODevice.h interfaces/UlDaqDeviceInfo.h interfaces/UlDaqDeviceConfig.h interfaces/UlCtrDevice.h interfaces/UlDevMemInfo.h interfaces/UlDioDevice.h interfaces/UlDaqOInfo.h interfaces/UlTmrInfo.h interfaces/UlDaqIDevice.h interfaces/UlAiDevice.h interfaces/UlAoDevice.h interfaces/UlMemRegionInfo.h interfaces/UlDaqIInfo.h interfaces/UlAoInfo.h interfaces/UlAoConfig.h interfaces/UlDioInfo.h interfaces/UlCtrInfo.h interfaces/UlAiChanInfo.h DevMemInfo.cpp AoDevice.cpp ul_internal.h DioConfig.h DioDevice.cpp usb/Usb1608g.cpp usb/UsbFpgaDevice.h usb/ctr/CtrUsbCtrx.cpp usb/ctr/CtrUsb1208hs.h usb/ctr/CtrUsbCtrx.h usb/ctr/CtrUsb1208hs.cpp usb/ctr/CtrUsbBase.cpp usb/ctr/CtrUsb1808.cpp usb/ctr/CtrUsb1808.h usb/ctr/CtrUsbBase.h usb/Usb1608fsPlus.cpp usb/tmr/TmrUsb1208hs.cpp usb/tmr/TmrUsb1208hs.h usb/tmr/TmrUsbBase.cpp usb/tmr/TmrUsbBase.h usb/tmr/TmrUsb1808.h usb/tmr/TmrUsb1808.cpp usb/UsbDio32hs.h usb/UsbDio32hs.cpp usb/Usb20x.h usb/UsbDaqDevice.h usb/dio/DioUsb1608g.cpp usb/dio/DioUsb1208fsPlus.cpp usb/dio/DioUsb1608g.h usb/dio/DioUsbDio32hs.h usb/dio/UsbDOutScan.h usb/dio/DioUsbBase.cpp usb/dio/DioUsbDio32hs.cpp usb/dio/DioUsb26xx.cpp usb/dio/DioUsbBase.h usb/dio/DioUsb1208hs.cpp usb/dio/UsbDOutScan.cpp usb/dio/UsbDInScan.h usb/dio/DioUsbCtrx.cpp usb/dio/DioUsb1208fsPlus.h usb/dio/DioUsb1208hs.h usb/dio/UsbDInScan.cpp usb/dio/DioUsbCtrx.h usb/dio/DioUsb1808.h usb/dio/DioUsb1808.cpp usb/dio/DioUsb26xx.h usb/Usb1608fsPlus.h usb/Usb1208fsPlus.cpp usb/daqi/DaqIUsb1808.cpp usb/daqi/DaqIUsbBase.h usb/daqi/DaqIUsb1808.h usb/daqi/DaqIUsbCtrx.cpp usb/daqi/DaqIUsbBase.cpp usb/daqi/DaqIUsbCtrx.h usb/Usb1808.h usb/Usb26xx.h usb/ai/AiUsb1208hs.h usb/ai/AiUsb1608g.cpp usb/ai/AiUsb1808.h usb/ai/AiUsb1608fsPlus.h usb/ai/AiUsb1808.cpp usb/ai/AiUsbBase.cpp usb/ai/AiUsb26xx.cpp usb/ai/AiUsb1208hs.cpp usb/ai/AiUsb1608g.h usb/ai/AiUsb1608fsPlus.cpp usb/ai/AiUsbBase.h usb/ai/AiUsb1208fsPlus.h usb/ai/AiUsb1208fsPlus.cpp usb/ai/AiUsb20x.cpp usb/ai/AiUsb20x.h usb/ai/AiUsb26xx.h usb/UsbEndpoint.h usb/ao/AoUsb26xx.h usb/ao/AoUsb20x.cpp usb/ao/AoUsb1608g.cpp usb/ao/AoUsb1208hs.h usb/ao/AoUsb1808.h usb/ao/AoUsb26xx.cpp usb/ao/AoUsbBase.h usb/ao/AoUsb1208fsPlus.h usb/ao/AoUsbBase.cpp usb/ao/AoUsb1808.cpp usb/ao/AoUsb20x.h usb/ao/AoUsb1208fsPlus.cpp usb/ao/AoUsb1208hs.cpp usb/ao/AoUsb1608g.h usb/daqo/DaqOUsbBase.h usb/daqo/DaqOUsb1808.h usb/daqo/DaqOUsb1808.cpp usb/daqo/DaqOUsbBase.cpp usb/Usb1608g.h usb/Usb1208hs.h usb/Usb20x.cpp usb/UsbEndpoint.cpp usb/UsbScanTransferOut.cpp usb/UsbScanTransferIn.h usb/Usb1208fsPlus.h usb/Usb1208hs.cpp usb/Usb1808.cpp usb/UsbDaqDevice.cpp usb/UsbScanTransferIn.cpp usb/UsbCtrx.cpp usb/UsbCtrx.h usb/Usb26xx.cpp usb/UsbScanTransferOut.h usb/UsbFpgaDevice.cpp utility/ErrorMap.cpp utility/ThreadEvent.cpp utility/UlLock.cpp utility/Endian.cpp utility/EuScale.h utility/FnLog.h utility/Nist.cpp utility/Endian.h utility/EuScale.cpp utility/ErrorMap.h utility/Nist.h utility/SuspendMonitor.cpp utility/FnLog.cpp utility/ThreadEvent.h utility/SuspendMonitor.h utility/UlLock.h IoDevice.h uldaq.h TmrDevice.cpp AiConfig.h DaqIDevice.h
libuldaq_la_LDFLAGS = $(LTLDFLAGS)

View File

@ -9,7 +9,7 @@
#include "DaqDeviceId.h"
#include "DaqDeviceManager.h"
#include "./usb/UsbDaqDevice.h"
//#include "./hid/HidDaqDevice.h"
#include "./hid/HidDaqDevice.h"
#include "./usb/Usb1208fsPlus.h"
#include "./usb/Usb1608fsPlus.h"
#include "./usb/Usb20x.h"
@ -20,7 +20,14 @@
#include "./usb/Usb26xx.h"
#include "./usb/UsbDio32hs.h"
#include "./usb/UsbCtrx.h"
//#include "./hid/UsbTc.h"
#include "./hid/UsbDio96h.h"
#include "./hid/UsbDio24.h"
#include "./hid/UsbPdiso8.h"
#include "./hid/UsbSsrxx.h"
#include "./hid/UsbErbxx.h"
#include "./hid/Usb3100.h"
#include "./hid/UsbTemp.h"
#include "./hid/UsbTempAi.h"
#include <iostream>
#include <cstring>
@ -48,18 +55,18 @@ std::vector<DaqDeviceDescriptor> UlDaqDeviceManager::getDaqDeviceInventory(DaqDe
std::vector<DaqDeviceDescriptor> usbDaqDeviceList = UsbDaqDevice::findDaqDevices();
//std::vector<DaqDeviceDescriptor> hidDaqDeviceList = HidDaqDevice::findDaqDevices();
std::vector<DaqDeviceDescriptor> hidDaqDeviceList = HidDaqDevice::findDaqDevices();
for(unsigned int i = 0; i < usbDaqDeviceList.size(); i++)
daqDeviceList.push_back(usbDaqDeviceList[i]);
/*for(unsigned int i = 0; i < hidDaqDeviceList.size(); i++)
daqDeviceList.push_back(hidDaqDeviceList[i]);*/
for(unsigned int i = 0; i < hidDaqDeviceList.size(); i++)
daqDeviceList.push_back(hidDaqDeviceList[i]);
return daqDeviceList;
}
UlDaqDevice& UlDaqDeviceManager::createDaqDevice(DaqDeviceDescriptor daqDevDescriptor)
UlDaqDevice& UlDaqDeviceManager::createDaqDevice(const DaqDeviceDescriptor& daqDevDescriptor)
{
DaqDevice* daqDev = DaqDeviceManager::getDaqDevice(daqDevDescriptor); // Don't recreate a new DaqDevice object if it already exists for the specified descriptor
@ -123,9 +130,53 @@ UlDaqDevice& UlDaqDeviceManager::createDaqDevice(DaqDeviceDescriptor daqDevDescr
daqDev = new UsbCtrx(daqDevDescriptor, "USB_CTR.bin");
break;
/*case DaqDeviceId::USB_TC:
daqDev = new UsbTc(daqDevDescriptor);
break;*/
case DaqDeviceId::USB_DIO96H:
case DaqDeviceId::USB_DIO96H_50:
daqDev = new UsbDio96h(daqDevDescriptor);
break;
case DaqDeviceId::USB_1024LS:
case DaqDeviceId::USB_1024HLS:
case DaqDeviceId::USB_DIO24:
case DaqDeviceId::USB_DIO24H:
daqDev = new UsbDio24(daqDevDescriptor);
break;
case DaqDeviceId::USB_PDISO8:
case DaqDeviceId::USB_PDISO8_40:
daqDev = new UsbPdiso8(daqDevDescriptor);
break;
case DaqDeviceId::USB_SSR24:
case DaqDeviceId::USB_SSR08:
daqDev = new UsbSsrxx(daqDevDescriptor);
break;
case DaqDeviceId::USB_ERB24:
case DaqDeviceId::USB_ERB08:
daqDev = new UsbErbxx(daqDevDescriptor);
break;
case DaqDeviceId::USB_3101:
case DaqDeviceId::USB_3102:
case DaqDeviceId::USB_3103:
case DaqDeviceId::USB_3104:
case DaqDeviceId::USB_3105:
case DaqDeviceId::USB_3106:
case DaqDeviceId::USB_3110:
case DaqDeviceId::USB_3112:
case DaqDeviceId::USB_3114:
daqDev = new Usb3100(daqDevDescriptor);
break;
case DaqDeviceId::USB_TEMP:
case DaqDeviceId::USB_TC:
daqDev = new UsbTemp(daqDevDescriptor);
break;
case DaqDeviceId::USB_TEMP_AI:
case DaqDeviceId::USB_TC_AI:
daqDev = new UsbTempAi(daqDevDescriptor);
break;
}
if(daqDev)

View File

@ -23,7 +23,7 @@ public:
virtual ~UlDaqDeviceManager();
static std::vector<DaqDeviceDescriptor> getDaqDeviceInventory(DaqDeviceInterface InterfaceType);
static UlDaqDevice& createDaqDevice(DaqDeviceDescriptor daqDevDescriptor);
static UlDaqDevice& createDaqDevice(const DaqDeviceDescriptor& daqDevDescriptor);
static void releaseDaqDevice(UlDaqDevice& daqDevice);
};

783
src/hid/HidDaqDevice.cpp Normal file
View File

@ -0,0 +1,783 @@
/*
* HidDaqDevice.cpp
*
* Author: Measurement Computing Corporation
*/
#include "HidDaqDevice.h"
#include "../DaqDeviceManager.h"
#include "../utility/Endian.h"
#include <stdlib.h>
#define NO_PERMISSION_STR "NO PERMISSION"
namespace ul
{
bool HidDaqDevice::mInitialized = false;
HidDaqDevice::HidDaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor) : DaqDevice(daqDeviceDescriptor)
{
FnLog log("HidDaqDevice::HidDaqDevice");
mDevHandle = NULL;
mConnected = false;
UlLock::initMutex(mConnectionMutex, PTHREAD_MUTEX_RECURSIVE);
UlLock::initMutex(mIoMutex, PTHREAD_MUTEX_RECURSIVE);
}
HidDaqDevice::~HidDaqDevice()
{
FnLog log("HidDaqDevice::~HidDaqDevice");
disconnect();
UlLock::destroyMutex(mIoMutex);
UlLock::destroyMutex(mConnectionMutex);
}
void HidDaqDevice::hidapi_init()
{
if(!mInitialized)
{
int status = hid_init();
if(status != 0)
{
UL_LOG("hid_init() failed");
}
else
mInitialized = true;
}
}
void HidDaqDevice::hidapi_exit()
{
if(mInitialized)
{
hid_exit();
mInitialized = false;
}
}
std::vector<DaqDeviceDescriptor> HidDaqDevice::findDaqDevices()
{
std::vector<DaqDeviceDescriptor> descriptorList;
FnLog log("HidDaqDevice::getDaqDeviceDescriptorList");
struct hid_device_info *devs, *cur_dev;
// Flush the input pipe of all mcc hid devices attached to the host
// If the input pipe's buffer was not emptied for any reason, i.e, application crash or SIGINT
// then sending setup request during device discovery will cause the device to hang
hid_flush_input_pipe(MCC_USB_VID);
devs = hid_enumerate(MCC_USB_VID, 0x0);
cur_dev = devs;
while (cur_dev)
{
if(DaqDeviceManager::isDaqDeviceSupported(cur_dev->product_id))
{
DaqDeviceDescriptor daqDevDescriptor;
memset(&daqDevDescriptor, 0,sizeof(DaqDeviceDescriptor));
daqDevDescriptor.productId = cur_dev->product_id;
daqDevDescriptor.devInterface = USB_IFC;
std::string productName = DaqDeviceManager::getDeviceName(cur_dev->product_id);
strncpy(daqDevDescriptor.productName, productName.c_str(), sizeof(daqDevDescriptor.productName) - 1);
strncpy(daqDevDescriptor.devString, productName.c_str(), sizeof(daqDevDescriptor.devString) - 1);
if(cur_dev->serial_number)
{
if(wcslen(cur_dev->serial_number))
{
char serial[128] = {0};
wcstombs(serial,cur_dev->serial_number, sizeof(serial));
strcpy(daqDevDescriptor.uniqueId, serial);
}
else
strcpy(daqDevDescriptor.uniqueId, NO_PERMISSION_STR);
}
UL_LOG("-----------------------");
UL_LOG("Product ID : 0x" << std::hex << daqDevDescriptor.productId << std::dec);
UL_LOG("Product Name: "<< daqDevDescriptor.productName);
UL_LOG("Serial Number : "<< daqDevDescriptor.uniqueId);
UL_LOG("-----------------------");
descriptorList.push_back(daqDevDescriptor);
/*printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number);
printf("\n");
printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string);
printf(" Product: %ls\n", cur_dev->product_string);
printf(" Release: %hx\n", cur_dev->release_number);
printf(" Interface: %d\n", cur_dev->interface_number);
printf("\n");*/
}
cur_dev = cur_dev->next;
}
hid_free_enumeration(devs);
return descriptorList;
}
void HidDaqDevice::connect()
{
FnLog log("UsbDaqDevice::connect");
UlLock lock(mConnectionMutex);
if(mConnected)
{
UL_LOG("Device is already connected, disconnecting...");
disconnect();
}
establishConnection();
mConnected = true;
//mCurrentSuspendCount = SuspendMonitor::getCurrentSystemSuspendCount();
initilizeHardware();
initializeIoDevices();
}
void HidDaqDevice::disconnect()
{
FnLog log("UsbDaqDevice::disconnect");
if(mConnected)
{
DaqDevice::disconnect();
releaseHidResources();
}
}
void HidDaqDevice::establishConnection()
{
FnLog log("HidDaqDevice::establishConnection");
if(std::strcmp(mDaqDeviceDescriptor.uniqueId, NO_PERMISSION_STR) == 0)
throw UlException(ERR_USB_DEV_NO_PERMISSION);
wchar_t serial[128];
memset(serial, 0, sizeof(serial));
mbstowcs( serial, mDaqDeviceDescriptor.uniqueId, strlen(mDaqDeviceDescriptor.uniqueId));
UlError err = ERR_NO_ERROR;
hid_device_info devInfo;
mDevHandle = hid_open(MCC_USB_VID, mDaqDeviceDescriptor.productId, serial, &devInfo, &err);
if(mDevHandle)
{
mRawFwVersion = devInfo.release_number;
}
else
{
if(err)
throw UlException(err);
else
throw UlException(ERR_DEV_NOT_FOUND);
}
}
void HidDaqDevice::releaseHidResources()
{
FnLog log("UsbDaqDevice::releaseUsbResources");
if(mDevHandle)
{
UlLock lock(mIoMutex);
hid_close(mDevHandle);
mDevHandle = NULL;
}
}
void HidDaqDevice::sendCmd(unsigned char cmd) const
{
size_t outLength = 1;
sendRawCmd(&cmd, &outLength);
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned char param) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param;
}outData;
#pragma pack()
outData.cmd = cmd;
outData.param = param;
size_t outLength = sizeof(outData);
sendRawCmd((unsigned char*) &outData, &outLength);
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned char param1, unsigned char param2) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned char param2;
}outData;
#pragma pack()
outData.cmd = cmd;
outData.param1 = param1;
outData.param2 = param2;
size_t outLength = sizeof(outData);
sendRawCmd((unsigned char*) &outData, &outLength);
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned char param2;
unsigned char param3;
}outData;
#pragma pack()
outData.cmd = cmd;
outData.param1 = param1;
outData.param2 = param2;
outData.param3 = param3;
size_t outLength = sizeof(outData);
sendRawCmd((unsigned char*) &outData, &outLength);
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned char param1, unsigned short param2, unsigned char param3) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned short param2;
unsigned char param3;
}outData;
#pragma pack()
outData.cmd = cmd;
outData.param1 = param1;
outData.param2 = param2;
outData.param3 = param3;
size_t outLength = sizeof(outData);
sendRawCmd((unsigned char*) &outData, &outLength);
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned char* dataBuffer, unsigned int dataBufferSize) const
{
size_t outLength = dataBufferSize + 1;
unsigned char* outData = new unsigned char[outLength];
outData[0] = cmd;
memcpy(&outData[1], dataBuffer, dataBufferSize);
sendRawCmd(outData, &outLength);
delete [] outData;
}
void HidDaqDevice::sendCmd(unsigned char cmd, unsigned short param, unsigned char* dataBuffer, unsigned int dataBufferSize) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned short param;
}outParams;
#pragma pack()
size_t outLength = sizeof(outParams) + dataBufferSize;
unsigned char* outData = new unsigned char[outLength];
outParams.cmd = cmd;
outParams.param = Endian::cpu_to_le_ui16(param);
memcpy(&outData[0], &outParams, sizeof(outParams));
int dataIdx = sizeof(outParams);
memcpy(&outData[dataIdx], dataBuffer, dataBufferSize);
sendRawCmd(outData, &outLength);
delete [] outData;
}
int HidDaqDevice::sendCmd(unsigned char cmd, unsigned short param1, unsigned char param2, unsigned char* dataBuffer, unsigned int dataBufferSize) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned short param1;
unsigned char param2;
}outParams;
#pragma pack()
size_t outLength = sizeof(outParams) + dataBufferSize;
unsigned char* outData = new unsigned char[outLength];
outParams.cmd = cmd;
outParams.param1 = Endian::cpu_to_le_ui16(param1);
outParams.param2 = param2;
memcpy(&outData[0], &outParams, sizeof(outParams));
int dataIdx = sizeof(outParams);
memcpy(&outData[dataIdx], dataBuffer, dataBufferSize);
sendRawCmd(outData, &outLength);
delete [] outData;
int sent = outLength - sizeof(outParams);
return sent;
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned char* data, unsigned int timeout) const
{
size_t outLength = 1;
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char data;
}indata;
#pragma pack()
size_t inLength = sizeof(indata);
queryRawCmd(&cmd, outLength, (unsigned char*) &indata, &inLength, timeout);
*data = indata.data;
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned int* data, unsigned int timeout) const
{
size_t outLength = 1;
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned int data;
}indata;
#pragma pack()
size_t inLength = sizeof(indata);
queryRawCmd(&cmd, outLength, (unsigned char*) &indata, &inLength, timeout);
*data = Endian::le_ui32_to_cpu(indata.data);
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned char param, unsigned char* data, unsigned int timeout) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param;
}outData;
struct
{
unsigned char cmd;
unsigned char data;
}inData;
#pragma pack()
outData.cmd = cmd;
outData.param = param;
size_t outLength = sizeof(outData);
size_t inLength = sizeof(inData);
queryRawCmd((unsigned char*) &outData, outLength, (unsigned char*) &inData, &inLength, timeout);
*data = inData.data;
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char* data, unsigned int timeout) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned char param2;
}outData;
struct
{
unsigned char cmd;
unsigned char data;
}inData;
#pragma pack()
outData.cmd = cmd;
outData.param1 = param1;
outData.param2 = param2;
size_t outLength = sizeof(outData);
size_t inLength = sizeof(inData);
queryRawCmd((unsigned char*) &outData, outLength, (unsigned char*) &inData, &inLength, timeout);
*data = inData.data;
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned short* data, unsigned int timeout) const
{
size_t outLength = 1;
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned short data;
}inData;
#pragma pack()
size_t inLength = sizeof(inData);
queryRawCmd(&cmd, outLength, (unsigned char*) &inData, &inLength, timeout);
*data = Endian::le_ui16_to_cpu(inData.data);
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout) const
{
size_t outLength = 1;
size_t inLength = dataBufferSize + 1;
unsigned char* inData = new unsigned char[inLength];
queryRawCmd(&cmd, outLength, inData, &inLength, timeout);
memcpy(dataBuffer, &inData[1], dataBufferSize);
delete [] inData;
}
unsigned int HidDaqDevice::queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned char param2;
unsigned char param3;
}outData;
#pragma pack()
unsigned int bytesRead = 0;
outData.cmd = cmd;
outData.param1 = Endian::cpu_to_le_ui16(param1);
outData.param2 = param2;
outData.param3 = param3;
size_t outLength = sizeof(outData);
size_t inLength = dataBufferSize + 1;
unsigned char* inData = new unsigned char[inLength];
queryRawCmd((unsigned char*) &outData, outLength, inData, &inLength, timeout);
if(inLength > 0)
{
bytesRead = inLength - 1;
memcpy(dataBuffer, &inData[1], bytesRead);
}
delete [] inData;
return bytesRead;
}
unsigned int HidDaqDevice::queryCmd(unsigned char cmd, unsigned short param1, unsigned char param2, unsigned char param3, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned short param1;
unsigned char param2;
unsigned char param3;
}outData;
#pragma pack()
unsigned int bytesRead = 0;
outData.cmd = cmd;
outData.param1 = Endian::cpu_to_le_ui16(param1);
outData.param2 = param2;
outData.param3 = param3;
size_t outLength = sizeof(outData);
size_t inLength = dataBufferSize + 1;
unsigned char* inData = new unsigned char[inLength];
queryRawCmd((unsigned char*) &outData, outLength, inData, &inLength, timeout);
if(inLength > 0)
{
bytesRead = inLength - 1;
memcpy(dataBuffer, &inData[1], bytesRead);
}
delete [] inData;
return bytesRead;
}
void HidDaqDevice::queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, float* data, unsigned int timeout) const
{
#pragma pack(1)
struct
{
unsigned char cmd;
unsigned char param1;
unsigned char param2;
}outData;
struct
{
unsigned char cmd;
unsigned char data[4];
}inData;
#pragma pack()
outData.cmd = cmd;
outData.param1 = param1;
outData.param2 = param2;
size_t outLength = sizeof(outData);
size_t inLength = sizeof(inData);
queryRawCmd((unsigned char*) &outData, outLength, (unsigned char*) &inData, &inLength, timeout);
*data = Endian::Instance().le_ptr_to_cpu_f32(inData.data);
}
void HidDaqDevice::sendRawCmd(const unsigned char *data, size_t* length) const
{
UlLock lock(mIoMutex);
//size_t len = length;
//int sent = 0;
UlError err = send(data, length);
//sent = len;
if(err)
throw UlException(err);
//return sent;
}
UlError HidDaqDevice::send(const unsigned char *data, size_t* length) const
{
UlError err = ERR_NO_ERROR;
int sent = 0;
if(mConnected)
{
if(mDevHandle)
{
sent = hid_write(mDevHandle, data, *length);
if (sent == -1)
{
UL_LOG("#### hid_write failed");
err = ERR_DEV_NOT_CONNECTED;
}
else
*length = sent;
}
else
err = ERR_DEV_NOT_FOUND;
}
else
err = ERR_NO_CONNECTION_ESTABLISHED;
return err;
}
void HidDaqDevice::queryRawCmd(const unsigned char *outdata, size_t outLength, unsigned char *indata, size_t* inLength, unsigned int timeout) const
{
UlLock lock(mIoMutex);
UlError err = query(outdata, outLength, indata, inLength, timeout);
if(err)
throw UlException(err);
}
UlError HidDaqDevice::query(const unsigned char *outdata, size_t outLength, unsigned char *indata, size_t* inLength, unsigned int timeout) const
{
UlError err = ERR_NO_ERROR;
int sent = 0;
if(mConnected)
{
if(mDevHandle)
{
sent = hid_write(mDevHandle, outdata, outLength);
if(sent == (int) outLength)
{
int received = 0;
received = hid_read_timeout(mDevHandle, indata, *inLength, timeout);
if(received == -1)
{
UL_LOG("#### hid_read failed");
err = ERR_DEV_NOT_CONNECTED;
}
else
{
if (received == 0)
err = ERR_DEAD_DEV;
*inLength = received;
}
}
else if (sent == -1)
{
UL_LOG("#### hid_write failed");
err = ERR_DEV_NOT_CONNECTED;
}
}
else
err = ERR_DEV_NOT_FOUND;
}
else
err = ERR_NO_CONNECTION_ESTABLISHED;
return err;
}
void HidDaqDevice::flashLed(int flashCount) const
{
sendCmd(CMD_FLASH_LED);
}
int HidDaqDevice::memRead(MemoryType memType, MemRegion memRegionType, unsigned int address, unsigned char* buffer, unsigned int count) const
{
check_MemRW_Args(memRegionType, MA_READ, address, buffer, count, false);
unsigned char bytesToRead;
int totalBytesRead = 0;
int bytesRead = 0;
int remaining = count;
if(buffer == NULL)
throw UlException(ERR_BAD_BUFFER);
int maxTransfer = 62;
unsigned char cmd = CMD_MEM_READ;
unsigned char* readBuff = buffer;
unsigned short addr = address;
do
{
bytesToRead = (remaining > maxTransfer ? maxTransfer : remaining);
bytesRead = queryCmd(cmd, addr, 0, bytesToRead, readBuff, bytesToRead);
remaining-= bytesRead;
totalBytesRead += bytesRead;
addr += bytesRead;
readBuff += bytesRead;
}
while(remaining > 0);
return totalBytesRead;
}
int HidDaqDevice::memWrite(MemoryType memType, MemRegion memRegionType, unsigned int address, unsigned char* buffer, unsigned int count) const
{
check_MemRW_Args(memRegionType, MA_WRITE, address, buffer, count, false);
unsigned char bytesToWrite;
int totalBytesWritten = 0;
int bytesWritten = 0;
int bytesRemaining = count;
if(buffer == NULL)
throw UlException(ERR_BAD_BUFFER);
int maxTransfer = 59;
unsigned char cmd = CMD_MEM_WRITE;
unsigned char* writeBuff = buffer;
unsigned short addr = address;
while(bytesRemaining > 0)
{
bytesToWrite = bytesRemaining > maxTransfer ? maxTransfer : bytesRemaining;
bytesWritten = sendCmd(cmd, addr, bytesToWrite, writeBuff, bytesToWrite);
bytesRemaining -= bytesWritten;
totalBytesWritten += bytesWritten;
addr += bytesWritten;
writeBuff += bytesWritten;
}
return totalBytesWritten;
}
} /* namespace ul */

83
src/hid/HidDaqDevice.h Normal file
View File

@ -0,0 +1,83 @@
/*
* HidDaqDevice.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_HIDDAQDEVICE_H_
#define HID_HIDDAQDEVICE_H_
#include <vector>
#include "hidapi.h"
#include "../DaqDevice.h"
#include "../uldaq.h"
#include "../UlException.h"
#include "../utility/UlLock.h"
namespace ul
{
class UL_LOCAL HidDaqDevice: public DaqDevice
{
public:
HidDaqDevice(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~HidDaqDevice();
static void hidapi_init();
static void hidapi_exit();
static std::vector<DaqDeviceDescriptor> findDaqDevices();
virtual void connect();
virtual void disconnect();
void sendCmd(unsigned char cmd) const;
void sendCmd(unsigned char cmd, unsigned char param) const;
void sendCmd(unsigned char cmd, unsigned char param1, unsigned char param2) const;
void sendCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3) const;
void sendCmd(unsigned char cmd, unsigned char param1, unsigned short param2, unsigned char param3) const;
void sendCmd(unsigned char cmd, unsigned char* dataBuffer, unsigned int dataBufferSize) const;
void sendCmd(unsigned char cmd, unsigned short param, unsigned char* dataBuffer, unsigned int dataBufferSize) const;
int sendCmd(unsigned char cmd, unsigned short param1, unsigned char param2, unsigned char* dataBuffer, unsigned int dataBufferSize) const;
void queryCmd(unsigned char cmd, unsigned char* data, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned int* data, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned char param, unsigned char* data, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char* data, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned short* data, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout = 2000) const;
unsigned int queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, unsigned char param3, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout = 2000) const;
unsigned int queryCmd(unsigned char cmd, unsigned short param1, unsigned char param2, unsigned char param3, unsigned char* dataBuffer, unsigned int dataBufferSize, unsigned int timeout = 2000) const;
void queryCmd(unsigned char cmd, unsigned char param1, unsigned char param2, float* data, unsigned int timeout = 2000) const;
void sendRawCmd(const unsigned char *data, size_t* length) const;
void queryRawCmd(const unsigned char *outdata, size_t outLength, unsigned char *indata, size_t* inLength, unsigned int timeout = 2000) const;
virtual void flashLed(int flashCount) const;
int memRead(MemoryType memType, MemRegion memRegionType, unsigned int address, unsigned char* buffer, unsigned int count) const;
int memWrite(MemoryType memType, MemRegion memRegionType, unsigned int address, unsigned char* buffer, unsigned int count) const;
private:
void establishConnection();
virtual void initilizeHardware() const {};
void releaseHidResources();
virtual UlError send(const unsigned char *data, size_t* length) const;
virtual UlError query(const unsigned char *outdata, size_t outLength, unsigned char *indata, size_t* inLength, unsigned int timeout) const;
public:
enum { MCC_USB_VID = 0x09db };
enum { CMD_MEM_READ = 0x30, CMD_MEM_WRITE = 0x31, CMD_FLASH_LED = 0x40 };
private:
hid_device* mDevHandle;
static bool mInitialized;
mutable pthread_mutex_t mConnectionMutex;
mutable pthread_mutex_t mIoMutex;
};
} /* namespace ul */
#endif /* HID_HIDDAQDEVICE_H_ */

35
src/hid/Usb3100.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
* Usb3100.cpp
*
* Author: Measurement Computing Corporation
*/
#include "Usb3100.h"
#include "./ao/AoUsb3100.h"
#include "./dio/DioHidAux.h"
#include "./ctr/CtrHid.h"
namespace ul
{
Usb3100::Usb3100(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setAoDevice(new AoUsb3100(*this));
setDioDevice(new DioHidAux(*this));
setCtrDevice(new CtrHid(*this, 1));
addMemRegion(MR_USER, 0, 256 , MA_READ | MA_WRITE);
addMemRegion(MR_CAL, 0x100, 1024, MA_READ);
}
Usb3100::~Usb3100()
{
}
void Usb3100::flashLed(int flashCount) const
{
sendCmd(CMD_FLASH_LED, (unsigned char) flashCount);
}
} /* namespace ul */

29
src/hid/Usb3100.h Normal file
View File

@ -0,0 +1,29 @@
/*
* Usb3100.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USB3100_H_
#define HID_USB3100_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL Usb3100: public HidDaqDevice
{
public:
Usb3100(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~Usb3100();
virtual void flashLed(int flashCount) const;
private:
enum {CMD_FLASH_LED = 0x40 };
};
} /* namespace ul */
#endif /* HID_USB3100_H_ */

36
src/hid/UsbDio24.cpp Normal file
View File

@ -0,0 +1,36 @@
/*
* UsbDio24.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbDio24.h"
#include "./dio/DioUsbDio24.h"
#include "./ctr/CtrUsbDio24.h"
namespace ul
{
UsbDio24::UsbDio24(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setDioDevice(new DioUsbDio24(*this));
setCtrDevice(new CtrUsbDio24(*this, 1));
}
UsbDio24::~UsbDio24()
{
}
void UsbDio24::flashLed(int flashCount) const
{
unsigned char buffer[MAX_PACKET_SIZE] = {0};
buffer[1] = CMD_FLASH_LED;
size_t length = sizeof(buffer);
sendRawCmd(buffer, &length);
}
} /* namespace ul */

33
src/hid/UsbDio24.h Normal file
View File

@ -0,0 +1,33 @@
/*
* UsbDio24.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBDIO24_H_
#define HID_USBDIO24_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbDio24: public HidDaqDevice
{
public:
UsbDio24(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbDio24();
virtual void flashLed(int flashCount) const;
public:
enum { MAX_PACKET_SIZE = 8 }; // do not set the packet size to 9. if set to 9 on macOS the hid driver sends a packet with no data which causes the device to hang
private:
enum { CMD_FLASH_LED = 0x0B };
};
} /* namespace ul */
#endif /* HID_USBDIO24_H_ */

29
src/hid/UsbDio96h.cpp Normal file
View File

@ -0,0 +1,29 @@
/*
* UsbDio96h.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbDio96h.h"
#include "./dio/DioUsbDio96h.h"
#include "./ctr/CtrHid.h"
namespace ul
{
UsbDio96h::UsbDio96h(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setDioDevice(new DioUsbDio96h(*this));
if(getDeviceType() != DaqDeviceId::USB_DIO96H_50)
setCtrDevice(new CtrHid(*this, 1));
addMemRegion(MR_USER, 0x080, 3968 , MA_READ | MA_WRITE);
}
UsbDio96h::~UsbDio96h()
{
}
} /* namespace ul */

24
src/hid/UsbDio96h.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbDio96h.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBDIO96H_H_
#define HID_USBDIO96H_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbDio96h: public HidDaqDevice
{
public:
UsbDio96h(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbDio96h();
};
} /* namespace ul */
#endif /* HID_USBDIO96H_H_ */

25
src/hid/UsbErbxx.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* UsbErbxx.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbErbxx.h"
#include "./dio/DioUsbErbxx.h"
namespace ul
{
UsbErbxx::UsbErbxx(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setDioDevice(new DioUsbErbxx(*this));
addMemRegion(MR_USER, 0x080, 3968 , MA_READ | MA_WRITE);
}
UsbErbxx::~UsbErbxx()
{
}
} /* namespace ul */

24
src/hid/UsbErbxx.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbErbxx.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBERBXX_H_
#define HID_USBERBXX_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbErbxx: public HidDaqDevice
{
public:
UsbErbxx(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbErbxx();
};
} /* namespace ul */
#endif /* HID_USBERBXX_H_ */

25
src/hid/UsbPdiso8.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* UsbPdiso8.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbPdiso8.h"
#include "./dio/DioUsbPdiso8.h"
namespace ul
{
UsbPdiso8::UsbPdiso8(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setDioDevice(new DioUsbPdiso8(*this));
addMemRegion(MR_USER, 0x080, 3968 , MA_READ | MA_WRITE);
}
UsbPdiso8::~UsbPdiso8()
{
}
} /* namespace ul */

24
src/hid/UsbPdiso8.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbPdiso8.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBPDISO8_H_
#define HID_USBPDISO8_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbPdiso8: public HidDaqDevice
{
public:
UsbPdiso8(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbPdiso8();
};
} /* namespace ul */
#endif /* HID_USBPDISO8_H_ */

25
src/hid/UsbSsrxx.cpp Normal file
View File

@ -0,0 +1,25 @@
/*
* UsbSsrxx.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbSsrxx.h"
#include "./dio/DioUsbSsrxx.h"
namespace ul
{
UsbSsrxx::UsbSsrxx(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setDioDevice(new DioUsbSsrxx(*this));
addMemRegion(MR_USER, 0x080, 3968 , MA_READ | MA_WRITE);
}
UsbSsrxx::~UsbSsrxx()
{
}
} /* namespace ul */

24
src/hid/UsbSsrxx.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbSsrxx.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBSSRXX_H_
#define HID_USBSSRXX_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbSsrxx: public HidDaqDevice
{
public:
UsbSsrxx(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbSsrxx();
};
} /* namespace ul */
#endif /* HID_USBSSRXX_H_ */

28
src/hid/UsbTemp.cpp Normal file
View File

@ -0,0 +1,28 @@
/*
* UsbTemp.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbTemp.h"
#include "./ai/AiUsbTemp.h"
#include "./dio/DioHidAux.h"
namespace ul
{
UsbTemp::UsbTemp(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setAiDevice(new AiUsbTemp(*this));
setDioDevice(new DioHidAux(*this));
addMemRegion(MR_USER, 0, 256 , MA_READ | MA_WRITE);
addMemRegion(MR_CAL, 0xF0, 6, MA_READ);
}
UsbTemp::~UsbTemp()
{
}
} /* namespace ul */

24
src/hid/UsbTemp.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbTemp.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBTEMP_H_
#define HID_USBTEMP_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbTemp: public HidDaqDevice
{
public:
UsbTemp(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbTemp();
};
} /* namespace ul */
#endif /* HID_USBTEMP_H_ */

31
src/hid/UsbTempAi.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* UsbTempAi.cpp
*
* Author: Measurement Computing Corporation
*/
#include "UsbTempAi.h"
#include "./ai/AiUsbTempAi.h"
#include "./dio/DioHidAux.h"
#include "./ctr/CtrHid.h"
namespace ul
{
UsbTempAi::UsbTempAi(const DaqDeviceDescriptor& daqDeviceDescriptor) : HidDaqDevice(daqDeviceDescriptor)
{
setAiDevice(new AiUsbTempAi(*this));
setDioDevice(new DioHidAux(*this));
setCtrDevice(new CtrHid(*this, 1));
addMemRegion(MR_USER, 0, 256 , MA_READ | MA_WRITE);
addMemRegion(MR_CAL, 0xF0, 6, MA_READ);
}
UsbTempAi::~UsbTempAi()
{
}
} /* namespace ul */

24
src/hid/UsbTempAi.h Normal file
View File

@ -0,0 +1,24 @@
/*
* UsbTempAi.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_USBTEMPAI_H_
#define HID_USBTEMPAI_H_
#include "HidDaqDevice.h"
namespace ul
{
class UL_LOCAL UsbTempAi: public HidDaqDevice
{
public:
UsbTempAi(const DaqDeviceDescriptor& daqDeviceDescriptor);
virtual ~UsbTempAi();
};
} /* namespace ul */
#endif /* HID_USBTEMPAI_H_ */

64
src/hid/ai/AiHidBase.cpp Normal file
View File

@ -0,0 +1,64 @@
/*
* AiHidBase.cpp
*
* Author: Measurement Computing Corporation
*/
#include "AiHidBase.h"
namespace ul
{
AiHidBase::AiHidBase(const HidDaqDevice& daqDevice): AiDevice(daqDevice), mHidDevice(daqDevice)
{
}
AiHidBase::~AiHidBase()
{
}
void AiHidBase::readCalDate()
{
unsigned char calDateBuf[6];
int calDateAddr = mAiInfo.getCalDateAddr();
if(calDateAddr != -1 && getScanState() == SS_IDLE)
{
int bytesReceived = daqDev().memRead(MT_EEPROM, MR_CAL, calDateAddr, (unsigned char*)calDateBuf, sizeof(calDateBuf));
if(bytesReceived == sizeof(calDateBuf))
{
tm time;
memset(&time, 0, sizeof(time));
time.tm_year = calDateBuf[0] + 100;
time.tm_mon = calDateBuf[1] - 1;
time.tm_mday = calDateBuf[2];
time.tm_hour = calDateBuf[3];
time.tm_min = calDateBuf[4];
time.tm_sec = calDateBuf[5];
time.tm_isdst = -1;
// make sure the date is valid, mktime does not validate the range
if(time.tm_mon <= 11 && time.tm_mday <= 31 && time.tm_hour <= 23 && time.tm_min <= 59 && time.tm_sec <= 60)
{
time_t cal_date_sec = mktime(&time); // seconds since unix epoch
if(cal_date_sec != -1) // mktime returns -1 if cal date is invalid
mCalDate = cal_date_sec;
// convert seconds to string
/*struct tm *timeinfo;
timeinfo = localtime(&cal_date_sec);
char b[100];
strftime(b, 100, "%Y-%m-%d %H:%M:%S", timeinfo);
std::cout << b << std::endl;*/
}
}
}
}
} /* namespace ul */

33
src/hid/ai/AiHidBase.h Normal file
View File

@ -0,0 +1,33 @@
/*
* AiHidBase.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_AI_AIHIDBASE_H_
#define HID_AI_AIHIDBASE_H_
#include "../HidDaqDevice.h"
#include "../../AiDevice.h"
namespace ul
{
class UL_LOCAL AiHidBase: public AiDevice
{
public:
AiHidBase(const HidDaqDevice& daqDevice);
virtual ~AiHidBase();
const HidDaqDevice& daqDev() const {return mHidDevice;}
protected:
virtual void readCalDate();
private:
const HidDaqDevice& mHidDevice;
};
} /* namespace ul */
#endif /* HID_AI_AIHIDBASE_H_ */

394
src/hid/ai/AiUsbTemp.cpp Normal file
View File

@ -0,0 +1,394 @@
/*
* AiUsbTemp.cpp
*
* Author: Measurement Computing Corporation
*/
#include "AiUsbTemp.h"
#include <iostream>
#include <sstream>
namespace ul
{
AiUsbTemp::AiUsbTemp(const HidDaqDevice& daqDevice) : AiHidBase(daqDevice)
{
mAiInfo.setNumChans(8);
mAiInfo.setNumCjcChans(2);
mAiInfo.hasTempChan(true);
mAiInfo.setNumChansByMode(AI_DIFFERENTIAL, 8);
mAiInfo.setResolution(24);
mAiInfo.setTInFlags(TIN_FF_DEFAULT);
mAiInfo.setTInArrayFlags(TINARRAY_FF_DEFAULT);
if(daqDev().getDeviceType() == DaqDeviceId::USB_TEMP)
{
mAiInfo.setChanTypes(AI_TC | AI_RTD | AI_THERMISTOR | AI_SEMICONDUCTOR);
mAiInfo.setChanTypes(0, 7, AI_TC | AI_RTD | AI_THERMISTOR | AI_SEMICONDUCTOR);
}
else
{
mAiInfo.setChanTypes(AI_TC);
mAiInfo.setChanTypes(0, 7, AI_TC);
}
mAiInfo.addInputMode(AI_DIFFERENTIAL);
mAiInfo.addRange(AI_DIFFERENTIAL, BIPPT078VOLTS);
mAiInfo.setCalDateAddr(0xF0);
initCustomScales();
}
AiUsbTemp::~AiUsbTemp()
{
}
void AiUsbTemp::initialize()
{
try
{
readCalDate();
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
void AiUsbTemp::tIn(int channel, TempScale scale, TInFlag flags, double* data)
{
check_TIn_Args(channel, scale, flags);
float tempValue = 0;
unsigned char chan = channel;
unsigned char units = 0;
if(scale == TS_VOLTS || scale == TS_NOSCALE)
units = 1;
float fData;
daqDev().queryCmd(CMD_TIN, chan, units, &fData);
tempValue = mEndian.le_ptr_to_cpu_f32((unsigned char*) &fData);
switch((int)(tempValue))
{
case -8888: // if the temp Value is -8888.0 TC open connection is detected
*data=-9999.0f;
throw UlException(ERR_OPEN_CONNECTION);
break;
case -9000: // if the temp Value is -9000.0 device is not ready yet
throw UlException(ERR_DEV_NOT_READY);
break;
default:
tempValue = convertTempUnit(tempValue, (TempUnit)scale);
*data = mCustomScales[channel].slope * tempValue + mCustomScales[channel].offset;
break;
}
}
void AiUsbTemp::tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[])
{
check_TInArray_Args(lowChan, highChan, scale, flags, data);
int chanCount = highChan - lowChan + 1;
unsigned char startChan = lowChan;
unsigned char endChan = highChan;
unsigned char units = 0;
bool openConnection = false;
if(scale == TS_VOLTS || scale == TS_NOSCALE)
units = 1;
float fData[8];
memset(fData, 0 , 8 * sizeof(float));
daqDev().queryCmd(CMD_TINSCAN, startChan, endChan, units, (unsigned char*) fData, chanCount * sizeof(float));
float tempValue = 0;
int channel = 0;
for(int i = 0; i < chanCount; i++)
{
tempValue = mEndian.le_ptr_to_cpu_f32((unsigned char*) &fData[i]);
channel = lowChan + i;
switch((int)(tempValue))
{
case -8888: // if the temp Value is -8888.0 TC open connection is detected
data[i] = -9999.0f;
openConnection = true;
break;
case -9000: // if the temp Value is -9000.0 device is not ready yet
throw UlException(ERR_DEV_NOT_READY);
break;
case -9999:
break;
default:
data[i] = convertTempUnit(tempValue, (TempUnit)scale);
data[i] = mCustomScales[channel].slope * data[i] + mCustomScales[channel].offset;
break;
}
}
if(openConnection)
throw UlException(ERR_OPEN_CONNECTION);
}
unsigned char AiUsbTemp::tcCode(TcType tcType) const
{
unsigned char tcCode = 0;
switch(tcType)
{
case TC_J:
tcCode = 0;
break;
case TC_K:
tcCode = 1;
break;
case TC_T:
tcCode = 2;
break;
case TC_E:
tcCode = 3;
break;
case TC_R:
tcCode = 4;
break;
case TC_S:
tcCode = 5;
break;
case TC_B:
tcCode = 6;
break;
case TC_N:
tcCode = 7;
break;
}
return tcCode;
}
TcType AiUsbTemp::tcType(unsigned char tcCode) const
{
TcType tcType;
switch(tcCode)
{
case 0:
tcType = TC_J;
break;
case 1:
tcType = TC_K;
break;
case 2:
tcType = TC_T;
break;
case 3:
tcType = TC_E;
break;
case 4:
tcType = TC_R;
break;
case 5:
tcType = TC_S;
break;
case 6:
tcType = TC_B;
break;
case 7:
tcType = TC_N;
break;
default:
tcType = (TcType) 0;
break;
}
return tcType;
}
AiChanType AiUsbTemp::getCfg_ChanType(int channel) const
{
AiChanType chanType;
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
unsigned char adc = channel / 2;
unsigned char subItem = SUBITEM_SENSOR_TYPE;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char sensorType = buf[0];
switch(sensorType)
{
case ST_RTD:
chanType = AI_RTD;
break;
case ST_THERMISTOR:
chanType = AI_THERMISTOR;
break;
case ST_THERMOCOUPLE:
chanType = AI_TC;
break;
case ST_SEMICONDUCTOR:
chanType = AI_SEMICONDUCTOR;
break;
default:
chanType = AI_DISABLED;
break;
}
return chanType;
}
SensorConnectionType AiUsbTemp::getCfg_SensorConnectionType(int channel) const
{
SensorConnectionType connectionType = (SensorConnectionType) 0;
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
AiChanType chanType = getCfg_ChanType(channel);
if(chanType == AI_RTD || chanType == AI_THERMISTOR)
{
unsigned char adc = channel / 2;
unsigned char subItem = SUBITEM_CONNECTION_TYPE;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char sensorType = buf[0];
switch(sensorType)
{
case 0:
connectionType = SCT_2_WIRE_1;
break;
case 1:
connectionType = SCT_2_WIRE_2;
break;
case 2:
connectionType = SCT_3_WIRE;
break;
case 3:
connectionType = SCT_4_WIRE;
break;
}
}
return connectionType;
}
void AiUsbTemp::getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const
{
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
if(!coefsStr)
throw UlException(ERR_BAD_BUFFER);
AiChanType chanType = getCfg_ChanType(channel);
int coefCount = 0;
if(chanType == AI_RTD)
coefCount = 4;
else if (chanType == AI_THERMISTOR)
coefCount = 3;
else if (chanType == AI_SEMICONDUCTOR)
coefCount = 2;
if(coefCount)
{
std::ostringstream coefs;
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_COEF0 + adcChan;
float coef;
for(int i = 0; i < coefCount; i++)
{
daqDev().queryCmd(CMD_GETITEM, adc, subItem, &coef);
coefs << coef;
if(i != (coefCount -1))
coefs << ", ";
subItem += 2;
}
if(*len > coefs.str().length())
{
strcpy(coefsStr, coefs.str().c_str());
*len = coefs.str().length() + 1;
}
else
{
*len = coefs.str().length() + 1;
throw UlException(ERR_BAD_BUFFER);
}
}
else
*len = 0;
}
void AiUsbTemp::setCfg_ChanTcType(int channel, TcType tcType)
{
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
if(tcType < TC_J || tcType > TC_N)
throw UlException(ERR_BAD_TC_TYPE);
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_TC_TYPE + adcChan;
unsigned char tcCodeVal = tcCode(tcType);
daqDev().sendCmd(CMD_SETITEM, adc, subItem, tcCodeVal);
}
TcType AiUsbTemp::getCfg_ChanTcType(int channel) const
{
TcType tcTypeVal;
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_TC_TYPE + adcChan;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char tcCodeVal = buf[0];
tcTypeVal = tcType(tcCodeVal);
return tcTypeVal;
}
} /* namespace ul */

52
src/hid/ai/AiUsbTemp.h Normal file
View File

@ -0,0 +1,52 @@
/*
* AiUsbTemp.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_AI_AIUSBTEMP_H_
#define HID_AI_AIUSBTEMP_H_
#include "AiHidBase.h"
namespace ul
{
class UL_LOCAL AiUsbTemp: public AiHidBase
{
public:
AiUsbTemp(const HidDaqDevice& daqDevice);
virtual ~AiUsbTemp();
virtual void initialize();
virtual void tIn(int channel, TempScale scale, TInFlag flags, double* data);
virtual void tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[]);
////////////////////// Configuration functions /////////////////////////////////
virtual AiChanType getCfg_ChanType(int channel) const;
virtual SensorConnectionType getCfg_SensorConnectionType(int channel) const;
virtual void getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const;
virtual void setCfg_ChanTcType(int channel, TcType tcType);
virtual TcType getCfg_ChanTcType(int channel) const;
protected:
virtual void loadAdcCoefficients() {};
virtual int getCalCoefIndex(int channel, AiInputMode inputMode, Range range) const { return 0; }
unsigned char tcCode(TcType tcType) const;
TcType tcType(unsigned char tcCode) const;
private:
enum {CMD_TIN = 0x18, CMD_TINSCAN = 0x19, CMD_SETITEM = 0x49, CMD_GETITEM = 0x4A};
enum {SUBITEM_SENSOR_TYPE = 0, SUBITEM_CONNECTION_TYPE = 1, SUBITEM_TC_TYPE = 0x10, SUBITEM_COEF0 = 0x14};
enum {ST_RTD = 0, ST_THERMISTOR = 1, ST_THERMOCOUPLE = 2, ST_SEMICONDUCTOR = 3, ST_DISABLED = 4};
enum {CT_2W_1S = 0, CT_2W_2S = 1, CT_3W = 2, CT_4W = 3 };
};
} /* namespace ul */
#endif /* HID_AI_AIUSBTEMP_H_ */

624
src/hid/ai/AiUsbTempAi.cpp Normal file
View File

@ -0,0 +1,624 @@
/*
* AiUsbTempAi.cpp
*
* Author: Measurement Computing Corporation
*/
#include "AiUsbTempAi.h"
#include <unistd.h>
#include <iostream>
#include <sstream>
namespace ul
{
AiUsbTempAi::AiUsbTempAi(const HidDaqDevice& daqDevice) : AiHidBase(daqDevice)
{
mAiInfo.setNumChans(8);
mAiInfo.setNumCjcChans(2);
mAiInfo.hasTempChan(true);
mAiInfo.setNumChansByMode(AI_DIFFERENTIAL, 8);
mAiInfo.setNumChansByMode(AI_SINGLE_ENDED, 4);
mAiInfo.setResolution(24);
mAiInfo.setAInFlags(AIN_FF_NOSCALEDATA);
mAiInfo.setTInFlags(TIN_FF_DEFAULT);
mAiInfo.setTInArrayFlags(TINARRAY_FF_DEFAULT);
if(daqDev().getDeviceType() == DaqDeviceId::USB_TEMP_AI)
{
mAiInfo.setChanTypes(AI_VOLTAGE | AI_TC | AI_RTD | AI_THERMISTOR | AI_SEMICONDUCTOR);
mAiInfo.setChanTypes(0, 3, AI_TC | AI_RTD | AI_THERMISTOR | AI_SEMICONDUCTOR);
mAiInfo.setChanTypes(4, 7, AI_VOLTAGE);
}
else
{
mAiInfo.setChanTypes(AI_VOLTAGE | AI_TC);
mAiInfo.setChanTypes(0, 3, AI_TC);
mAiInfo.setChanTypes(4, 7, AI_VOLTAGE);
}
mAiInfo.addInputMode(AI_SINGLE_ENDED);
mAiInfo.addInputMode(AI_DIFFERENTIAL);
mAiInfo.setCalDateAddr(0xF0);
addSupportedRanges();
initTempUnits();
initCustomScales();
memset(mCurrentChanCfg, 0, sizeof(mCurrentChanCfg));
}
AiUsbTempAi::~AiUsbTempAi()
{
}
void AiUsbTempAi::initialize()
{
try
{
readCalDate();
unsigned char adc, adcChan, subItem, modeCode, rangeCode;
// read and store voltage channels mode and range
for(int chan = 4; chan < mAiInfo.getNumChans(); chan++)
{
adc = chan / 2;
adcChan = chan % 2;
subItem = SUBITEM_CHAN_MODE + adcChan;
daqDev().queryCmd(CMD_GETITEM, adc, subItem, &modeCode);
mCurrentChanCfg[chan].inputMode = (AiInputMode) 0;
if(modeCode == 0)
mCurrentChanCfg[chan].inputMode = AI_DIFFERENTIAL;
else if(modeCode == 1)
mCurrentChanCfg[chan].inputMode = AI_SINGLE_ENDED;
subItem = SUBITEM_CHAN_RANGE + adcChan;
daqDev().queryCmd(CMD_GETITEM, adc, subItem, &rangeCode);
mCurrentChanCfg[chan].range = (Range) 0;
switch(rangeCode)
{
case 2:
mCurrentChanCfg[chan].range = BIP10VOLTS;
break;
case 3:
mCurrentChanCfg[chan].range = BIP5VOLTS;
break;
case 4:
mCurrentChanCfg[chan].range = BIP2PT5VOLTS;
break;
case 5:
mCurrentChanCfg[chan].range = BIP1PT25VOLTS;
break;
}
}
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
double AiUsbTempAi::aIn(int channel, AiInputMode inputMode, Range range, AInFlag flags)
{
check_AIn_Args(channel, inputMode, range, flags);
double data = 0.0;
bool chanCfgChanged = false;
if(channel >= 4) // voltage channels
{
if(mCurrentChanCfg[channel].inputMode != inputMode)
{
setInputMode(channel, inputMode);
chanCfgChanged = true;
}
if(mCurrentChanCfg[channel].range != range)
{
setRange(channel, range);
chanCfgChanged = true;
}
if(chanCfgChanged)
usleep(1000000);
unsigned char chan = channel;
unsigned char units = 0;
if(flags & AIN_FF_NOSCALEDATA)
units = 1;
float fData;
daqDev().queryCmd(CMD_AIN, chan, units, &fData);
data = mEndian.le_ptr_to_cpu_f32((unsigned char*) &fData);
data = mCustomScales[channel].slope * data + mCustomScales[channel].offset;
}
else
throw UlException(ERR_BAD_AI_CHAN);
return data;
}
void AiUsbTempAi::tIn(int channel, TempScale scale, TInFlag flags, double* data)
{
check_TIn_Args(channel, scale, flags);
float tempValue = 0;
unsigned char chan = channel;
unsigned char units = 0;
// remove if we need TIn to read voltage channels
if(channel > 3)
throw UlException(ERR_BAD_AI_CHAN);
if(channel < 4 && (scale == TS_VOLTS || scale == TS_NOSCALE))
units = 1;
float fData;
daqDev().queryCmd(CMD_AIN, chan, units, &fData);
tempValue = mEndian.le_ptr_to_cpu_f32((unsigned char*) &fData);
if(channel < 4) // perform conversion if a temp channel
{
switch((int)(tempValue))
{
case -8888: // if the temp Value is -8888.0 TC open connection is detected
*data =-9999.0f;
throw UlException(ERR_OPEN_CONNECTION);
break;
case -9000: // if the temp Value is -9000.0 device is not ready yet
throw UlException(ERR_DEV_NOT_READY);
break;
default:
tempValue = convertTempUnit(tempValue, (TempUnit)scale);
*data = mCustomScales[channel].slope * tempValue + mCustomScales[channel].offset;
break;
}
}
}
void AiUsbTempAi::tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[])
{
check_TInArray_Args(lowChan, highChan, scale, flags, data);
int chanCount = highChan - lowChan + 1;
unsigned char startChan = lowChan;
unsigned char endChan = highChan;
unsigned char units = 0;
bool openConnection = false;
if(scale == TS_VOLTS || scale == TS_NOSCALE)
units = 1;
float fData[8];
float tempValue = 0;
int channel = 0;
memset(fData, 0 , 8 * sizeof(float));
daqDev().queryCmd(CMD_AINSCAN, startChan, endChan, units, (unsigned char*) fData, chanCount * sizeof(float));
for(int i = 0; i < chanCount; i++)
{
tempValue = mEndian.le_ptr_to_cpu_f32((unsigned char*)&fData[i]);
channel = lowChan + i;
if((lowChan + i) < 4) // perform conversion if a temp channel
{
switch((int)(tempValue))
{
case -8888: // if the temp Value is -8888.0 TC open connection is detected
data[i] = -9999.0f;
openConnection = true;
break;
case -9000: // if the temp Value is -9000.0 device is not ready yet
throw UlException(ERR_DEV_NOT_READY);
break; // if the temp Value is -9000.0 device is not ready yet
case -9999:
data[i] = tempValue;
break;
default:
data[i] = convertTempUnit(tempValue, (TempUnit)scale);
data[i] = mCustomScales[channel].slope * data[i] + mCustomScales[channel].offset;
break;
}
}
}
if(openConnection)
throw UlException(ERR_OPEN_CONNECTION);
}
void AiUsbTempAi::setInputMode(int channel, AiInputMode mode)
{
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_CHAN_MODE + adcChan;
unsigned char modeCode = (mode == AI_SINGLE_ENDED) ? 1 : 0;
daqDev().sendCmd(CMD_SETITEM, adc, subItem, modeCode);
mCurrentChanCfg[channel].inputMode = mode;
}
void AiUsbTempAi::setRange(int channel, Range range)
{
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_CHAN_RANGE + adcChan;
unsigned char rangeCode = getRangeCode(range);
daqDev().sendCmd(CMD_SETITEM, adc, subItem, rangeCode);
mCurrentChanCfg[channel].range = range;
}
unsigned char AiUsbTempAi::tcCode(TcType tcType) const
{
unsigned char tcCode = 0;
switch(tcType)
{
case TC_J:
tcCode = 0;
break;
case TC_K:
tcCode = 1;
break;
case TC_T:
tcCode = 2;
break;
case TC_E:
tcCode = 3;
break;
case TC_R:
tcCode = 4;
break;
case TC_S:
tcCode = 5;
break;
case TC_B:
tcCode = 6;
break;
case TC_N:
tcCode = 7;
break;
}
return tcCode;
}
TcType AiUsbTempAi::tcType(unsigned char tcCode) const
{
TcType tcType;
switch(tcCode)
{
case 0:
tcType = TC_J;
break;
case 1:
tcType = TC_K;
break;
case 2:
tcType = TC_T;
break;
case 3:
tcType = TC_E;
break;
case 4:
tcType = TC_R;
break;
case 5:
tcType = TC_S;
break;
case 6:
tcType = TC_B;
break;
case 7:
tcType = TC_N;
break;
default:
tcType = (TcType) 0;
break;
}
return tcType;
}
unsigned char AiUsbTempAi::getRangeCode(Range range) const
{
unsigned char code;
switch(range)
{
case BIP10VOLTS:
code = 2;
break;
case BIP5VOLTS:
code = 3;
break;
case BIP2PT5VOLTS:
code = 4;
break;
case BIP1PT25VOLTS:
code = 5;
break;
default:
code = 2;
break;
}
return code;
}
AiChanType AiUsbTempAi::getCfg_ChanType(int channel) const
{
AiChanType chanType;
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP_AI)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
if(channel < 4)
{
unsigned char adc = channel / 2;
unsigned char subItem = SUBITEM_SENSOR_TYPE;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char sensorType = buf[0];
switch(sensorType)
{
case 0:
chanType = AI_RTD;
break;
case 1:
chanType = AI_THERMISTOR;
break;
case 2:
chanType = AI_TC;
break;
case 3:
chanType = AI_SEMICONDUCTOR;
break;
default:
chanType = AI_DISABLED;
break;
}
}
else
{
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_CHAN_MODE + adcChan;
unsigned char modeCode = 0;
daqDev().queryCmd(CMD_GETITEM, adc, subItem, &modeCode);
if(modeCode == 0x02)
chanType = AI_DISABLED;
else
chanType = AI_VOLTAGE;
}
return chanType;
}
SensorConnectionType AiUsbTempAi::getCfg_SensorConnectionType(int channel) const
{
SensorConnectionType connectionType = (SensorConnectionType) 0;
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP_AI)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
AiChanType chanType = getCfg_ChanType(channel);
if(chanType == AI_RTD || chanType == AI_THERMISTOR)
{
unsigned char adc = channel / 2;
unsigned char subItem = SUBITEM_CONNECTION_TYPE;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char sensorType = buf[0];
switch(sensorType)
{
case 0:
connectionType = SCT_2_WIRE_1;
break;
case 1:
connectionType = SCT_2_WIRE_2;
break;
case 2:
connectionType = SCT_3_WIRE;
break;
case 3:
connectionType = SCT_4_WIRE;
break;
}
}
return connectionType;
}
void AiUsbTempAi::getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const
{
if(daqDev().getDeviceType() != DaqDeviceId::USB_TEMP_AI)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
if(channel < 0 || channel >= mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
if(!coefsStr)
throw UlException(ERR_BAD_BUFFER);
AiChanType chanType = getCfg_ChanType(channel);
int coefCount = 0;
if(chanType == AI_RTD)
coefCount = 4;
else if (chanType == AI_THERMISTOR)
coefCount = 3;
else if (chanType == AI_SEMICONDUCTOR)
coefCount = 2;
if(coefCount)
{
std::ostringstream coefs;
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_COEF0 + adcChan;
float coef;
for(int i = 0; i < coefCount; i++)
{
daqDev().queryCmd(CMD_GETITEM, adc, subItem, &coef);
coefs << coef;
if(i != (coefCount -1))
coefs << ", ";
subItem += 2;
}
if(*len > coefs.str().length())
{
strcpy(coefsStr, coefs.str().c_str());
*len = coefs.str().length() + 1;
}
else
{
*len = coefs.str().length() + 1;
throw UlException(ERR_BAD_BUFFER);
}
}
else
*len = 0;
}
void AiUsbTempAi::setCfg_ChanTcType(int channel, TcType tcType)
{
if(channel < 0 || channel > 3)
throw UlException(ERR_BAD_AI_CHAN);
if(tcType < TC_J || tcType > TC_N)
throw UlException(ERR_BAD_TC_TYPE);
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_TC_TYPE + adcChan;
unsigned char tcCodeVal = tcCode(tcType);
daqDev().sendCmd(CMD_SETITEM, adc, subItem, tcCodeVal);
}
TcType AiUsbTempAi::getCfg_ChanTcType(int channel) const
{
TcType tcTypeVal;
if(channel < 0 || channel > 3)
throw UlException(ERR_BAD_AI_CHAN);
unsigned char adc = channel / 2;
unsigned char adcChan = channel % 2;
unsigned char subItem = SUBITEM_TC_TYPE + adcChan;
unsigned char buf[4];
daqDev().queryCmd(CMD_GETITEM, adc, subItem, buf);
unsigned char tcCodeVal = buf[0];
tcTypeVal = tcType(tcCodeVal);
return tcTypeVal;
}
void AiUsbTempAi::check_AIn_Args(int channel, AiInputMode inputMode, Range range, AInFlag flags) const
{
if(channel < 0 || channel > mAiInfo.getNumChans())
throw UlException(ERR_BAD_AI_CHAN);
if(!mAiInfo.isInputModeSupported(inputMode))
throw UlException(ERR_BAD_INPUT_MODE);
if(!mAiInfo.isRangeSupported(inputMode, range))
throw UlException(ERR_BAD_RANGE);
if(channel > 3 && range == BIPPT078VOLTS)
throw UlException(ERR_BAD_RANGE);
if(~mAiInfo.getAInFlags() & flags)
throw UlException(ERR_BAD_FLAG);
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
if((int) mCustomScales.size() < mAiInfo.getNumChans())
throw UlException(ERR_INTERNAL);
}
TempScale AiUsbTempAi::getTempScale(TempUnit unit)
{
TempScale scale;
switch(unit)
{
case TU_FAHRENHEIT:
scale = TS_FAHRENHEIT;
break;
case TU_KELVIN:
scale = TS_KELVIN;
break;
default:
scale = TS_CELSIUS;
}
return scale;
}
void AiUsbTempAi::addSupportedRanges()
{
mAiInfo.addRange(AI_SINGLE_ENDED, BIP10VOLTS);
mAiInfo.addRange(AI_SINGLE_ENDED, BIP5VOLTS);
mAiInfo.addRange(AI_SINGLE_ENDED, BIP2PT5VOLTS);
mAiInfo.addRange(AI_SINGLE_ENDED, BIP1PT25VOLTS);
mAiInfo.addRange(AI_DIFFERENTIAL, BIP10VOLTS);
mAiInfo.addRange(AI_DIFFERENTIAL, BIP5VOLTS);
mAiInfo.addRange(AI_DIFFERENTIAL, BIP2PT5VOLTS);
mAiInfo.addRange(AI_DIFFERENTIAL, BIP1PT25VOLTS);
mAiInfo.addRange(AI_DIFFERENTIAL, BIPPT078VOLTS);
}
} /* namespace ul */

65
src/hid/ai/AiUsbTempAi.h Normal file
View File

@ -0,0 +1,65 @@
/*
* AiUsbTempAi.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_AI_AIUSBTEMPAI_H_
#define HID_AI_AIUSBTEMPAI_H_
#include "AiHidBase.h"
namespace ul
{
class UL_LOCAL AiUsbTempAi: public AiHidBase
{
public:
AiUsbTempAi(const HidDaqDevice& daqDevice);
virtual ~AiUsbTempAi();
virtual void initialize();
virtual double aIn(int channel, AiInputMode inputMode, Range range, AInFlag flags);
virtual void tIn(int channel, TempScale scale, TInFlag flags, double* data);
virtual void tInArray(int lowChan, int highChan, TempScale scale, TInArrayFlag flags, double data[]);
////////////////////// Configuration functions /////////////////////////////////
virtual AiChanType getCfg_ChanType(int channel) const;
virtual SensorConnectionType getCfg_SensorConnectionType(int channel) const;
virtual void getCfg_ChanCoefsStr(int channel, char* coefsStr, unsigned int* len) const;
virtual void setCfg_ChanTcType(int channel, TcType tcType);
virtual TcType getCfg_ChanTcType(int channel) const;
protected:
virtual void loadAdcCoefficients() {};
virtual int getCalCoefIndex(int channel, AiInputMode inputMode, Range range) const { return 0; }
unsigned char tcCode(TcType tcType) const;
TcType tcType(unsigned char tcCode) const;
unsigned char getRangeCode(Range range) const;
void setInputMode(int channel, AiInputMode mode);
void setRange(int channel, Range range);
void addSupportedRanges();
TempScale getTempScale(TempUnit unit);
virtual void check_AIn_Args(int channel, AiInputMode inputMode, Range range, AInFlag flags) const;
private:
enum {CMD_AIN = 0x18, CMD_AINSCAN = 0x19, CMD_SETITEM = 0x49, CMD_GETITEM = 0x4A};
enum {SUBITEM_SENSOR_TYPE = 0, SUBITEM_CONNECTION_TYPE = 1, SUBITEM_TC_TYPE = 0x10, SUBITEM_CHAN_RANGE = 0x12, SUBITEM_COEF0 = 0x14, SUBITEM_CHAN_MODE = 0x1C};
enum {ST_RTD = 0, ST_THERMISTOR = 1, ST_THERMOCOUPLE = 2, ST_SEMICONDUCTOR = 3, ST_DISABLED = 4};
enum {CT_2W_1S = 0, CT_2W_2S = 1, CT_3W = 2, CT_4W = 3 };
AiQueueElement mCurrentChanCfg[8];
};
} /* namespace ul */
#endif /* HID_AI_AIUSBTEMPAI_H_ */

23
src/hid/ao/AoHidBase.cpp Normal file
View File

@ -0,0 +1,23 @@
/*
* AoHidBase.cpp
*
* Author: Measurement Computing Corporation
*/
#include "AoHidBase.h"
namespace ul
{
AoHidBase::AoHidBase(const HidDaqDevice& daqDevice): AoDevice(daqDevice), mHidDevice(daqDevice)
{
}
AoHidBase::~AoHidBase()
{
}
} /* namespace ul */

30
src/hid/ao/AoHidBase.h Normal file
View File

@ -0,0 +1,30 @@
/*
* AoHidBase.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_AO_AOHIDBASE_H_
#define HID_AO_AOHIDBASE_H_
#include "../HidDaqDevice.h"
#include "../../AoDevice.h"
namespace ul
{
class UL_LOCAL AoHidBase: public AoDevice
{
public:
AoHidBase(const HidDaqDevice& daqDevice);
virtual ~AoHidBase();
const HidDaqDevice& daqDev() const {return mHidDevice;}
private:
const HidDaqDevice& mHidDevice;
};
} /* namespace ul */
#endif /* HID_AO_AOHIDBASE_H_ */

268
src/hid/ao/AoUsb3100.cpp Normal file
View File

@ -0,0 +1,268 @@
/*
* AoUsb3100.cpp
*
* Author: Measurement Computing Corporation
*/
#include "AoUsb3100.h"
namespace ul
{
AoUsb3100::AoUsb3100(const HidDaqDevice& daqDevice) : AoHidBase(daqDevice)
{
mAoInfo.setAOutFlags(AOUT_FF_NOSCALEDATA | AOUT_FF_NOCALIBRATEDATA);
mAoInfo.setAOutArrayFlags(AOUTARRAY_FF_NOSCALEDATA | AOUTARRAY_FF_NOCALIBRATEDATA | AOUTARRAY_FF_SIMULTANEOUS);
mAoInfo.setNumChans(numChans());
mAoInfo.setResolution(16);
mAoInfo.setCalCoefsStartAddr(0x100);
mAoInfo.setSampleSize(2);
mAoInfo.addRange(BIP10VOLTS);
mAoInfo.addRange(UNI10VOLTS);
int rangeCount = 2;
if(hasCurrentOutput())
{
mAoInfo.addRange(MA0TO20);
rangeCount++;
}
mAoInfo.setCalCoefCount(rangeCount * mAoInfo.getNumChans());
mSyncMode = AOSM_SLAVE;
memset(mChanCurrentRange, 0, sizeof(mChanCurrentRange));
}
AoUsb3100::~AoUsb3100()
{
}
void AoUsb3100::initialize()
{
memset(mChanCurrentRange, 0, sizeof(mChanCurrentRange));
try
{
mSyncMode = readSyncMode();
loadDacCoefficients();
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
void AoUsb3100::aOut(int channel, Range range, AOutFlag flags, double dataValue)
{
check_AOut_Args(channel, range, flags, dataValue);
writeData(channel, range, flags, dataValue, UPDATE_IMMEDIATE);
}
void AoUsb3100::aOutArray(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[])
{
check_AOutArray_Args(lowChan, highChan, range, flags, data);
unsigned char updateMode = (flags & AOUTARRAY_FF_SIMULTANEOUS) ? UPDATE_ON_SYNC : UPDATE_IMMEDIATE;
int i = 0;
for(int chan = lowChan; chan <= highChan; chan++)
{
writeData(chan, range[i], (AOutFlag) flags, data[i], updateMode);
i++;
}
if(flags & AOUTARRAY_FF_SIMULTANEOUS)
{
if(mSyncMode == AOSM_MASTER)
daqDev().sendCmd(CMD_AOUTSYNC);
}
}
void AoUsb3100::writeData(int channel, Range range, AOutFlag flags, double dataValue, unsigned char updateMode)
{
if(mChanCurrentRange[channel] != range)
configChanRange(channel, range);
unsigned char chan = channel;
unsigned short calData = calibrateData(channel, range, flags, dataValue);
if(range == MA0TO20 && dataValue == 0.0) // don't apply cal factors if output value is zero, from the windows code
calData = 0;
calData = Endian::cpu_to_le_ui16(calData);
daqDev().sendCmd(CMD_AOUT, chan, calData, updateMode);
}
void AoUsb3100::configChanRange(int channel, Range range)
{
unsigned char rangeCode = mapRangeCode(range);
daqDev().sendCmd(CMD_AOUTCONFIG, (unsigned char) channel , rangeCode);
mChanCurrentRange[channel] = range;
}
AOutSyncMode AoUsb3100::readSyncMode() const
{
unsigned char cmd = CMD_STATUS;
unsigned char status = 0;
daqDev().queryCmd(cmd, &status);
AOutSyncMode mode = (AOutSyncMode)(status & 0x01);
return mode;
}
void AoUsb3100::writeSyncMode(AOutSyncMode mode) const
{
unsigned char cmd = CMD_SETSYNC;
unsigned char type = (mode == 0) ? 1 : 0;
daqDev().sendCmd(cmd, type);
}
int AoUsb3100::mapRangeCode(Range range) const
{
int rangeCode;
switch(range)
{
case UNI10VOLTS:
rangeCode = 0;
break;
case BIP10VOLTS:
rangeCode = 1;
break;
case MA0TO20:
rangeCode = 0;
break;
default:
throw UlException(ERR_BAD_RANGE);
}
return rangeCode;
}
int AoUsb3100::getCalCoefIndex(int channel, Range range) const
{
int index = 0;
if(range == UNI10VOLTS)
index = channel * 2;
else if(range == BIP10VOLTS)
index = channel * 2 + 1;
else if(range == MA0TO20)
index = mAoInfo.getNumChans() * 2 + channel;
return index;
}
void AoUsb3100::loadDacCoefficients()
{
#pragma pack(1)
typedef struct
{
unsigned char slope[4];
unsigned char offset[4];
} coef;
#pragma pack()
CalCoef calCoef;
mCalCoefs.clear();
bool readCurOutCoefs = false;
int calCoefCount = mAoInfo.getNumChans() * 2;
int calBlockSize = calCoefCount * sizeof(coef);
int address = mAoInfo.getCalCoefsStartAddr();
coef* buffer = new coef[calCoefCount];
start:
int bytesReceived = daqDev().memRead(MT_EEPROM, MR_CAL, address, (unsigned char*)buffer, calBlockSize);
if(bytesReceived == calBlockSize)
{
for(int i = 0; i < calCoefCount; i++)
{
calCoef.slope = mEndian.le_ptr_to_cpu_f32(buffer[i].slope);
calCoef.offset = mEndian.le_ptr_to_cpu_f32(buffer[i].offset);
mCalCoefs.push_back(calCoef);
}
}
if(hasCurrentOutput() && !readCurOutCoefs)
{
calCoefCount = mAoInfo.getNumChans();
calBlockSize = calCoefCount * sizeof(coef);
address = 0x200;
readCurOutCoefs = true;
goto start;
}
delete [] buffer;
}
int AoUsb3100::numChans() const
{
int numChans;
switch(daqDev().getDeviceType())
{
case DaqDeviceId::USB_3103:
case DaqDeviceId::USB_3104:
case DaqDeviceId::USB_3112:
numChans = 8;
break;
case DaqDeviceId::USB_3105:
case DaqDeviceId::USB_3106:
case DaqDeviceId::USB_3114:
numChans = 16;
break;
default:
numChans = 4;
break;
}
return numChans;
}
bool AoUsb3100::hasCurrentOutput() const
{
bool hasCurOut = false;
if(daqDev().getDeviceType() == DaqDeviceId::USB_3102 ||
daqDev().getDeviceType() == DaqDeviceId::USB_3104 ||
daqDev().getDeviceType() == DaqDeviceId::USB_3106)
{
hasCurOut = true;
}
return hasCurOut;
}
void AoUsb3100::setCfg_SyncMode(AOutSyncMode mode)
{
writeSyncMode(mode);
mSyncMode = readSyncMode();
}
AOutSyncMode AoUsb3100::getCfg_SyncMode() const
{
return readSyncMode();
}
} /* namespace ul */

54
src/hid/ao/AoUsb3100.h Normal file
View File

@ -0,0 +1,54 @@
/*
* AoUsb3100.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_AO_AOUSB3100_H_
#define HID_AO_AOUSB3100_H_
#include "AoHidBase.h"
namespace ul
{
class UL_LOCAL AoUsb3100: public AoHidBase
{
public:
AoUsb3100(const HidDaqDevice& daqDevice);
virtual ~AoUsb3100();
virtual void initialize();
virtual void aOut(int channel, Range range, AOutFlag flags, double dataValue);
virtual void aOutArray(int lowChan, int highChan, Range range[], AOutArrayFlag flags, double data[]);
void configChanRange(int channel, Range range);
virtual void setCfg_SyncMode(AOutSyncMode mode);
virtual AOutSyncMode getCfg_SyncMode() const;
protected:
void writeData(int channel, Range range, AOutFlag flags, double dataValue, unsigned char updateMode);
int mapRangeCode(Range range) const;
virtual int getCalCoefIndex(int channel, Range range) const;
private:
int numChans() const;
bool hasCurrentOutput() const;
void loadDacCoefficients();
AOutSyncMode readSyncMode() const;
void writeSyncMode(AOutSyncMode mode) const;
private:
enum { CMD_AOUT = 0x14, CMD_AOUTSYNC = 0x15, CMD_AOUTCONFIG = 0x1C, CMD_SETSYNC = 0x43, CMD_STATUS = 0x44};
enum { UPDATE_IMMEDIATE = 0, UPDATE_ON_SYNC = 1 };
Range mChanCurrentRange[16];
AOutSyncMode mSyncMode;
};
} /* namespace ul */
#endif /* HID_AO_AOUSB3100_H_ */

64
src/hid/ctr/CtrHid.cpp Normal file
View File

@ -0,0 +1,64 @@
/*
* CtrHid.cpp
*
* Author: Measurement Computing Corporation
*/
#include "CtrHid.h"
namespace ul
{
CtrHid::CtrHid(const HidDaqDevice& daqDevice, int numCtrs) : CtrHidBase(daqDevice)
{
mCtrInfo.hasPacer(false);
mCtrInfo.setResolution(32);
for(int ctr = 0; ctr < numCtrs; ctr++)
mCtrInfo.addCtr(CMT_COUNT);
mCtrInfo.setRegisterTypes(CRT_COUNT | CRT_LOAD);
}
CtrHid::~CtrHid()
{
}
unsigned long long CtrHid::cIn(int ctrNum)
{
unsigned int count = 0;
check_CIn_Args(ctrNum);
daqDev().queryCmd(CMD_CIN, &count);
return count;
}
void CtrHid::cLoad(int ctrNum, CounterRegisterType regType, unsigned long long loadValue)
{
check_CLoad_Args(ctrNum, regType, loadValue);
if(loadValue != 0)
throw UlException(ERR_BAD_CTR_VAL);
daqDev().sendCmd(CMD_CINIT);
}
void CtrHid::cClear(int ctrNum)
{
cLoad(ctrNum, CRT_LOAD, 0);
}
unsigned long long CtrHid::cRead(int ctrNum, CounterRegisterType regType)
{
check_CRead_Args(ctrNum, regType);
return cIn(ctrNum);
}
} /* namespace ul */

32
src/hid/ctr/CtrHid.h Normal file
View File

@ -0,0 +1,32 @@
/*
* CtrHid.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_CTR_CTRHID_H_
#define HID_CTR_CTRHID_H_
#include "CtrHidBase.h"
namespace ul
{
class UL_LOCAL CtrHid: public CtrHidBase
{
public:
CtrHid(const HidDaqDevice& daqDevice, int numCtrs);
virtual ~CtrHid();
virtual unsigned long long cIn(int ctrNum);
void cLoad(int ctrNum, CounterRegisterType regType, unsigned long long loadValue);
virtual void cClear(int ctrNum);
virtual unsigned long long cRead(int ctrNum, CounterRegisterType regType);
private:
enum { CMD_CINIT = 0x20, CMD_CIN = 0x21 };
};
} /* namespace ul */
#endif /* HID_CTR_CTRHID_H_ */

View File

@ -0,0 +1,23 @@
/*
* CtrHidBase.cpp
*
* Author: Measurement Computing Corporation
*/
#include "CtrHidBase.h"
namespace ul
{
CtrHidBase::CtrHidBase(const HidDaqDevice& daqDevice): CtrDevice(daqDevice), mHidDevice(daqDevice)
{
}
CtrHidBase::~CtrHidBase()
{
}
} /* namespace ul */

30
src/hid/ctr/CtrHidBase.h Normal file
View File

@ -0,0 +1,30 @@
/*
* CtrHidBase.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_CTR_CTRHIDBASE_H_
#define HID_CTR_CTRHIDBASE_H_
#include "../HidDaqDevice.h"
#include "../../CtrDevice.h"
namespace ul
{
class UL_LOCAL CtrHidBase: public CtrDevice
{
public:
CtrHidBase(const HidDaqDevice& daqDevice);
virtual ~CtrHidBase();
const HidDaqDevice& daqDev() const {return mHidDevice;}
private:
const HidDaqDevice& mHidDevice;
};
} /* namespace ul */
#endif /* HID_CTR_CTRHIDBASE_H_ */

View File

@ -0,0 +1,79 @@
/*
* CtrUsbDio24.cpp
*
* Created on: Oct 10, 2018
* Author: mcc
*/
#include "CtrUsbDio24.h"
#include "../UsbDio24.h"
namespace ul
{
CtrUsbDio24::CtrUsbDio24(const HidDaqDevice& daqDevice, int numCtrs) : CtrHidBase(daqDevice)
{
mCtrInfo.hasPacer(false);
mCtrInfo.setResolution(32);
for(int ctr = 0; ctr < numCtrs; ctr++)
mCtrInfo.addCtr(CMT_COUNT);
mCtrInfo.setRegisterTypes(CRT_COUNT | CRT_LOAD);
}
CtrUsbDio24::~CtrUsbDio24()
{
}
unsigned long long CtrUsbDio24::cIn(int ctrNum)
{
unsigned int count = 0;
check_CIn_Args(ctrNum);
unsigned char outBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
unsigned char inBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
outBuffer[1] = CMD_CIN;
size_t outBufLen = sizeof(outBuffer);
size_t inBufLen = sizeof(inBuffer);
daqDev().queryRawCmd(outBuffer, outBufLen, inBuffer, &inBufLen);
count = Endian::Instance().le_ptr_to_cpu_ui32(inBuffer);
return count;
}
void CtrUsbDio24::cLoad(int ctrNum, CounterRegisterType regType, unsigned long long loadValue)
{
check_CLoad_Args(ctrNum, regType, loadValue);
if(loadValue != 0)
throw UlException(ERR_BAD_CTR_VAL);
unsigned char buffer[UsbDio24::MAX_PACKET_SIZE] = {0};
buffer[1] = CMD_CINIT;
size_t length = sizeof(buffer);
daqDev().sendRawCmd(buffer, &length);
}
void CtrUsbDio24::cClear(int ctrNum)
{
cLoad(ctrNum, CRT_LOAD, 0);
}
unsigned long long CtrUsbDio24::cRead(int ctrNum, CounterRegisterType regType)
{
check_CRead_Args(ctrNum, regType);
return cIn(ctrNum);
}
} /* namespace ul */

33
src/hid/ctr/CtrUsbDio24.h Normal file
View File

@ -0,0 +1,33 @@
/*
* CtrUsbDio24.h
*
* Created on: Oct 10, 2018
* Author: mcc
*/
#ifndef HID_CTR_CTRUSBDIO24_H_
#define HID_CTR_CTRUSBDIO24_H_
#include "CtrHidBase.h"
namespace ul
{
class UL_LOCAL CtrUsbDio24: public CtrHidBase
{
public:
CtrUsbDio24(const HidDaqDevice& daqDevice, int numCtrs);
virtual ~CtrUsbDio24();
virtual unsigned long long cIn(int ctrNum);
void cLoad(int ctrNum, CounterRegisterType regType, unsigned long long loadValue);
virtual void cClear(int ctrNum);
virtual unsigned long long cRead(int ctrNum, CounterRegisterType regType);
private:
enum { CMD_CIN = 0x04, CMD_CINIT = 0x05};
};
} /* namespace ul */
#endif /* HID_CTR_CTRUSBDIO24_H_ */

117
src/hid/dio/DioHidAux.cpp Normal file
View File

@ -0,0 +1,117 @@
/*
* DioHidAux.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioHidAux.h"
namespace ul
{
DioHidAux::DioHidAux(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
mDioInfo.addPort(0, AUXPORT0, 8, DPIOT_BITIO);
}
DioHidAux::~DioHidAux()
{
}
void DioHidAux::initialize()
{
try
{
initPortsDirectionMask();
dConfigPort(AUXPORT0, DD_INPUT);
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
void DioHidAux::dConfigPort(DigitalPortType portType, DigitalDirection direction)
{
check_DConfigPort_Args(portType, direction);
unsigned char dir;
if (direction == DD_OUTPUT)
dir = 0;
else
dir = 1;
daqDev().sendCmd(CMD_DCONFIG_PORT, dir);
setPortDirection(portType, direction);
}
void DioHidAux::dConfigBit(DigitalPortType portType, int bitNum, DigitalDirection direction)
{
check_DConfigBit_Args(portType, bitNum, direction);
unsigned char dir;
if(direction == DD_OUTPUT)
dir = 0;
else
dir = 1;
daqDev().sendCmd(CMD_DCONFIG_BIT, (unsigned char) bitNum, dir);
setBitDirection(portType, bitNum, direction);
}
unsigned long long DioHidAux::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
daqDev().queryCmd(CMD_DIN, &portValue);
return portValue;
}
void DioHidAux::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
unsigned char val = data;
daqDev().sendCmd(CMD_DOUT, val);
}
bool DioHidAux::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
daqDev().queryCmd(CMD_DBITIN, (unsigned char) bitNum, &bitValue);
return bitValue? true : false;
}
void DioHidAux::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
unsigned char bitVal = bitValue ? 1 : 0;
daqDev().sendCmd(CMD_DBITOUT, (unsigned char) bitNum, bitVal);
}
unsigned long DioHidAux::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
mask.set();
return mask.to_ulong();
}
} /* namespace ul */

41
src/hid/dio/DioHidAux.h Normal file
View File

@ -0,0 +1,41 @@
/*
* DioHidAux.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DioHidAux_H_
#define HID_DIO_DioHidAux_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioHidAux: public DioHidBase
{
public:
DioHidAux(const HidDaqDevice& daqDevice);
virtual ~DioHidAux();
virtual void initialize();
virtual void dConfigPort(DigitalPortType portType, DigitalDirection direction);
virtual void dConfigBit(DigitalPortType portType, int bitNum, DigitalDirection direction);
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
private:
enum {CMD_DCONFIG_PORT = 0x01, CMD_DCONFIG_BIT = 0x02, CMD_DIN = 0x03, CMD_DOUT = 0x04, CMD_DBITIN = 0x05, CMD_DBITOUT = 0x06};
};
} /* namespace ul */
#endif /* HID_DIO_DioHidAux_H_ */

View File

@ -0,0 +1,23 @@
/*
* DioHidBase.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioHidBase.h"
namespace ul
{
DioHidBase::DioHidBase(const HidDaqDevice& daqDevice) : DioDevice(daqDevice), mHidDevice(daqDevice)
{
}
DioHidBase::~DioHidBase()
{
}
} /* namespace ul */

30
src/hid/dio/DioHidBase.h Normal file
View File

@ -0,0 +1,30 @@
/*
* DioHidBase.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOHIDBASE_H_
#define HID_DIO_DIOHIDBASE_H_
#include "../HidDaqDevice.h"
#include "../../DioDevice.h"
namespace ul
{
class UL_LOCAL DioHidBase: public DioDevice
{
public:
DioHidBase(const HidDaqDevice& daqDevice);
virtual ~DioHidBase();
const HidDaqDevice& daqDev() const {return mHidDevice;}
private:
const HidDaqDevice& mHidDevice;
};
} /* namespace ul */
#endif /* HID_DIO_DIOHIDBASE_H_ */

219
src/hid/dio/DioUsbDio24.cpp Normal file
View File

@ -0,0 +1,219 @@
/*
* DioUsbDio24.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioUsbDio24.h"
#include "../UsbDio24.h"
namespace ul
{
DioUsbDio24::DioUsbDio24(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
mDioInfo.addPort(0, FIRSTPORTA, 8, DPIOT_IO);
mDioInfo.addPort(1, FIRSTPORTB, 8, DPIOT_IO);
mDioInfo.addPort(2, FIRSTPORTCL, 4, DPIOT_IO);
mDioInfo.addPort(3, FIRSTPORTCH, 4, DPIOT_IO);
mPortCLVal = 0;
mPortCHVal = 0;
}
DioUsbDio24::~DioUsbDio24()
{
}
void DioUsbDio24::initialize()
{
try
{
initPortsDirectionMask();
for(unsigned int portNum = 0; portNum < mDioInfo.getNumPorts(); portNum++)
dConfigPort(mDioInfo.getPortType(portNum), DD_INPUT);
mPortCLVal = 0;
mPortCHVal = 0;
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
void DioUsbDio24::dConfigPort(DigitalPortType portType, DigitalDirection direction)
{
check_DConfigPort_Args(portType, direction);
unsigned char buffer[UsbDio24::MAX_PACKET_SIZE] = {0};
buffer[1] = CMD_DCONFIG;
buffer[2] = getPortCode(portType);
buffer[3] = (direction == DD_INPUT)? 1 : 0;
size_t length = sizeof(buffer);
daqDev().sendRawCmd(buffer, &length);
setPortDirection(portType, direction);
if(direction == DD_INPUT)
{
if(portType == FIRSTPORTCL)
mPortCLVal = 0;
else if(portType == FIRSTPORTCH)
mPortCHVal = 0;
}
}
unsigned long long DioUsbDio24::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
unsigned char outBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
unsigned char inBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
outBuffer[1] = CMD_DIN;
outBuffer[2] = getPortCode(portType);
size_t outBufLen = sizeof(outBuffer);
size_t inBufLen = sizeof(inBuffer);
daqDev().queryRawCmd(outBuffer, outBufLen, inBuffer, &inBufLen);
portValue = inBuffer[0];
if(portType == FIRSTPORTCL)
portValue &= 0x0f;
else if(portType == FIRSTPORTCH)
portValue >>= 4;
return portValue;
}
void DioUsbDio24::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
unsigned char val = data & 0xff;
if(portType == FIRSTPORTCL)
{
mPortCLVal = val & 0x0f;
val = val | (mPortCHVal << 4);
}
else if(portType == FIRSTPORTCH)
{
mPortCHVal = val & 0x0f;
val = (val << 4) | mPortCLVal;
}
unsigned char buffer[UsbDio24::MAX_PACKET_SIZE] = {0};
buffer[1] = CMD_DOUT;
buffer[2] = getPortCode(portType);
buffer[3] = val;
size_t length = sizeof(buffer);
daqDev().sendRawCmd(buffer, &length);
}
bool DioUsbDio24::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
unsigned char outBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
unsigned char inBuffer[UsbDio24::MAX_PACKET_SIZE] = {0};
unsigned char bit = bitNum;
if(portType == FIRSTPORTCH)
bit +=4;
outBuffer[1] = CMD_BITIN;
outBuffer[2] = getPortCode(portType);
outBuffer[3] = bit;
size_t outBufLen = sizeof(outBuffer);
size_t inBufLen = sizeof(inBuffer);
daqDev().queryRawCmd(outBuffer, outBufLen, inBuffer, &inBufLen);
bitValue = inBuffer[0] & 0x01;
return bitValue? true : false;
}
void DioUsbDio24::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
unsigned char bit = bitNum;
if(portType == FIRSTPORTCH)
bit +=4;
unsigned char bitVal = bitValue ? 1 : 0;
unsigned char buffer[UsbDio24::MAX_PACKET_SIZE] = {0};
buffer[1] = CMD_BITOUT;
buffer[2] = getPortCode(portType);
buffer[3] = bit;
buffer[4] = bitVal;
size_t length = sizeof(buffer);
daqDev().sendRawCmd(buffer, &length);
}
unsigned char DioUsbDio24::getPortCode(DigitalPortType portType) const
{
unsigned char code = 0;
switch(portType)
{
case FIRSTPORTA:
code = 1;
break;
case FIRSTPORTB:
code = 4;
break;
case FIRSTPORTCL:
code = 8;
break;
case FIRSTPORTCH:
code = 2;
break;
default:
code = 0;
break;
}
return code;
}
void DioUsbDio24::setCfg_PortInitialOutputVal(unsigned int portNum, unsigned long long val)
{
if(daqDev().getDeviceType() == DaqDeviceId::USB_1024LS || daqDev().getDeviceType() == DaqDeviceId::USB_DIO24)
throw UlException(ERR_CONFIG_NOT_SUPPORTED);
DioDevice::setCfg_PortInitialOutputVal(portNum, val);
}
unsigned long DioUsbDio24::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
mask.set();
return mask.to_ulong();
}
} /* namespace ul */

45
src/hid/dio/DioUsbDio24.h Normal file
View File

@ -0,0 +1,45 @@
/*
* DioUsbDio24.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOUSBDIO24_H_
#define HID_DIO_DIOUSBDIO24_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioUsbDio24: public DioHidBase
{
public:
DioUsbDio24(const HidDaqDevice& daqDevice);
virtual ~DioUsbDio24();
virtual void initialize();
virtual void dConfigPort(DigitalPortType portType, DigitalDirection direction);
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
////////////////////// Configuration functions /////////////////////////////////
virtual void setCfg_PortInitialOutputVal(unsigned int portNum, unsigned long long val);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
unsigned char getPortCode(DigitalPortType portType) const;
private:
enum {CMD_DIN = 0, CMD_DOUT = 1, CMD_BITIN = 0x02, CMD_BITOUT = 0x03, CMD_DCONFIG = 0x0D};
unsigned char mPortCLVal;
unsigned char mPortCHVal;
};
} /* namespace ul */
#endif /* HID_DIO_DIOUSBDIO24_H_ */

View File

@ -0,0 +1,217 @@
/*
* DioUsbDio96h.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioUsbDio96h.h"
namespace ul
{
DioUsbDio96h::DioUsbDio96h(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
mNewMicro = false;
addPorts();
}
DioUsbDio96h::~DioUsbDio96h()
{
}
void DioUsbDio96h::initialize()
{
unsigned short rawFwVer = daqDev().getRawFwVer();
if(rawFwVer < 0x200)
mNewMicro = false;
else
mNewMicro = true;
try
{
initPortsDirectionMask();
// set the ports to input mode if fw version is less than 2.0
if(!mNewMicro)
{
for(unsigned int portNum = 0; portNum < mDioInfo.getNumPorts(); portNum++)
dConfigPort(mDioInfo.getPortType(portNum), DD_INPUT);
}
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
void DioUsbDio96h::dConfigPort(DigitalPortType portType, DigitalDirection direction)
{
check_DConfigPort_Args(portType, direction);
unsigned char portNum = mDioInfo.getPortNum(portType);
unsigned char dir;
if (direction == DD_OUTPUT)
dir = 0;
else
dir = 1;
daqDev().sendCmd(CMD_DCONFIG_PORT, portNum, dir);
setPortDirection(portType, direction);
}
unsigned long long DioUsbDio96h::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
unsigned char portNum = mDioInfo.getPortNum(portType);
daqDev().queryCmd(CMD_DIN, portNum, &portValue);
return portValue;
}
void DioUsbDio96h::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
unsigned short portNum = mDioInfo.getPortNum(portType);
unsigned char val = data;
daqDev().sendCmd(CMD_DOUT, portNum, val);
}
void DioUsbDio96h::dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DInArray_Args(lowPort, highPort, data);
unsigned char portVals[16];
daqDev().queryCmd(CMD_GET_ALL, portVals, sizeof(portVals), 2000);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
data[i] = portVals[portNum];
i++;
}
}
void DioUsbDio96h::dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DOutArray_Args(lowPort, highPort, data);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
if(mNewMicro)
{
unsigned char portVals[16] = {0};
unsigned short portsMask = 0;
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
portVals[portNum] = data[i];
portsMask |= 1 << portNum;
i++;
}
daqDev().sendCmd(CMD_DOUT_MULTIPLE, portsMask, portVals, sizeof(portVals));
}
else
{
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
dOut(mDioInfo.getPortType(portNum), data[i]);
i++;
}
}
}
bool DioUsbDio96h::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
unsigned char portNum = mDioInfo.getPortNum(portType);
daqDev().queryCmd(CMD_DBITIN, portNum, bitNum, &bitValue);
return bitValue? true : false;
}
void DioUsbDio96h::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
unsigned char portNum = mDioInfo.getPortNum(portType);
unsigned char bitVal = bitValue ? 1 : 0;
daqDev().sendCmd(CMD_DBITOUT, portNum, (unsigned char) bitNum, bitVal);
}
unsigned long DioUsbDio96h::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
mask.set();
if(mNewMicro)
{
unsigned char cmd = CMD_DCONFIG_PORT_R;
unsigned short portsDir = 0;
daqDev().queryCmd(cmd, &portsDir);
std::bitset<16> portsDirMask(portsDir);
if(portsDirMask[portNum])
mask.set();
else
mask.reset();
}
return mask.to_ulong();
}
void DioUsbDio96h::addPorts()
{
mDioInfo.addPort(0, FIRSTPORTA, 8, DPIOT_IO);
mDioInfo.addPort(1, FIRSTPORTB, 8, DPIOT_IO);
mDioInfo.addPort(2, FIRSTPORTCL, 4, DPIOT_IO);
mDioInfo.addPort(3, FIRSTPORTCH, 4, DPIOT_IO);
mDioInfo.addPort(4, SECONDPORTA, 8, DPIOT_IO);
mDioInfo.addPort(5, SECONDPORTB, 8, DPIOT_IO);
mDioInfo.addPort(6, SECONDPORTCL, 4, DPIOT_IO);
mDioInfo.addPort(7, SECONDPORTCH, 4, DPIOT_IO);
mDioInfo.addPort(8, THIRDPORTA, 8, DPIOT_IO);
mDioInfo.addPort(9, THIRDPORTB, 8, DPIOT_IO);
mDioInfo.addPort(10, THIRDPORTCL, 4, DPIOT_IO);
mDioInfo.addPort(11, THIRDPORTCH, 4, DPIOT_IO);
mDioInfo.addPort(12, FOURTHPORTA, 8, DPIOT_IO);
mDioInfo.addPort(13, FOURTHPORTB, 8, DPIOT_IO);
mDioInfo.addPort(14, FOURTHPORTCL, 4, DPIOT_IO);
mDioInfo.addPort(15, FOURTHPORTCH, 4, DPIOT_IO);
}
} /* namespace ul */

View File

@ -0,0 +1,48 @@
/*
* DioUsbDio96h.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOUSBDIO96H_H_
#define HID_DIO_DIOUSBDIO96H_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioUsbDio96h: public DioHidBase
{
public:
DioUsbDio96h(const HidDaqDevice& daqDevice);
virtual ~DioUsbDio96h();
virtual void initialize();
virtual void dConfigPort(DigitalPortType portType, DigitalDirection direction);
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual void dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual void dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
private:
void addPorts();
private:
enum {CMD_DCONFIG_PORT = 0x01, CMD_DIN = 0x03, CMD_DOUT = 0x04, CMD_DBITIN = 0x05, CMD_DBITOUT = 0x06,
CMD_DCONFIG_PORT_R = 0x09, CMD_DOUT_MULTIPLE = 0x0C, CMD_GET_ALL = 0x46};
bool mNewMicro;
};
} /* namespace ul */
#endif /* HID_DIO_DIOUSBDIO96H_H_ */

129
src/hid/dio/DioUsbErbxx.cpp Normal file
View File

@ -0,0 +1,129 @@
/*
* DioUsbErbxx.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioUsbErbxx.h"
namespace ul
{
DioUsbErbxx::DioUsbErbxx(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
if(daqDevice.getDeviceType() == DaqDeviceId::USB_ERB08)
{
mDioInfo.addPort(0, FIRSTPORTCL, 4, DPIOT_NONCONFIG);
mDioInfo.addPort(1, FIRSTPORTCH, 4, DPIOT_NONCONFIG);
mPortOffset = 2;
}
else
{
mDioInfo.addPort(0, FIRSTPORTA, 8, DPIOT_NONCONFIG);
mDioInfo.addPort(1, FIRSTPORTB, 8, DPIOT_NONCONFIG);
mDioInfo.addPort(2, FIRSTPORTCL, 4, DPIOT_NONCONFIG);
mDioInfo.addPort(3, FIRSTPORTCH, 4, DPIOT_NONCONFIG);
mPortOffset = 0;
}
}
DioUsbErbxx::~DioUsbErbxx()
{
}
void DioUsbErbxx::initialize()
{
try
{
initPortsDirectionMask();
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
unsigned long long DioUsbErbxx::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
daqDev().queryCmd(CMD_DIN, portNum, &portValue);
return portValue;
}
void DioUsbErbxx::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
unsigned short portNum = mDioInfo.getPortNum(portType) + mPortOffset;
unsigned char val = data;
daqDev().sendCmd(CMD_DOUT, portNum, val);
}
bool DioUsbErbxx::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
daqDev().queryCmd(CMD_DBITIN, portNum, bitNum, &bitValue);
return bitValue? true : false;
}
void DioUsbErbxx::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
unsigned char bitVal = bitValue ? 1 : 0;
daqDev().sendCmd(CMD_DBITOUT, portNum, (unsigned char) bitNum, bitVal);
}
unsigned long long DioUsbErbxx::getCfg_PortLogic(unsigned int portNum)
{
if(portNum >= mDioInfo.getNumPorts())
throw UlException(ERR_BAD_PORT_INDEX);
unsigned long long logic = 0; // non-invert
unsigned char cmd = CMD_STATUS;
unsigned short status = 0;
daqDev().queryCmd(cmd, &status);
std::bitset<16> statusMask(status);
int bitIdx = portNum + mPortOffset;
if(statusMask[bitIdx] == 0)
logic = 1;
return logic;
}
unsigned long DioUsbErbxx::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
mask.reset();
return mask.to_ulong();
}
} /* namespace ul */

42
src/hid/dio/DioUsbErbxx.h Normal file
View File

@ -0,0 +1,42 @@
/*
* DioUsbErbxx.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOUSBERBXX_H_
#define HID_DIO_DIOUSBERBXX_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioUsbErbxx: public DioHidBase
{
public:
DioUsbErbxx(const HidDaqDevice& daqDevice);
virtual ~DioUsbErbxx();
virtual void initialize();
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
virtual unsigned long long getCfg_PortLogic(unsigned int portNum);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
private:
enum {CMD_DIN = 0x03, CMD_DOUT = 0x04, CMD_DBITIN = 0x05, CMD_DBITOUT = 0x06, CMD_STATUS = 0x44};
unsigned char mPortOffset;
};
} /* namespace ul */
#endif /* HID_DIO_DIOUSBERBXX_H_ */

View File

@ -0,0 +1,124 @@
/*
* DioUsbPdiso8.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioUsbPdiso8.h"
namespace ul
{
DioUsbPdiso8::DioUsbPdiso8(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
mDioInfo.addPort(0, AUXPORT0, 8, DPIOT_NONCONFIG);
mDioInfo.addPort(1, AUXPORT1, 8, DPIOT_IN);
}
DioUsbPdiso8::~DioUsbPdiso8()
{
}
void DioUsbPdiso8::initialize()
{
try
{
initPortsDirectionMask();
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
unsigned long long DioUsbPdiso8::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
unsigned char portNum = mDioInfo.getPortNum(portType);
daqDev().queryCmd(CMD_DIN, portNum, &portValue);
return portValue;
}
void DioUsbPdiso8::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
unsigned short portNum = mDioInfo.getPortNum(portType);
unsigned char val = data;
daqDev().sendCmd(CMD_DOUT, portNum, val);
}
bool DioUsbPdiso8::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
unsigned char portNum = mDioInfo.getPortNum(portType);
daqDev().queryCmd(CMD_DBITIN, portNum, bitNum, &bitValue);
return bitValue? true : false;
}
void DioUsbPdiso8::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
unsigned char portNum = mDioInfo.getPortNum(portType);
unsigned char bitVal = bitValue ? 1 : 0;
daqDev().sendCmd(CMD_DBITOUT, portNum, (unsigned char) bitNum, bitVal);
}
unsigned long long DioUsbPdiso8::getCfg_PortIsoMask(unsigned int portNum)
{
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
unsigned char mask = 0;
portNum = FILTER_PORT;
daqDev().queryCmd(CMD_DIN, portNum, &mask);
mask = ~mask;
return mask;
}
void DioUsbPdiso8::DioUsbPdiso8::setCfg_PortIsoMask(unsigned int portNum, unsigned long long mask)
{
if(!mDaqDevice.isConnected())
throw UlException(ERR_NO_CONNECTION_ESTABLISHED);
portNum = FILTER_PORT;
unsigned char val = ~mask;
daqDev().sendCmd(CMD_DOUT, portNum, val);
}
unsigned long DioUsbPdiso8::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
if(portNum == 0)
mask.reset();
else
mask.set();
return mask.to_ulong();
}
} /* namespace ul */

View File

@ -0,0 +1,42 @@
/*
* DioUsbPdiso8.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOUSBPDISO8_H_
#define HID_DIO_DIOUSBPDISO8_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioUsbPdiso8: public DioHidBase
{
public:
DioUsbPdiso8(const HidDaqDevice& daqDevice);
virtual ~DioUsbPdiso8();
virtual void initialize();
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
virtual unsigned long long getCfg_PortIsoMask(unsigned int portNum);
virtual void setCfg_PortIsoMask(unsigned int portNum, unsigned long long mask);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
private:
enum {RELAY_PORT = 0x00, INPUT_PORT = 0x01, FILTER_PORT = 0x02};
enum {CMD_DIN = 0x03, CMD_DOUT = 0x04, CMD_DBITIN = 0x05, CMD_DBITOUT = 0x06};
};
} /* namespace ul */
#endif /* HID_DIO_DIOUSBPDISO8_H_ */

222
src/hid/dio/DioUsbSsrxx.cpp Normal file
View File

@ -0,0 +1,222 @@
/*
* DioUsbSsrxx.cpp
*
* Author: Measurement Computing Corporation
*/
#include "DioUsbSsrxx.h"
namespace ul
{
DioUsbSsrxx::DioUsbSsrxx(const HidDaqDevice& daqDevice) : DioHidBase(daqDevice)
{
if(daqDevice.getDeviceType() == DaqDeviceId::USB_SSR08)
{
mDioInfo.addPort(0, FIRSTPORTCL, 4, DPIOT_NONCONFIG);
mDioInfo.addPort(1, FIRSTPORTCH, 4, DPIOT_NONCONFIG);
mPortOffset = 2;
}
else
{
mDioInfo.addPort(0, FIRSTPORTA, 8, DPIOT_NONCONFIG);
mDioInfo.addPort(1, FIRSTPORTB, 8, DPIOT_NONCONFIG);
mDioInfo.addPort(2, FIRSTPORTCL, 4, DPIOT_NONCONFIG);
mDioInfo.addPort(3, FIRSTPORTCH, 4, DPIOT_NONCONFIG);
mPortOffset = 0;
}
mNewMicro = false;
}
DioUsbSsrxx::~DioUsbSsrxx()
{
}
void DioUsbSsrxx::initialize()
{
unsigned short rawFwVer = daqDev().getRawFwVer();
if(rawFwVer < 0x200)
mNewMicro = false;
else
mNewMicro = true;
try
{
initPortsDirectionMask();
}
catch(UlException& e)
{
UL_LOG("Ul exception occurred: " << e.what());
}
}
unsigned long long DioUsbSsrxx::dIn(DigitalPortType portType)
{
unsigned char portValue = 0;
check_DIn_Args(portType);
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
daqDev().queryCmd(CMD_DIN, portNum, &portValue);
return portValue;
}
void DioUsbSsrxx::dOut(DigitalPortType portType, unsigned long long data)
{
check_DOut_Args(portType, data);
std::bitset<32> portDirectionMask = getPortDirection(portType);
if(portDirectionMask.any())
throw UlException(ERR_WRONG_DIG_CONFIG);
unsigned short portNum = mDioInfo.getPortNum(portType) + mPortOffset;
unsigned char val = data;
daqDev().sendCmd(CMD_DOUT, portNum, val);
}
void DioUsbSsrxx::dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DInArray_Args(lowPort, highPort, data);
unsigned char portVals[4];
daqDev().queryCmd(CMD_GET_ALL, portVals, sizeof(portVals), 2000);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
data[i] = portVals[portNum + mPortOffset];
i++;
}
}
void DioUsbSsrxx::dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[])
{
check_DOutArray_Args(lowPort, highPort, data);
unsigned int lowPortNum = mDioInfo.getPortNum(lowPort);
unsigned int highPortNum = mDioInfo.getPortNum(highPort);
std::bitset<32> portDirectionMask;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
portDirectionMask = getPortDirection(mDioInfo.getPortType(portNum));
if(portDirectionMask.any())
throw UlException(ERR_WRONG_DIG_CONFIG);
}
if(mNewMicro)
{
unsigned char portVals[4] = {0};
unsigned short portsMask = 0;
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
portVals[portNum + mPortOffset] = data[i];
portsMask |= 1 << (portNum + mPortOffset);
i++;
}
daqDev().sendCmd(CMD_DOUT_MULTIPLE, portsMask, portVals, sizeof(portVals));
}
else
{
int i = 0;
for(unsigned int portNum = lowPortNum; portNum <= highPortNum; portNum++)
{
dOut(mDioInfo.getPortType(portNum), data[i]);
i++;
}
}
}
bool DioUsbSsrxx::dBitIn(DigitalPortType portType, int bitNum)
{
check_DBitIn_Args(portType, bitNum);
unsigned char bitValue = 0;
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
daqDev().queryCmd(CMD_DBITIN, portNum, bitNum, &bitValue);
return bitValue? true : false;
}
void DioUsbSsrxx::dBitOut(DigitalPortType portType, int bitNum, bool bitValue)
{
check_DBitOut_Args(portType, bitNum);
std::bitset<32> portDirectionMask = getPortDirection(portType);
if(portDirectionMask[bitNum])
throw UlException(ERR_WRONG_DIG_CONFIG);
unsigned char portNum = mDioInfo.getPortNum(portType) + mPortOffset;
unsigned char bitVal = bitValue ? 1 : 0;
daqDev().sendCmd(CMD_DBITOUT, portNum, (unsigned char) bitNum, bitVal);
}
unsigned long long DioUsbSsrxx::getCfg_PortLogic(unsigned int portNum)
{
if(portNum >= mDioInfo.getNumPorts())
throw UlException(ERR_BAD_PORT_INDEX);
unsigned long long logic = 0; // non-invert
unsigned char cmd = CMD_STATUS;
unsigned short status = 0;
daqDev().queryCmd(cmd, &status);
std::bitset<16> statusMask(status);
int bitIdx = portNum + mPortOffset + 4;
if(statusMask[bitIdx] == 0)
logic = 1;
return logic;
}
unsigned long DioUsbSsrxx::readPortDirMask(unsigned int portNum) const
{
std::bitset<8> mask;
unsigned char cmd = CMD_STATUS;
unsigned short status = 0;
daqDev().queryCmd(cmd, &status);
std::bitset<16> statusMask(status);
int bitIdx = portNum + mPortOffset;
if(statusMask[bitIdx])
mask.set();
else
mask.reset();
return mask.to_ulong();
}
} /* namespace ul */

46
src/hid/dio/DioUsbSsrxx.h Normal file
View File

@ -0,0 +1,46 @@
/*
* DioUsbSsrxx.h
*
* Author: Measurement Computing Corporation
*/
#ifndef HID_DIO_DIOUSBSSRXX_H_
#define HID_DIO_DIOUSBSSRXX_H_
#include "DioHidBase.h"
namespace ul
{
class UL_LOCAL DioUsbSsrxx: public DioHidBase
{
public:
DioUsbSsrxx(const HidDaqDevice& daqDevice);
virtual ~DioUsbSsrxx();
virtual void initialize();
virtual unsigned long long dIn(DigitalPortType portType);
virtual void dOut(DigitalPortType portType, unsigned long long data);
virtual void dInArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual void dOutArray(DigitalPortType lowPort, DigitalPortType highPort, unsigned long long data[]);
virtual bool dBitIn(DigitalPortType portType, int bitNum);
virtual void dBitOut(DigitalPortType portType, int bitNum, bool bitValue);
virtual unsigned long long getCfg_PortLogic(unsigned int portNum);
protected:
virtual unsigned long readPortDirMask(unsigned int portNum) const;
private:
enum {CMD_DIN = 0x03, CMD_DOUT = 0x04, CMD_DBITIN = 0x05, CMD_DBITOUT = 0x06, CMD_DOUT_MULTIPLE = 0x0C,
CMD_STATUS = 0x44, CMD_GET_ALL = 0x46};
unsigned char mPortOffset;
bool mNewMicro;
};
} /* namespace ul */
#endif /* HID_DIO_DIOUSBSSRXX_H_ */

1687
src/hid/hid_linux.cpp Normal file

File diff suppressed because it is too large Load Diff

1126
src/hid/hid_mac.cpp Normal file

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More