Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

How to control NI 9485 using ANSI C

I have a couple of NI 9485 8-Channel Solid-State Relay (SSR) Digital Output Modules in a NI cDAQ-9188 Ethernet chassis.  The purpose of these modules is to act as a relay to transmit signals to the device under test.  I have inherited ANSI C code for this and other devices in the chassis and my direction is to finish the code.  I have a problem choosing the correct ANSI C functions to make this module work.   I initially used  the ControlIndividualRelay.c example but the software/chassis complained that the channels specified did not match the type of channels on the device when I used the functions DAQmxSwitchSetTopologyAndReset followed with a DAQmxSwitchCloseRelays. I have tried various examples but the result is always the same the types of channels specified in the code do not match the device/module channel type.  I have looked all over the discussion board without any luck.

 

I would like to know what ANSI C functions I have to use so that I can instruct the NI 9485 module to turn on or off the relay for the signal connected to Channel 0a/b.  I have also tried using the digital write functions but the software complains that the type of write function does not match the type of channels in the task (devx/port0/line0) code -200526.  If I use devx/ch0 to specify the channel then the DAQmxCreateDOChan function returns error code -200170 (the physical channel does not exist on this device).  Any help would be appreciated so that I can then go off and try to resolve the "reserved device" problems.

 

Thank you,

 

Luis Alvarez

0 Kudos
Message 1 of 5
(3,707 Views)

Hi Luis,

 

The NI 9485 uses the digital output APIs. Could you post more information about what code you ran that returned error -200526? Was it one of the digital output example programs?

 

Brad

---
Brad Keryan
NI R&D
0 Kudos
Message 2 of 5
(3,697 Views)

 Brad,

 

Thanks for your response.  First of all, I inherited the C code from the developer who is leaving the company and had used the ANSI C examples yo develop code and that I have very limited experience with NI data acquisition hardware.  I initially thought that the code was thoroughly tested and ready to go and the only thing left was for the wiring harness to be developed.  As I started to familiarize myself with the written software I realized that the code had not been tested with the real Chassis and modules at all.  The reason why I’m explaining this is because there might be a simpler way to perform some of the functions.  The cDAQ-9188 Chassis uses the NI-9485 module as a set of relays to be activated as needed for multiple control signals.

 

Let me describe the applicable code to this module.  In an initialization function a device ID/port (channel) string was defined for each control, analog input and analog output signal.  Here is an example of this definition (the original code was modified after looking at the WriteDigChan.c example):

 

      sprintf(s_outputSignalPortNames[0][CONTROL_SIGNAL_1], "%s/port0/line0", s_relayModule2Name);

      sprintf(s_outputSignalPortNames[0][CONTROL_SIGNAL_2], "%s/port0/line2", s_relayModule2Name);

and so on for each device and control signals.

  

Then, these Device ID/port string definitions were used to create tasks for each signal (control, analog input and output) and set up the digital output using i and j loops as follows :

 

                  DAQmxErrorCheck(DAQmxCreateTask("", &s_outputSignalTaskHandles[i][j]));

                  DAQmxErrorCheck(DAQmxCreateDOChan(s_outputSignalTaskHandles[i][j],

                                                                                 s_outputSignalPortNames[i][j],

                                                                                  "",

                                                                                 DAQmx_Val_ChanForAllLines));

 

And last all the tasks were started (I commented out the code because I found out that the modules only allow one task at a time), as follows:

//                DAQmxErrorCheck(DAQmxStartTask(s_outputSignalTaskHandles[i][j]));

 

 

When the first test is started, the analog signal is turned on  (DAQmxErrorCheck(DAQmxWriteAnalogF64(s_outputSignalTaskHandles[DEVICE_NO][signalLine], 1, 1, 10.0, DAQmx_Val_GroupByChannel, &voltage, NULL, NULL));), and then the control signal is activated via the relay module as follows:

 

             DAQmxErrorCheck(DAQmxWriteDigitalU8(s_outputSignalTaskHandles[DEVICE_NO][signalLine], 1, 1, 10.0, DAQmx_Val_GroupByChannel, relayIndex, NULL, NULL));  

 

The relayIndex signal is a uInt8 type signal and the intent is to set/clear bits to turn on or off the respective control signals.  This is where the I get error code -200526 (Write cannot be performed because this version of DAQWrite does not match the type of channels in the task….)

 

The developer had initially used an AO set of definitions with CHx for the ports for this module.  I changed these to DO with portx/liney for the ports as per the example WriteDigChan.c. I had also used the DAQmxWriteDigitalLines function with the same results.

 

I hope this is enough information.  Thanks for your help.

 

Luis

0 Kudos
Message 3 of 5
(3,625 Views)

Hi Luis,

 

Do you need to control the behavior of the individual relay or just connect two channels? I saw an example in the same folder as Control Individual Relay that was called Connect Two Channels, so I would try running that to see if the behavior changes and you are able to run it successfully. The error messages you were seeing may be due to specifying an entire channel instead of an individual relay. Depending on how you modified the code, you could be trying to do a write that is not supported by the task or the device.

 

You also mentioned something about the channels already being reserved. This could be due to another program such as Measurement and Automation Explorer holding the resources for that channel or trying to create two tasks on the same line. 

Jake H | Product Manager
0 Kudos
Message 4 of 5
(3,595 Views)

Luis,

 

I take that back - the 9485 does not use the DAQmx Switch commands. It's a digital module that closes a relay when you output a digital high and opens it when you write a digital low. For more information, please see this KnowledgeBase article here.

Jake H | Product Manager
Message 5 of 5
(3,589 Views)