10-12-2016 03:35 PM
Hi all,
The function I want to realize is very simple. Reading the data from DAQ, play the sound file if a rising edge is detected, and stop playing if a falling edge is detected.
Attachment is my code, it works, but if I stop the program and start it again, the program will somehow get stuck(but no error), then all I can do is end the task and reopen the program. I put two case structures for each channel, I believe the problem is caused by the second case structure.
I am a beginner of labview, could someone help me optimize this code?
Thank you!
Solved! Go to Solution.
10-12-2016 05:25 PM
While this is not specifically in relation to the part of the code you are worried about it might help.
Have a look at the example finder for "Continuous Digital Input". I feel like using a digital input for your keys would make a lot of your logic much simpler so that you dont have to detect the rising edges.
After that I would recommend a simple state machine using shift registers so that if there is no change then do nothing, if the state changes the trigger the playing or ending of the sound. That way you can merge your two case structures into a single one since in no instance should you be receiving a rising edge and a falling edge at the same time.
On another note, I would consider moving from the multiple file paths to a single folder path that you then create the paths from known information.
10-13-2016 07:57 AM - edited 10-13-2016 07:57 AM
First of all, use arrays to your benefit. You can make this fairly simple by converting the Dynamic Data Type to an array of waveforms. The Trigger Detection can process an array of waveforms. You can then process all of the trigger detections in a FOR loop, updating which trigger (and the level) you are looking for dynamically.
10-13-2016 11:31 AM
Hi Crossrulz,
Thank you so much! I just have one more question.
I'm gonna use 12 channels of DAQ and play 12 different sound files. Shall I split 1D array of waveforms and creat 12 FOR loops? As only one sound file path can be created in a FOR loop.
10-13-2016 11:52 AM
@yatang wrote:I'm gonna use 12 channels of DAQ and play 12 different sound files. Shall I split 1D array of waveforms and creat 12 FOR loops? As only one sound file path can be created in a FOR loop.
You only need 1 loop. You could always make the file paths an array and use the same FOR loop. Just move the array control to be outside of the FOR loop and let it autoindex so that each channel will only look at its designated file.
10-13-2016 03:00 PM
Hi Corssrulz,
So what I should do is right-click the path control, select Browse Options, and change the Selection Mode to Folders. Then if I run the program, the first channel of DAQ will be connected to the first file in the folder, and the second channel will be connected to the second file in the folder.
Am I right?
10-13-2016 03:19 PM
It is not as simple as just selecting a folder. You would need to do a list folder, sort the files in some way, and build up an array of paths from the folder list (Build Array inside of a FOR loop). Preferably do all of that before your main loop.
10-14-2016 01:22 PM
Hi crossrulz,
I sort the files using List Folder and build an array of paths.
It works, thank you very much.
10-14-2016 01:24 PM
@yatang wrote:Hi crossrulz,
I sort the files using List Folder and build an array of paths.
To make it a little more efficient, move that FOR loop for building the full file paths to be outside of the While loop. No point in constanatly calculating the same value.
10-14-2016 01:35 PM
Oh yes, I forgot it.