02-08-2016 01:05 PM
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.
Solved! Go to Solution.
02-08-2016 06:10 PM
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.
02-08-2016 06:16 PM
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!
02-09-2016 01:57 AM
Hello,
knowing the board you are using, you can limit the search function in the example finder so that only compatible examples are shown:
The example I pointed you to before is compatible with your board.
02-10-2016 10:24 AM
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?
02-10-2016 10:31 AM
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.
02-10-2016 10:35 AM
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.
02-10-2016 10:41 AM - edited 02-10-2016 10:42 AM
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).
02-10-2016 10:47 AM
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.
02-10-2016 09:49 PM
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.