element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog Sound and Vibration Measurement: Instrument Network Service for LabVIEW Pt4: Data Stream Functionality - analysis
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 14 Apr 2022 11:11 AM Date Created
  • Views 2405 views
  • Likes 8 likes
  • Comments 4 comments
  • RoadTest
  • mcc172
  • sockets
  • daq
  • labview
Related
Recommended

Sound and Vibration Measurement: Instrument Network Service for LabVIEW Pt4: Data Stream Functionality - analysis

Jan Cumps
Jan Cumps
14 Apr 2022
Sound and Vibration Measurement: Instrument Network Service for LabVIEW Pt4: Data Stream Functionality - analysis

For the Sound and Vibration Measurement Hat for Raspberry Pi road test, I'm reviewing Measurement Computing's IEPE Measurement DAQ HAT for Raspberry Pi.
The next series of posts are going to be a subplot. I'll make software to remotely control the DAQ, via LabVIEW.
In this post, I 'm analysing how to stream the data that the DAQ generates to the LabVIEW flow.

image

All images and screenshots in this blog are from the actual designs. They reflect the status at the time of writing

Complex topic warning. This post will review multi-threading in LabVIEW and in the Linux instrument service. And uses a second tcp/ip socket to stream data over the network.

image

Instrument Service: streaming acquisition data

I'll have to be able to scan inputs, and stream the data to LabVIEW at the same time. If I'd know up front how many samples to take, I could just create a big enough buffer, do the sampling, and return the data. But this device supports constant sampling, so that solution won't do. Parallel processing is needed.

The mcc172 library has a partial solution for my scenario. When you ask the instrument to start scanning, it spawns a new thread that does the scanning. It 'll spend all its time getting data and filling a buffer. If you told it up front how many samples to take, it 'll stop when that job is achieved. Else it runs until you call the Stop Scan API function. Your code is then responsible in parallel to read that buffer fast enough and do something useful with the data. That could be: streaming it, perform a FFT, displaying it, …

In the instrument service that I'm writing for the road test, the goal is clear: the data has to be sent to LabVIEW. The needs to happen over the network. There is again a naive option: I could use the existing connection, and stream the data while the instrument samples. But that would block any other communication to the instrument - it would not be able to entertain incoming commands, such a s a request to stop continuous scanning. I need to develop a parallel stream mechanism. It's not hard, but requires some bookkeeping: I have to spawn a new thread to move data from the scanning buffer to the network socket. The new thread will wait until the client (LabVIEW) connects, and then continuously reads the scan buffer, formats the data to a string (note to self: I could make a binary stream too) and sends it off to the socket. It 'll be send and forget. The LabVIEW side is responsible for keeping up with the flood.

In total, there will be 3 threads active in parallel during scanning:

  • the main thread. It just continues to do what it's supposed to do: wait for cammands and act upon them
  • the mcc172 library's scan thread: it samples and fills a circular buffer. Runs until it is asked to stop or the requested amount of scans are acquired
  • my stream thread that gets the data from that buffer and writes it. Has a similar life span as the mcc172 one.

There is a Scan Cleanup function in the instrument service (and its brothers in the SCPI service and LabVIEW driver) that will mop op the threads and buffers.

image

LabVIEW: producer / consumer pattern

There's an existing design pattern in LabVIEW to deal with data streams. It uses two parallel flows. The producer will eat incoming data and enqueue it. The consumer pops data off the queue and does the business logic. This takes care that the business processing doesn't slow down the data retrieval. I'm using that mechanism to deal with the data from the MCC172 DAQ. The annotated screen capture below shows the early development.

image

In the LabVIEW design we have 2 threads. The producer and consumer run in parallel threads. Splitting the queue's outputs and routing it to the two rectangles causes LabVIEW to multi-thread. There is no main thread at that time, because I don't need one. But if you look at it from the perspective of automating an instrument, then the Producer thread is the dominant one during the scanning execution.

In the drawing at the end of the previous section, you can see the two parts working together. It shows when threads are generated, and who waits when (or doesn't wait). It's a bit involved, the brain needs multitasking too to understand it. The Instrument Service implementation is mature. Once I have a reliable version of the LabVIEW part, I will think about simplifying it for the end consumer. It would be nice if I could club all the complexity into a separate utility block, and only expose the queue to the flow ...

The design is definitely not stable yet, but I can share the result of the first run with a signal attached to channel 0:

image

It's a tiny bit of a 50 Hz, 0.5 Vpp signal. I set the sample rate to 1024, samples to 64, and these are the 28 first results retrieved by LabVIEW, pasted into a spreadsheet.
You can retrieve the current status of all the software for this road test via this github tag: 20220414.

Link to all posts.


  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 3 years ago

    When checking the processes in Linux with top, you can see the 2 threads running during a scan. I used this commend, to scan the two services and the threads generated:

    top -H -p520 -p560

    Result when scanning continuously:

    image

    When stopping the scan, the two additional threads disappear. The services keep running.

    image

    There are several ways to get the service process id. This is the simplest:

    sudo systemctl status daqhats.service

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago in reply to Jan Cumps

    Real data now: image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 3 years ago

    I've made a dummy instrument service (available on github), that allows anyone to test the software and the LabVIEW driver, without DAQ HAT.

    At this moment, it returns a constant increment output, starting from -5V, incrementing with 0.000001 V at each sample. It's resulting in output that is in the valid range for this instrument, and easy to (automatically) validate the results. You can check if any values are dropped, corrected or skipped.

    Here's a capture with 1024 samples. Delayed for "showing data retrieval on video" sake but it performs without delays in the real world.

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mp2100
    mp2100 over 3 years ago

    <quote>

    Complex topic warning.

    </quote>

    Thanks for the warning.  Your posts are always informative and useful.  And (for me) often complex.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube