09-13-2019 04:56 PM
Can anyone open the attached and tell me what I'm doing wrong? All I'm trying to do is read in data from a spreadsheet (1khz example attached), generate two analog output waveforms (from columns B and C) and a digital output waveform (column D) from the values, and then "run" the profiles (with tight time synchronization) while also recording 6 channels of analog input data. The behavior I'm seeing doesn't make sense and no matter what I do the measured time the loop is running never matches the duration in the input spreadsheet (in this case it should be 10 seconds exactly).
I have an 8-slot cDAQ chassis (9189), a 9202 analog input module, a 9264 analog output module, and a 9403 digital IO module.
Thanks for your help in advance!
09-13-2019 08:37 PM
You'll get more eyes on your code if you back-save to an earlier LabVIEW version. A lot of us aren't using LV 2019 yet. Go to the File menu, pick "Save for Previous Version..." and then pick 2014 or so. A lot more of us will be able to to have a look.
-Kevin P
09-13-2019 11:24 PM
Great suggestion - attached!
09-14-2019 01:10 AM - edited 09-14-2019 01:20 AM
As a quick suggestion, I'd guess that you probably never want to both be loading and running a profile. As a result, you could reorganize your code to use something along the lines of a State Machine to go from an Idle -> Load -> Run -> Idle or similar cycle. At the very least, you can set your buttons to be Mechanical Action = Latch (when clicked, released) so that they reset themselves to false when you've read.
At present, you're reading the same data over and over again whilst the "Load" is true, then Writing over and over again whilst the "Run" is true (if this takes 10 seconds, maybe you're cancelling out of it by clicking again during the run, but still...) Sorry - missed the property node setting false. None-the-less, you could avoid this by using a different mechanical action.
The default setting for "sample mode 1" (AI) is "Finite Samples" and you don't set the number of samples. Is this typically set to Continuous when you're acquiring data?
If so, I'm not sure what's wrong. As a follow-up question, is the time measured always less than 10s? (is it usually 1s?)
09-14-2019 12:27 PM
Looking at your code, I think I know what you want to do, but it is sometimes a good idea to "write it down" (Document First) and explain it to us. Here's what I think:
If you code an Event Loop to handle the "Load Profile" and "Run Profile" buttons, they could serve as a "Producer" (of Messages) for the Message Handler loop (acting as a Consumer). To force the user to push Load Profile before Run Profile, start with Run Profile not visible. Make both Buttons the Rectangular buttons (like Stop) that are Latch when Released (any Boolean button can be set this way, but by a convention spanning at least a decade, square ones latch and round/oval ones are Switch when Pressed).
The Message Handler should have several Messages to which it responds.
Use the Event Loop to send the Message Handler the Load Profile and Run Profile Messages when you press their buttons. You should also have it process the Stop button and send an Exit (or Stop) Message to stop the Message Handler (and it should also stop the Event Loop).
Note that this scheme gets rid of all Local Variables and also removes the need for any need for Value Property nodes for variables, substituting Wires in Shift Registers to hold "Variables", and using the Controls to initialize them.
While you are at it, you don't need any Sequence Frames in this routine. You are doing most of the sequencing using the Error Line (good!), and can do more using the Message Handler's "Message" states and Shift Registers. Let Data Flow work for you.
Since you are using DAQmx, and your DAQ devices (typically) have much better clocks than your Windows PC, you should not need any timing functions in this code (except, if you want, a timer to verify that playing a 10-second Analog Signal to an Analog Output device at the same sampling rate used to acquire it does, indeed, take 10 seconds).
Don't be afraid to "hide messy details" in a sub-VI (for which you create a VI Icon, using the Icon Editor, possibly a Square with White interior on which you write 2-3 short words that say what the VI does). I'll admit your code is simple enough that you might not need such encapsulation (yet).
Bob Schor
09-14-2019 09:04 PM
Thanks guys! The state machine suggestion is awesome - I was first exposed to labview about 15 years ago (briefly) and a number of things are starting to come back to me...like the ability to make state machines! I’ll digest the great suggestions here and report back tomorrow. Thanks again!