Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Read Digital Input from 6521

Hi,

I´m trying to read from an digital input channel on NI 6521.

I have to read Line 0 and 1 which have different values.

Can you tell me which functions I have to use and how I can access
each value (line 0 and 1).

I tried the examples ReadDigChan and ReadDigPort, but I don´t
know how to access a single value from line 0 or line 1.


Thank you.
0 Kudos
Message 1 of 4
(5,139 Views)
Here´s the *.c-file of read digital line
 
#include <ansi_c.h>
#include <NIDAQmx.h>
#define DAQmxErrChk(functionCall) {DAQmxError = (functionCall);  {if (DAQmxError < 0){goto Error;}}}

int32 CreateDAQTaskInProject(TaskHandle *taskOut1)
{
 int32 DAQmxError = DAQmxSuccess;
    TaskHandle taskOut;
 DAQmxErrChk(DAQmxCreateTask("DAQTaskInProject", &taskOut));
 DAQmxErrChk(DAQmxCreateDIChan(taskOut, "Dev2/port0/line0",
  "DigitalIn0", DAQmx_Val_ChanPerLine));
 DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "DigitalIn0", DAQmx_DI_InvertLines,
  0));
 DAQmxErrChk(DAQmxCreateDIChan(taskOut, "Dev2/port0/line3",
  "DigitalIn1", DAQmx_Val_ChanPerLine));
 DAQmxErrChk(DAQmxSetChanAttribute(taskOut, "DigitalIn1", DAQmx_DI_InvertLines,
  0));
    *taskOut1 = taskOut;
Error:
 return DAQmxError;
}
Here´s the *.h-file
 
int32 CreateDAQTaskInProject(TaskHandle *taskOut1);
#ifdef __cplusplus
 }
#endif
#endif // ifndef DAQTASKINPROJECT_INCLUDE
 
Then later you put the *.c-function in your main *.c like here:
 
#include <nidaqmx.h>
#include <cvirte.h>  
#include <userint.h>
#include "DAQAssistantExercise.h"
#include "DAQTaskInProject.h"
static int panelHandle;
int main (int argc, char *argv[])
{
 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "DAQAssistantExercise.uir", PANEL)) < 0)
  return -1;
 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 return 0;
}
int CVICALLBACK AcquireCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 int32 read;
 float64 data[100];
 TaskHandle taskHandle;
 
 switch (event)
  {
  case EVENT_COMMIT:
   CreateDAQTaskInProject(&taskHandle);                // Here is open the function of the *.c file with the digital line Task
   DAQmxReadAnalogF64 (taskHandle, DAQmx_Val_Auto, 100.0,
        DAQmx_Val_GroupByChannel, data, 100, &read, 0);
   DeleteGraphPlot (panel, PANEL_GRAPH, -1, VAL_IMMEDIATE_DRAW);
   PlotY (panel, PANEL_GRAPH, data, 100, VAL_DOUBLE, VAL_THIN_LINE,
       VAL_EMPTY_SQUARE, VAL_SOLID, 1, VAL_RED);
   DAQmxClearTask (taskHandle);
   
   break;
  }
 return 0;
}
int CVICALLBACK QuitCallback (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
 switch (event)
  {
  case EVENT_COMMIT:
   QuitUserInterface (0);
   break;
  }
 return 0;
}
0 Kudos
Message 2 of 4
(5,125 Views)

I have copied here a solution of our LabWindow/CVI-Programm whose works with C - but for your MStudio8 the functions must be the same

Hope this help you

Best Regards - AE Munich

0 Kudos
Message 3 of 4
(5,124 Views)

Here is a link to digital input with visual basic and mstudio

 

http://zone.ni.com/devzone/cda/epd/p/id/1991

 

and with n-samples

 

http://zone.ni.com/devzone/cda/epd/p/id/163

0 Kudos
Message 4 of 4
(5,123 Views)