Refinement alongside Digital
r1198 | dcl | 2006-10-26 18:38:13 +1000 (Thu, 26 Oct 2006) | 2 lines
This commit is contained in:
@@ -3,44 +3,15 @@
|
||||
* ANSI C program:
|
||||
* Monitor.c
|
||||
*
|
||||
* Description:
|
||||
* This program counts digital events on a NI-6602
|
||||
* Counter Input Channel. The Device, Counter Channel, Initial Count, Count
|
||||
* Direction, and are all configurable.
|
||||
*
|
||||
* Edges are counted on the counter's default input terminal (refer
|
||||
* to the I/O Connections Overview section below for more
|
||||
* information), but could easily be modified to count edges on a
|
||||
* PFI or RTSI line.
|
||||
*
|
||||
* Instructions for Running:
|
||||
* 1. Select the Device and Channel which corresponds to the counter
|
||||
* you want to count on.
|
||||
* 2. Select the TCP/IP port number you want to listen on.
|
||||
* 3. Enter the Initial Count, Count Direction, to specify how you want
|
||||
* the counter to count.
|
||||
*
|
||||
* Steps:
|
||||
* 1. Create a task.
|
||||
* 2. Create a Counter Input channel to Count Events. The Edge
|
||||
* parameter is used to determine if the counter will increment
|
||||
* on rising or falling edges.
|
||||
* 3. Call the Start function to arm the counter and begin
|
||||
* counting. The counter will be preloaded with the Initial
|
||||
* Count.
|
||||
* 4. The counter will be continually polled.
|
||||
* 5. Call the Clear Task function to clear the Task.
|
||||
* 6. Display an error if any.
|
||||
*
|
||||
*********************************************************************/
|
||||
|
||||
#define CNTR_CHK(func) if (cntr_fatal(error=(func))) goto Error; else
|
||||
#define DEVICE_CHK(func) if (device_fatal(error=(func))) goto Error; else
|
||||
|
||||
#include "Monitor.h"
|
||||
#include "utility.h"
|
||||
#include "params.h"
|
||||
#include "sock.h"
|
||||
#include "cntr.h"
|
||||
#include "device.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
@@ -54,8 +25,6 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define MAX_COUNTERS 8
|
||||
|
||||
int usage(int argc, char* argv[], const char* reason)
|
||||
{
|
||||
int i;
|
||||
@@ -74,11 +43,11 @@ int main(int argc, char* argv[])
|
||||
char errBuff[2048]={'\0'};
|
||||
struct timeval now;
|
||||
uint64 last_poll;
|
||||
char* device = DEFAULT_COUNTER_DEVICE;
|
||||
char* device = DEFAULT_DEVICE;
|
||||
uint dev_no;
|
||||
int port = DEFAULT_LISTEN_PORT;
|
||||
int idx = 1;
|
||||
COUNTER* counters[MAX_COUNTERS];
|
||||
DEVICE* devices[MAX_DEVICES];
|
||||
|
||||
if (idx >= argc)
|
||||
return usage(argc, argv, "no args");
|
||||
@@ -128,12 +97,12 @@ int main(int argc, char* argv[])
|
||||
dev_no = atoi(&device[3]);
|
||||
sock_init();
|
||||
gettimeofday(&now, NULL);
|
||||
for (idx = 0; idx < MAX_COUNTERS; ++idx)
|
||||
for (idx = 0; idx < MAX_DEVICES; ++idx)
|
||||
{
|
||||
sprintf(device, "dev%d/ctr%d", dev_no, idx);
|
||||
CNTR_CHK(cntr_init(&counters[idx], device));
|
||||
sock_listen(port + idx, cntr_command, counters[idx]);
|
||||
counters[idx]->current_time = now;
|
||||
DEVICE_CHK(device_init(&devices[idx], device));
|
||||
sock_listen(port + idx, device_command, devices[idx]);
|
||||
devices[idx]->current_time = now;
|
||||
}
|
||||
|
||||
printf("Continuously polling. Press Ctrl+C to interrupt\n");
|
||||
@@ -148,12 +117,12 @@ int main(int argc, char* argv[])
|
||||
sock_check(timeout);
|
||||
gettimeofday(&now, NULL);
|
||||
timeofday = 1000 * (uint64) now.tv_sec + now.tv_usec / 1000;
|
||||
for (idx = 0; idx < MAX_COUNTERS; ++idx)
|
||||
for (idx = 0; idx < MAX_DEVICES; ++idx)
|
||||
{
|
||||
COUNTER* cp = counters[idx];
|
||||
PARAMETERS* pp = &cp->params;
|
||||
last_poll = 1000 * (uint64) cp->current_time.tv_sec
|
||||
+ cp->current_time.tv_usec / 1000;
|
||||
DEVICE* device = devices[idx];
|
||||
PARAMETERS* pp = &device->params;
|
||||
last_poll = 1000 * (uint64) device->current_time.tv_sec
|
||||
+ device->current_time.tv_usec / 1000;
|
||||
if (timeofday / pp->poll_period > last_poll / pp->poll_period)
|
||||
timeout = 0;
|
||||
else
|
||||
@@ -170,18 +139,18 @@ int main(int argc, char* argv[])
|
||||
next_timeout = timeout;
|
||||
if (timeout == 0)
|
||||
{
|
||||
cp->current_time = now;
|
||||
device->current_time = now;
|
||||
#if 1
|
||||
dbg_printf(0, "%d:-%s %s %.3f %s %.3f %4d\n",
|
||||
idx,
|
||||
make_timestamp(&cp->current_time),
|
||||
make_timestamp(&cp->sample_timer),
|
||||
cntr_time_to_next_sample(cp),
|
||||
make_timestamp(&cp->report_timer),
|
||||
cntr_time_to_next_report(cp),
|
||||
cp->sample_index);
|
||||
make_timestamp(&device->current_time),
|
||||
make_timestamp(&device->sample_timer),
|
||||
device_time_to_next_sample(device),
|
||||
make_timestamp(&device->report_timer),
|
||||
device_time_to_next_report(device),
|
||||
device->sample_index);
|
||||
#endif
|
||||
CNTR_CHK(cntr_poll(cp));
|
||||
DEVICE_CHK(device_poll(device));
|
||||
}
|
||||
}
|
||||
if (next_timeout > 999)
|
||||
@@ -193,13 +162,13 @@ int main(int argc, char* argv[])
|
||||
|
||||
Error:
|
||||
puts("");
|
||||
if (cntr_fatal(error))
|
||||
if (device_fatal(error))
|
||||
{
|
||||
cntr_errmsg(errBuff, sizeof(errBuff));
|
||||
device_errmsg(errBuff, sizeof(errBuff));
|
||||
printf("DAQmx Error: %s\n", errBuff);
|
||||
}
|
||||
for (idx = 0; idx < MAX_COUNTERS; ++idx)
|
||||
cntr_term(counters[idx]);
|
||||
for (idx = 0; idx < MAX_DEVICES; ++idx)
|
||||
device_term(devices[idx]);
|
||||
printf("End of program\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user