Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use libraries for traditional daq with C#

I am having an issue using the axCWDIO library in my project to control a DAQPad-6508.Can anyone help?

I have an axCWDIO object on my form, have the properties set for output ports, and included the libraries axCWDAQControlsLib, CWDAQControlsLib, and CWUIControlsLib.
The problem is when I want to set specific lines to high (5v) it doesnt always set them.Havent been able to find anything in the documentation that comes with the NIDAQ (I used version 7.4.1) I dont know if this is really trying to write to a port instead of a line, perhaps thats my problem? Not only does it not set anything for some values of intcnt, it gives an error if I get too high (as if the highest is port.item(11) because there are 12 ports on a 96 bit version?) I also get an error reading after the first time.
Heres the basics of my code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using AxCWDAQControlsLib;
using CWDAQControlsLib;

namespace NIDaqTester
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int ret = 0;
            object data = null;
            try
            {
                for (int intcnt = 0; intcnt < 11; intcnt++)
                {
                    ret = axCWDIO1.Ports.Item(intcnt).SingleWrite(5);
                    Thread.Sleep(50);
                    ret = axCWDIO1.Ports.Item(intcnt).SingleRead(ref data);
                    Thread.Sleep(50);
                }
                for (int intcnt = 0; intcnt < 11; intcnt++)
                {
                }
                for (int intcnt = 5; intcnt < 11; intcnt++)
                {
                   
                    ret = axCWDIO1.Ports.Item(intcnt).SingleWrite(0);
                }
                axCWDIO1.Dispose();
            }
            catch(Exception ex)
            {
                axCWDIO1.Dispose();
                return;
            }
        }
    }
}

0 Kudos
Message 1 of 2
(3,140 Views)
Hi,

What kind of errors do you see?

Also have you tried changing the SingleWrite command to write a 1 instead of a 5? Usually digital logic only accepts a 1 or a 0, not the actual voltage.

I found this reference on Component Works which is what the axCWDIO object is based on. The documentation is not very complete but I found the Tutorials in Chapter 6 very useful. The other problem with this document is that it refers to VB code and not C#.

Abhinav T.
Applications Engineer
National Instruments
Abhinav T.
Applications Engineering
National Instruments India

LabVIEW Introduction Course - Six Hours
Getting Started with NI-DAQmx
Measurement Fundamentals
0 Kudos
Message 2 of 2
(3,117 Views)