#!/bin/ch #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <sys/time.h> #include <chplot.h> #include "DIO96.h" #include "control.h" #define DATABUF 2 #define DATAPOINTS 10000 int main() { unsigned char buf[DATABUF], data_ready; struct timeval tv; fd_set rfds; int retval, fd0, fd1, ctl, sem, n, i, NumPoints = DATAPOINTS, ViewSignal = 13; struct msg_struct msg; class CPlot plot; /* OPEN THE FIFOS */ if ((fd0 = open("/dev/rtf0", O_RDONLY)) == NULL) { fprintf(stderr, "Error opening /dev/rtf0\n"); exit(-1); } if ((fd1 = open("/dev/rtf1", O_RDONLY)) == NULL) { fprintf(stderr, "Error opening /dev/rtf1\n"); close(fd0); exit(-1); } if ((ctl = open("/dev/rtf2", O_WRONLY)) == NULL) { fprintf(stderr, "Error opening /dev/rtf2\n"); close(fd0); close(fd1); exit(-1); } if ((sem = open("/dev/rtf4", O_RDONLY)) == NULL) { fprintf(stderr, "Error opening /dev/rtf4\n"); close(fd0); close(fd1); close(ctl); exit(-1); } /* SETUP THE START MESSAGE */ msg.command = START_TASK; msg.period = TICK_RESOLUTION; /* 1ns per tick */ msg.conf = DIO96_CONF; msg.buffer_size = DATABUF; msg.dataPts = NumPoints; /* SEND THE MESSAGE */ if (write(ctl, &msg, sizeof(msg)) < 0) { fprintf(stderr, "Can't send a command to RT-task\n"); close(fd0); close(fd1); close(ctl); close(sem); exit(-1); } /* CREATE BUFFER TO STORE THE DATA */ unsigned char Signal[NumPoints]; int x[NumPoints]; for(i=0; i<NumPoints; i++) { Signal[i]=0; x[i]=0; } /* ACQUIRE THE DATA */ for(i=0; i<NumPoints; i++) { FD_ZERO(&rfds); FD_SET(sem, &rfds); tv.tv_sec = 2; tv.tv_usec = 0; retval = select(sem+1, &rfds, NULL, NULL, &tv); if (retval > 0) { n = read(sem, &data_ready, 1); if(data_ready==0x00) read(fd0, buf, DATABUF); if(data_ready==0x01) read(fd1, buf, DATABUF); if(ViewSignal > 7) Signal[i] = (buf[1] & 1<<(ViewSignal-8)) >> (ViewSignal-8); else Signal[i] = (buf[0] & 1<<ViewSignal) >> ViewSignal; x[i] = i; } } /* PLOT INFO TO TEMPORARY FILE */ plot.data2D(x, Signal); plot.plotType(PLOT_PLOTTYPE_STEPS, 0, 1, 1); plot.title("Signal Output"); plot.label(PLOT_AXIS_Y, "Signal"); plot.label(PLOT_AXIS_X, "Data Point"); plot.axisRange(PLOT_AXIS_Y, -0.1, 1.1); plot.plotting(); /* CLOSE THE OPENED FIFOS */ close(fd0); close(fd1); close(ctl); close(sem); return 0; }