Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of channel in the task not match with number of channel in data

Hello There
We just bough new PCI-DIO96 board for our new project and use managed NI-DAQmx library to develop our own software application using VB.NET on Visual Studio 2005.
I build the class DIO with a subClass name MyBit which will represent 12 Ports as a member of the class each name AA,AB....and so on and end with DC .
Each port will share a ReadTask , WriteTask ,MyReader and MyWritter (ReadTask and WriteTask is of type Task and MyReader and MyWritter is of type DigitalSingleChannelReader and DigitalSingleChannelWrite Respectively) .
Class DIO has method SetOut for Output a specific port and bit or Bit array and method ReadPort for reading a Bit array of a specific port.
When the class DIO is instantiate with its constructor the 12 ports will be initialized and a shared member (Static in C++) also will be also initialized and add channel to its respective Task (ReadTask for Input Port and WriteTask for OutPut port with their respective MyReader and MyWritter ).
I got problem when I try to use Sub SetOut which its body use MyWritter.WriteSingleSampleMultiLine(True,DATA()) command in NI-DAQmx library . I got error message telling that the number of Channels in the Task not Match with Number of channels in Data.
I don't know what does it mean.
The intention of creating a class MyBit which is a sub class of DIO  with the shared member is for keeping the channel status in ReadTask and WriteTask during software run , as if we create a new Task each time and add the same channel name to the task would not possible unless the old task is disposed , so each time the task create and add channel a physical status of a current channel will be lost.
So how to overcome the above error (Number of channel in data and task not match).
Regards
 
0 Kudos
Message 1 of 6
(4,758 Views)
Hi Khammonh,

You did not mention the error code associated with the error, but I believe it is -200463:
"Specified read or write operation failed, because the number of lines in the data for a channel does not match the number of lines in the channel."

The WriteSingleSampleMultiLine method writes a single digital sample to multiple digital lines contained in a task channel.  The DATA() array that you pass to this method is a 1D array of samples to write.  Each element of the array corresponds to a digital line within the channel, and the size of the array must be equal to the number of digital lines in the channel or the error will be returned.  What is the size of the DATA() array that you are passing compared to how many digital lines you are intending to write this data to?

Regards,
Andrew W
National Instruments
0 Kudos
Message 2 of 6
(4,741 Views)

Hello Andrew

Thank you for your answer, I actually very new to NI though I developed a lot of application but never use NI .Answer to your question .

DATA() is 1D array with 8 elements and no thing wrong with the format , before I get your reply I try on error and found that I need to create the task and its associate Reader and Writter for each channel . Previously I create a common ReadTask ,WriteTask and their associate Reader and Writer as a shared member of the class ( hope to save system resources) but this way it doesn't work as these common tasks content six channels each ( 6 Inputs and 6 OutPuts) when I want to write to a specific channel in the task I got the error message. So I change my class structure , add 4 readonly properties to the class each represent ReadTask, WriteTask , Reader and Writer of the class. This way I have no problem. I download NI-DAQmx for .NET but its documentation seems not completely loaded , when I drill to some particular member of the class there is no help available. Where I can get a complete documentation preferably a compiled help that integrated into Visual Studio 2005(or VB.NET 2005)  IDE if not a PDF format is also fine.

I also want to learn more about NI hardware and software driver for my next development a comprehensive sample code would be good as I saw each sample code provided is a small piece of code contain only one a few commands . A small application code would be a good sample says has a few AI ,DI ,DO and AO , AI and DI may have one that work in a interup mode (Interup when detect status change).

Hope I will get a good recommendation.

Regards

0 Kudos
Message 3 of 6
(4,736 Views)
Hi Khammonh,

It sounds like you are relatively new to programming with the NI-DAQmx API.  I think the best option for you would be to refer to some of the shipping examples that are included with the driver when you choose the option to include support for .NET.  This would allow you to see a testing and working example similar to the application that you are trying to implement.  It will allow you to see the proper programming flow for setting up various types of applications.  The examples for VB.NET are located in the directories shown in the following image:



In addition, the .NET help file for NI-DAQmx can be found in Start>>Programs>>National Instruments>>NI-DAQ>>NI-DAQmx .NET Framework Help.

Regards,
Andrew W
National Instruments

Message Edited by TheWoost on 05-10-2007 11:00 AM

0 Kudos
Message 4 of 6
(4,726 Views)

Hi Andrew

Thank for your reply and the table of sample code location ( seems it is the same as in the documentation ) it is a good sample but still in a piece by piece code. If each of them function independently when we include all of them into the same project seem to be OK . My worry is if all tasks has the lifecycle time of the application lifecycle in another words there is no task was disposed during application running , would it be any system resource issue?

Regarding .NET help I did snap to the same spot you has mentioned , but in some detail in a lower heirrachy of the name space it just not available I don't know why.

0 Kudos
Message 5 of 6
(4,718 Views)
Hi Khammonh,

I would like to jump here and help you out. Seems like you have all the good examples provided by TheWoost, now you probably need to make sure you understand the DAQmx model.
The short answer to you questions is yes, you can dispose the tasks you are not using anymore in the middle of the life cycle of the program. The longer answer is to use the Getting started with DAQmx, specially, the text based programming section here.

For the help, if you have loaded the assemblies, you should be able to load and vew the following:
NI Measurement Studio Help » NI Measurement Studio .NET Class Library » Reference » NationalInstruments.DAQmx

Hope this helps,
Gerardo O.
RF SW Engineering R&D
National Instruments
0 Kudos
Message 6 of 6
(4,706 Views)