06-29-2016 10:20 AM
Has anyone had experience in programming the NI-6520 Relay card using CVI? I am using CVI 2013 with DAQ 15.0.
NI-MAX shows the card installed and can access it via the Test Panel.
I just need some simple command lines for flipping the relays.
Solved! Go to Solution.
06-30-2016 10:51 AM
Hey jbrown60,
Have you already tried the examples that ship with CVI?
Text Based NI-DAQmx Data Acquisition Examples - http://www.ni.com/example/6999/en/#.NETDIO
in that document it states that "The default installation directory for LabWindows/CVI examples is C:\Documents and Settings\All Users\Documents\National Instruments\CVI\samples\DAQmx."
Also check out the support reasources!
NI LabWindows™/CVI Technical Resources: Getting Started, Support, and Downloads - http://www.ni.com/lwcvi/technical-resources/
07-06-2016 05:49 AM
My installation of CVI did not come with the samples in that directory.
The problem is slightly more complicated in that my develoment machine is a laptop and the target machine is a desktop with the 6520 in it, so I am programming blind.
I have installed the NI-DAQ 15 that came with the card on both machines (which hopefully won't screw up previous development packages).
The desktop sees the NI-6520 as "Dev1". On the test panel: I can select port 1, and select the state under port1/line0:7 to change the state of relays. So I know I should be able to talk to it somehow. Is the board considered a switch or digital I/O. I'm just looking for maybe ten lines of code that will connect me to the board and activate a relay.
07-07-2016 03:35 AM
1. A correct install of DAQmx should come together with the appropriate examples, maybe located in a different folder on disk. You can use the example finder (Help >> Find examples... menu item in CVI IDE) limiting the search on your specific board: see this post where I explain how to do this
2. Even if your PC hasn't the correct hardware installed, you could create a simulated device for your board and test your software agains it: see this tutorial on simulated deviced in DAQmx
07-08-2016 10:25 AM
Thank you Roberto for directing me to some very useful information.
Using the Help files for the NI MAX install I was able to create a virtual instrument.
I was also able to find the CVI example program "WriteDigPort" which sets up a DAQmx task to write to the board, which in this case is the 6520.
As expected it really comes down to only about 6 lines of code. I will post the controlling function when I get it incorporated so that others may not have to spend days hunting.
07-08-2016 10:48 AM
You're welcome!
07-12-2016 06:10 AM
As promised. A simple set of routines to control the 6520 under Win7, CVI 2013, NI-DAQmx 15.5
Required include files:
#include <NIDAQmx.h>
#include <DAQmxIOctrl.h>
/* declare global for Task Session */
static TaskHandle taskHandle = 0;
/* main function calls Init6520Sesn to get taskHandle and start DAQ task */
int Init6520Sesn( )
{
int32 rtnStatus = 0;
char chan[256];
/* NI MAX address location for the 6520 shows as Dev1,
* port0 controls sensors, port1 controls relay state
* line0:7 addresses the 8 relays on the board
*/
sprintf(chan,"Dev1/port1/line0:7");
/*********************************************/
// DAQmx Configure Code
/*********************************************/
rtnStatus = DAQmxCreateTask("",&taskHandle);
rtnStatus = DAQmxCreateDOChan(taskHandle, chan, "", DAQmx_Val_ChanForAllLines);
/*********************************************/
// DAQmx Start Code
/*********************************************/
rtnStatus = DAQmxStartTask(taskHandle);
/* put error handling code here */
return 0;
}
void Switch6520Relays(int nRelayState )
{
uInt32 data;
char errBuff[2048]={'\0'};
int32 written;
int32 rtnStatus = 0;
/*********************************************/
// DAQmx Write Code
/*********************************************/
data = nRelayState ; // convert int to UINT32
rtnStatus = DAQmxWriteDigitalU32(taskHandle,1,1,10.0,DAQmx_Val_GroupByChannel,&data,&written,NULL);
if(rtnStatus != 0)
{
DAQmxGetExtendedErrorInfo(errBuff,2048);
MessagePopup("DAQmx Error",errBuff);
}
}
// END 6520 Functions
/* Add shutdown calls when session no longer needed, in this case when the application closes */
int CVICALLBACK panelCB (int panel, int event, void *callbackData,
int eventData1, int eventData2)
{
if (event == EVENT_CLOSE)
{
DAQmxStopTask(taskHandle);
DAQmxClearTask(taskHandle);
QuitUserInterface (0);
}
return 0;
}