diff --git a/include/villas/nodes/uldaq.h b/include/villas/nodes/uldaq.h new file mode 100644 index 000000000..9e8071a19 --- /dev/null +++ b/include/villas/nodes/uldaq.h @@ -0,0 +1,44 @@ +/** Node-type for uldaq connections. + * + * @file + * @author Manuel Pitz + * @author Steffen Vogel + * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +/** + * @ingroup node + * @addtogroup uldaq Read USB analog to digital converters + * @{ + */ + +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +/** @} */ \ No newline at end of file diff --git a/lib/nodes/uldaq.c b/lib/nodes/uldaq.c new file mode 100644 index 000000000..09cf903a8 --- /dev/null +++ b/lib/nodes/uldaq.c @@ -0,0 +1,171 @@ +/** Node-type for uldaq connections. + * + * @file + * @author Manuel Pitz + * @author Steffen Vogel + * @copyright 2017-2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *********************************************************************************/ + +#include +#include +#include +#include +#include + +int uldaq_start(struct node *n) +{ + int ret; + + // Get descriptors for all of the available DAQ devices + err = ulGetDaqDeviceInventory(interfaceType, devDescriptors, &numDevs); + + if(err != ERR_NO_ERROR) + ret = -1; + + // verify at least one DAQ device is detected + if (numDevs == 0) + { + //printf("No DAQ devices are connected\n"); + ret = -1; + } + + // get a handle to the DAQ device associated with the first descriptor + daqDeviceHandle = ulCreateDaqDevice(devDescriptors[0]); + + if (daqDeviceHandle == 0) + { + //printf ("\nUnable to create a handle to the specified DAQ device\n"); + ret = -1; + } + + err = ulConnectDaqDevice(daqDeviceHandle); + if (err != ERR_NO_ERROR) + ret = -1; + + int chanCount = 0;//change this to use more than one channel + AiQueueElement queueArray[MAX_QUEUE_SIZE]; + for (i=0; iqueue, l->queuelen, &memory_hugepage, QUEUE_SIGNALLED_EVENTFD); +} + +int uldaq_stop(struct node *n) +{ + int ret; + + + // stop the acquisition if it is still running + if (status == SS_RUNNING && err == ERR_NO_ERROR) + { + ulAInScanStop(daqDeviceHandle); + } + + ulDisconnectDaqDevice(daqDeviceHandle); + + ulReleaseDaqDevice(daqDeviceHandle); + + if (ret) + return ret; + + return queue_signalled_destroy(&l->queue); +} + +int uldaq_read(struct node *n, struct sample *smps[], unsigned cnt, unsigned *release) +{ + int avail; + + struct loopback *l = (struct loopback *) n->_vd; + struct sample *cpys[cnt]; + + avail = queue_signalled_pull_many(&l->queue, (void **) cpys, cnt); + + for (int i = 0; i < avail; i++) { + sample_copy(smps[i], cpys[i]); + sample_decref(cpys[i]); + } + + return avail; +} + + +static struct plugin p = { + .name = "uldaq", + .description = "Read USB analog to digital converters like UL201", + .type = PLUGIN_TYPE_NODE, + .node = { + .vectorize = 0, + .flags = NODE_TYPE_PROVIDES_SIGNALS, + .size = sizeof(struct loopback), + .parse = loopback_parse, + .print = loopback_print, + .start = uldaq_start, + .stop = uldaq_stop, + .read = uldaq_read + } +}; + +REGISTER_PLUGIN(&p) +LIST_INIT_STATIC(&p.node.instances) \ No newline at end of file