10-28-2021 05:13 AM
Hi,
I am currently attempting to use LabVIEW to emulate my companies communication protocol so that this can communicate to external devices for testing purposes. I am using the NI 9401 fast switching DAQ to achieve this.
I have created a Sub VI with a string of 1's and 0's to replicate the protocol frame I wish to emulate. This data has been sent to the DAQmx write function. I require each data bit to be 100us and each data frame of the protocol is 131 bytes (13.1ms total).
Currently, I have the sample clock set to 10000 which when measured is producing the required waveform at the correct timing. (I am sure there is an alternative method to achieving the correct timing, but for now this seems to be functioning as expected).
I am now having an issue with the duration of the task at the next stage (Start/End Task). The timing of these data frames needs to be precise as I am eventually looking to send multiple frames in quick succession. I want the written data from 'p1C_EventInit Node - 001' to only output once and then stop. The current set up, depending on the wait I have in place between start/stop task and how I manipulate it, the task can either miss the end of the waveform, or re-cycle back around to the beginning and give extra data at the end of the waveform.
Is there a function/Sub VI I can take advantage of that will start the task and stop the task as soon as the end of the data is reached, eliminating the risk and chance of receiving the incorrect number of data bits?
I am pretty new to LabVIEW and I am not sure if there will be much simpler and accurate way to create what I am trying to achieve (I'm sure there is!).
Any suggestions would be welcome and much appreciated.
I have attached 3 screenshots:
1. Main VI.
2. Front Panel of main VI showing waveform results for 3 different data frames at DAQmx Write function stage.
3. Sub VI showing data frame being sent.
Solved! Go to Solution.
10-28-2021 08:24 AM
As a very new Member, you probably haven't seen the numerous Replys that note it is much easier to examine, test, understand, and improve code than a "picture of code" (suppose you had to debug/improve/test a picture of a C++ (or Matlab, or Python) code listing, rather than the .cpp, .m, or .py file itself).
But as to your question, if you are going to be sending multiple Digital Waveforms out a DAQmx channel, open the Task once, and close it when you are all done. Depending on your DAQ output device, you might not even need a "Start Task" or "Stop Task" -- you might just need a "Write This Digital Waveform" (I'm not on my own PC, where I can look up and test the DAQmx commands to do this ...).
Bob Schor
10-28-2021 08:47 AM
Hi Bob,
Thanks for your reply. I fully understand and please find the attached code.
I'm using a NI 9401 on a single Chassis (cDAQ-9171). Currently the DAQ will be sending a single fixed frame (p1C_EventInit Node - 001 - this has been created using multiple 1's & 0's). The issue is that the sample rate is correct and so is the fixed frame (1's and 0's) but the data is being looped (probably due to the while loop controlling the timing of the frame) and the data starts to be sent again.
I would like help on how to send the data frame in p1C_EventInit Node - 001 without it looping, but stopping once its been completed.
Regards,
M
10-28-2021 08:51 AM
In the call to DAQmx Timing, you should specify the # samples to generate. By leaving it unwired, it defaults to 1000 and you'll start repeating your data. (DAQmx treats the data you write as a circular buffer -- when it gets to the end of the buffer, it wraps around to start over again from the beginning.)
So just take the size of the data array and wire up to the # samples in DAQmx Timing.
(Note: it only works this way for Finite Sampling tasks. The # samples input is mostly meaningless when you configure Continuous Sampling. See gripe and partial suggestion here.)
-Kevin P
11-02-2021 04:40 AM
Hi Kevin
I have updated the # samples as suggested and this has fixed my repeating data issue.
Many thanks for this, much appreciated.
M
06-20-2022 02:18 AM
Hi Kevin.
Many thanks for your previous help.
I am now having trouble when trying to send multiple data arrays using the same DAQ.
I'm using a NI 9401 on a single Chassis (cDAQ-9171).
Is it possible to send multiple arrays at the same time using different ports?
For example, the first array is being sent through port DIO0. Is it possible to send an array through DIO1 the same way in parallel with DIO0?
As i am trying to do this but there is nothing coming from DIO1 even with that particular channel selected on the code.
Please refer to the following link and you can see what I mean in more detail. The code is attached to this link.
Hope you can help.