From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Read digital input, update displayed counter, write counter info to file

Solved!
Go to solution

Hello guys,

 

I would like to create a CVI program to read a digital line connected to an external switch. Display the number of times the switch was presed and save the data to a csv file. I am eble to create the DAQmax task whithin the project and I also created a textbox (not sure if I should use a textbox) to display the number of times the switch was pressed. I just can't figure out how to write update the textbox nor save to a file. Any help will be greatly appreciated.

 

- CVI rookie.

0 Kudos
Message 1 of 12
(4,782 Views)

Let's divide all the matter into subtasks.

 

1. Count events: to count the num ber of times a button was pressed you need to prepare a task for edge counting. the task returns an integer when you read it with DAQmxReadCounterScalarU32 so the textbox is probably not the best opption to display the value

 

2. Use a numeric indicator to display the value with SetCtrlVal

 

3. Output to file using functions in the Formatting and I/O Library or the ANSI C library

 

CVI comes plenty of useful examples that you can search and locate using the Example Finder: execute Help >> Find Examples... menu function and use the search options to locate the appropriate example: for counting task I suggest you look at the simple CntDigEv.prj, which addresses items #1 and #2 in the above list. Pointing you to the correct example for item #3 is more difficult since the format of output data impacts heavily on the choice of the correct instrument: do you want to save only the last number read? A series of values, maybe associated with the time the number refers to? A series of readings at regular intervals? Give us some detail more and we will be able to help you more precisely.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 12
(4,776 Views)

Hi Roberto,

 

Thanks for the prompt respond. I am using a NI USB-6009 with one digital channel as input. The switch gets actuated approx once every minute or so.

I will look at the suggested samples and breakdown the tasks into smaller sections and build from there.

 

Thanks!

0 Kudos
Message 3 of 12
(4,777 Views)

Hello,

knowing the board you are using, you can limit the search function in the example finder so that only compatible examples are shown:

Screenshot 2014-07-01 16.49.56.jpg

 

The example I pointed you to before is compatible with your board.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 12
(4,762 Views)

Hello,

 

I had no luck locating the .fp file for my USB-6009. I know it is install since I am able to use the device vis LabView, but I don't understand why I am not able to add it to my CVI project. Any hint?

0 Kudos
Message 5 of 12
(4,738 Views)

Which .fp file are you looking for?

To use a DAQ board you don't need any such file, simply install DAQmx and you have all needed libraries to interact with the board, together with the example programs.

You must also check that NI-DAQmx item is active (i.e. not dimmed) in Library menu: if it's not, execute Library >> Customize... function and check NI-DAQmx item, next restart CVI.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 6 of 12
(4,736 Views)

I was trying to add the USB-6009 to my project. The NI-DAQmx is active under Library, however, on the left hand colum of the project explorer, my "Instruments" is empty. I don't know what I'm missing if all I want is to red a port.

0 Kudos
Message 7 of 12
(4,734 Views)
Solution
Accepted by topic author hvazquez

Have you tried the example program? This will show you the necessary components that must be added to the project. Particularly, you won't find any item in Instrument menu related to the board and no component in the project tree (well, actually NI samples use NI DAQmx I/O Controls instrument, but this is just to populate controls on the user interface for demonstration purposes, normally programs do not need such component to work).



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 8 of 12
(4,730 Views)

I did tried CntDigEv.prj. I could not find it using the NI Example Finder (it is installed in my computer, however, for some reason I can't execute it). This is what I get while running the example program.

 

 Capture.PNG

0 Kudos
Message 9 of 12
(4,723 Views)

Never mind the last post. I reinstalled LabWindows/CVI. The NI Example Finder is working now. I can run the examples but perhaps is my lack of understanding that I can't figure out how to use the library. I generated the code, I do have a .c, .h and .mxb for my USB6009 within my project, however, the more I look at the sample project, it is not clear to me how to read one specific port.

 

Any help will be greatly appreciated.

0 Kudos
Message 10 of 12
(4,706 Views)