Digital I/O

cancel
Showing results for 
Search instead for 
Did you mean: 

DIO DAQ vi that can perform write and read measurements using binary data saved in a file

Hi

I‘ve gone through the LabVIEW/forums examples of file I/O and DAQ but still struggling to create a DIO DAQ vi, that performs writes operation to an output channel by writing data to a file which  the same file will be read by an input channel and the correct data display.

The aim is to create a directory of different spreadsheet files each having a different 1D array of binary numbers (row format) of a maximum of 32 bits; to serve as a digital test pattern which can be written and read (MSB first) in a loop and the result continuously compared if the data read is the same as the data written.

I do understand the file I/O vi and the DIO measurement vi if considered separately but my biggest challenge is how and what functions must I use to link the file I/O functions with those of the DAQ measurement to create a flawless sensible DIO measurement just by writing and reading a file name.

I doubt if what I need is similar to the response in the forum otherwise I’ll appreciate any other better and simpler idea besides those already mentioned in the forum.

Thanks in advance

Rgds

Paul

0 Kudos
Message 1 of 20
(4,492 Views)

Can you post what you have tried so far that is not working?  If you have a working program for the DAQ part of your task, then you be able to add a Read from Spreadsheet File to that, and wire the output from that into the data input of your DAQmx Digital Write VI. 

0 Kudos
Message 2 of 20
(4,476 Views)

Hi

 

Thanks for the concern and support, please see the attached file of what i've been trying to do. Is for my Lab assignment.

 

I appreciate your help.

 

Rgds

 

Paul

 

0 Kudos
Message 3 of 20
(4,459 Views)

Paul,

 

I have multiple questions for you:

1)  Do you always mean to write that constant array of zeros to spreadsheet?

2)  You must be aware of data flow here in the sense that we have no idea what things will happen first inside this loop (ie the read from spreadsheet/DO, write to spreadsheet, and DI are three seperate things that can happen in any order which I don't think you intend)

3)  Have you taken a look at any of our design patternsMaster/Slave Producer/Consumer If you want good timing knowledge of these patterns will be critical to your code if not you could simply use the error wire to enforce data flow in the order you wanted.

4)  What did you intend to do at the bottom where your code is broken?  Did you possibly want to compare each element of the 2 arrays to the corresponding element of the other array?  If so I would use a auto indexed for loop.

5)  Are we using 2 different devices or 1 single device?

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 4 of 20
(4,438 Views)

Hi JD

Thanks for your concern and below is a broad idea behind my whole project, and i hope this clear what you weren't sure of.

Two main parts:

This is the objective:

Part A

My aim is to design an automatic control system that turns on/off devices (max 32) in a particular fashion or pattern based on the states of the digital data of 32 bits that I’ll send (write and read).

Basically this 32 bits digital or binary data will designates all the 32 devices where; the logic state of the LSB of the 32 bits binary data will control the first device while the logic state of the MSB of the 32 bits binary data will control the 32 device; whereby a logic state of 1 or high will turn on the device and vice versa.

My approach is:

A- To create different spreadsheet files (database), each having a 32bits 1D binary data which will represent a particular pattern of 1s and 0s (practically what devices will be on or off) after write and read operations.

B- To create a write to and read from spreadsheet task, which will prompt me to specify what file to write and read.

………………………………………………………………………………………………………

C- I’m practicing with a single NI USB-6509 simulated device and a demo version of LabVIEW 8.6

D- I’ve configured ports 0 to 3 (32 lines) to be output (for write operations) and ports 8 to 11 (32 lines) to  be input for read operations; I wanna write to and read from all 32 line or devices at same time.

E- Next is to create a write and read digital output/input DAQ task; whereby the data to be written to the write task will be the 32 bits binary data saved in the spreadsheet file and this same data must be read to ensure data written is same as data read;

Operation.

I’ll start the VI, and from the dialogue box, i'll write the data in the spread sheet file and read the data if is correct; then the output of the read from spreadsheet file will serve as the input data to the DAQ write task and this data again will be read by the DAQ task to ensure it is still the same data that was in the spreadsheet file.

Problems.

I have a problem linking the output of the read from spreadsheet file to the input of the write to DAQ task and to implement part B below.

Part B

Is to receive fedback to determine if two or more devices did or didn't turn off or on or in other words are stock in a particular state and didn't respond to the data sent.

I thought of using digital test patterns functions which I’m battling to implement, well I’ll have a  look at the design patterns and VI functions you mentioned.

 

But i'll appreciate if you can advice me further or any better and easier alternative solutions as i'm not that efficient with LabVIEW at this point in time.

 

Thanks once more.

Rgds

Paul

0 Kudos
Message 5 of 20
(4,426 Views)

Paul,

 

I really appreciate the better description of what you are trying to do and now I understand it much more, but I really cannot help you until some of my above questions have been answered.  Did you look at the links I posted?  Do you see why these programming patterns are going to be of use to you?

 

To address your problems:

1)  You will probably want to handle these to operations in different loops allowing you to control when each executes.

 

2)  You will have to know how those devices communicat to us?  Can we send them a command to verify they are running?  Is this meant to be for any general device or a specific set of devices.  We can certainly send signals but without having more detailed knowledge of what these devices expect to read and what they will return based upon that response there isn't a whole lot we can do.

Sincerely,
Jason Daming
Applications Engineer
National Instruments
http://www.ni.com/support
0 Kudos
Message 6 of 20
(4,408 Views)

Hi JD

Thanks once more and this is the direct answers to your questions:

To question 1: No, the array of 32 bits will always have different patterns of 1s and 0s.

To question 2: The data flow should be as follows:

Loop1: Data loop

Is simply how the data is to be written to the data input of the write DAQmx function and the main reason I wanted to use write to and read from file function is because, the user might make mistake if different 32 bits data are manually enter to the data input of write DAQmx function). It should execute as follows:

Start the VI/prompt for data to write (select file name)/write the data/read the same data to confirm

Loop 2: DAQ Loop

Is simply the write to and read from DAQ task which I can implement provided the write operation has to be manually done but not otherwise as in this case since the data from loop 1 will be the data written to DAQ device.

Loop 3: Safety loop

Is the challenging part, whose purpose is to determine if the data read from the DAQ device is still the same as the data entered in loop 1 especially if the 32 bits data are all 1s (high logic).

The technical reason why this loop is needed is because, the might be a short on the cable carrying this data to the input ports and from the output ports of the DAQ device which might not only corrupt the whole data that was written in loop1 but might also damage the DAQ device since multiple TTL outputs will be sourcing current to one another.

To question 3:

Yes, I’ve read through it and I’m still reading through it over and over again wandering and trying to figure out how loop 1 and loop 3 can be implemented using design test patterns or state machines.

It will be great if the above can be done using state machines as I’ll be killing two birds with a single throw of a stone, because my next project will be to design a mini obstacle avoiding robot based on state machines knowledge although I know this is a whole module on its own (never mine).

To question 4: I wasn’t just sure of where to connect the function as I wasn’t compatible.

To question5: Just one device (NI USB-6509). I’m using the simulated version to get it to work.

To conclude, all I’m interested from the project is to ensure that the 32 bit data that is written, is the same data that has been used to turn on/off all 32 devices (depending on the 32 bits data pattern) and I think the easiest way to monitor this is to check the logic states of the 32 bits data entering the cable that connects to the output of the DAQ device to the 32 devices and the cable leaving the 32 devices to the input of the DAQ device as this will effectively be the same as checking if the 32 devices receives the correct 32 bits data that was sent in the first place.

 

Note all I’m monitoring from the 32 devices is their output logic state if they have been turn on or off depending on the logic data at their inputs.

The DAQ device irefers to the NI USB-6509 DIO device.

I hope this clear all the doubts as I don’t mine explaining it further until you know exactly what I need and please I’ll appreciate if  the solution provided can be presented such that it best suit my understandings.

Thanks very much.

Rgds

Paul

0 Kudos
Message 7 of 20
(4,384 Views)

Paul,

Depending on how fast you need this to write/read data, you could probably implement a state machine for this.  There is a template for this that you can get to in LabVIEW by going to File>>New... and then Navigating to From Template>>Frameworks>>Design Patterns>>Standard State Machine.  I imagine for your program you will have the follwing states:

Initialize - initial value of the state enum; sets up the DAQ tasks, and performs any other initial operations.  Always transitions to the Write state.

Write - Reads one line from the file and writes those values to the DIO lines.  Transitions to the Read state, unless there is an error, in which case it transitions to the Stop state.

Read - Reads the return values from the devices.  Transitions to the Compare state, unless there is an error, in which case it transitions to the Stop state.

Compare - Compare the value read from the file to the value read from the DIO lines.  If they are the same, transition to the Write state to start the process over.  If they are different, transition to the Stop state (or prompt the user, or resend the same values, etc)

Stop - Close the tasks, stop the while loop.

 

You will need to add values for each of the states to the Enum Type Def, and then add a case to the case structure for each of them.  This is just how I envision it, but you know your application and the expected behavior better than I do.  Hopefully this gives you a basic idea of a potential architecture. 

 

-Christina

0 Kudos
Message 8 of 20
(4,337 Views)

Hi Christina

 

Yes, i look at the state machines templates and follow your procedure and i really appreciate your support but please i'll be very grateful if you can write a simple 3 states machine so that i can observe (in debug mode) what each code of the program really does then i can expand it to suit my use otherwise is just like giving answers tips without working solutions.

 

I'm seeking assistance from the forum because i can't implement it else i won't be composing stories upon stories to make my problem  clearer, so please i need a basic intuitive VI that works for me to learn from it, then i can expand it.

 

Rgds

 

Paul

0 Kudos
Message 9 of 20
(4,304 Views)

Paul,

I have attached a simple state machine VI and the enum (.ctl) file that defines the states.  This should be similar to what you are trying to do.  I hope it helps. 

 

-Christina

Download All
0 Kudos
Message 10 of 20
(4,283 Views)