Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| test-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2022/09/12 14:57] – changed forum.digilentinc.com to forum.digilent.com jeff.greenberg_ni.com | test-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Logging Data to a Flash Drive with Analog Discovery Pro (ADP3450/ | ||
| + | ~~TechArticle~~ | ||
| + | <WRAP center round todo 60%> | ||
| + | This page is under construction. | ||
| + | </ | ||
| + | |||
| + | ===== Overview ===== | ||
| + | <WRAP group> | ||
| + | This guide demonstrates using the Analog Discovery Pro in Linux mode to automate data logging directly to a USB flash drive. Automation is accomplished using WaveForms SDK and Python 3. Before following this guide, make sure that you run the latest Linux version on your device. Follow this guide to update the Linux on your Analog Discovery Pro: [[test-and-measurement: | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Inventory ===== | ||
| + | <WRAP group> | ||
| + | * [[test-and-measurement: | ||
| + | * A FAT/FAT32 USB drive | ||
| + | * [[https:// | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Boot Into Linux Mode ===== | ||
| + | <WRAP group> | ||
| + | <WRAP group>< | ||
| + | Mode selection can be done through WaveForms using the Device Manager. With the Analog Discovery Pro connected to the host computer by Ethernet, open WaveForms. If the Device Manager hasn't opened yet, then click Settings -> Device Manager. | ||
| + | </ | ||
| + | {{ : | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Select the Analog Discovery Pro from the device menu, then click the Boot button. The Boot Mode window should open. By default, Standard Mode which allows the user to communicate with the instrumentation device over USB or Ethernet will be selected. | ||
| + | |||
| + | To change to Linux Mode, select Linux, then click "Apply & Reboot" | ||
| + | </ | ||
| + | {{ : | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | At this time, an audible click should be heard and the Analog Discovery Pro will disconnect from WaveForms. About 10-15 seconds should pass before it reconnects. Confirm that the second column next to the Analog Discovery Pro says "USB Linux", | ||
| + | </ | ||
| + | {{ : | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Connect Through a Terminal Emulator ===== | ||
| + | <WRAP group> | ||
| + | <WRAP group>< | ||
| + | Find what serial port the Analog Discovery Pro is connected to and note it. | ||
| + | |||
| + | Open a terminal emulator such as PuTTY or TeraTerm and connect to the noted serial port using 115200 Baud, 8 data, 1 stop, and no parity bits. | ||
| + | </ | ||
| + | {{ reference: | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Login with username: " | ||
| + | </ | ||
| + | {{ reference: | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Mount the Flash Drive ===== | ||
| + | <WRAP group> | ||
| + | <WRAP group>< | ||
| + | Download {{ : | ||
| + | |||
| + | Plug the USB into the back of the Analog Discovery Pro. In the terminal, type < | ||
| + | </ | ||
| + | {{ reference: | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Make the drive contents accessible by entering the command < | ||
| + | </ | ||
| + | {{ reference: | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Script Overview ===== | ||
| + | <WRAP group> | ||
| + | <WRAP group>< | ||
| + | Import the necessary Python packages, then define the name of the output file and the drive letter and number of the USB drive. | ||
| + | </ | ||
| + | <code python># import modules | ||
| + | from ctypes import * | ||
| + | from dwfconstants import * | ||
| + | from subprocess import call | ||
| + | import sys | ||
| + | |||
| + | # parameters | ||
| + | filename = " | ||
| + | drive = " | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Load the WaveForms SDK dynamic library, then open the device. | ||
| + | </ | ||
| + | <code python># load WaveForms SDK | ||
| + | if sys.platform.startswith(" | ||
| + | dwf = cdll.dwf | ||
| + | elif sys.platform.startswith(" | ||
| + | dwf = cdll.LoadLibrary("/ | ||
| + | else: | ||
| + | dwf = cdll.LoadLibrary(" | ||
| + | |||
| + | # global variables | ||
| + | hdwf = c_int() | ||
| + | |||
| + | # open device | ||
| + | dwf.FDwfDeviceOpen(c_int(-1), | ||
| + | # check for errors | ||
| + | if hdwf.value == hdwfNone.value: | ||
| + | print(" | ||
| + | quit()</ | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Initialize the Oscilloscope. If you want to use a different instrument, change this part at your will. | ||
| + | |||
| + | Mount the USB storage. If the file system is already mounted, this command will only return a message. Set the path and the name of your file. | ||
| + | </ | ||
| + | <code python> | ||
| + | # initialize the oscilloscope | ||
| + | # enable the channel | ||
| + | dwf.FDwfAnalogInChannelEnableSet(hdwf, | ||
| + | # set 0V offset | ||
| + | dwf.FDwfAnalogInChannelOffsetSet(hdwf, | ||
| + | # set the range from -5V to +5V | ||
| + | dwf.FDwfAnalogInChannelRangeSet(hdwf, | ||
| + | # start the oscilloscope | ||
| + | dwf.FDwfAnalogInConfigure(hdwf, | ||
| + | |||
| + | # mount the USB strorage | ||
| + | call([" | ||
| + | |||
| + | # set file path | ||
| + | filename = "/ | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Load and save the oscilloscope data in a buffer, then write out the content of the buffer to the file. The file remains opened, until the script runs. | ||
| + | </ | ||
| + | <code python> | ||
| + | with open(filename, | ||
| + | while True: | ||
| + | # measure voltage | ||
| + | # load internal buffer | ||
| + | dwf.FDwfAnalogInStatus(hdwf, | ||
| + | voltage = c_double() | ||
| + | # save the internal buffer | ||
| + | dwf.FDwfAnalogInStatusSample(hdwf, | ||
| + | voltage = float(voltage.value) | ||
| + | |||
| + | # save voltage | ||
| + | f.write(" | ||
| + | </ | ||
| + | |||
| + | <WRAP group>< | ||
| + | Finally, exit the script on " | ||
| + | </ | ||
| + | <code python> | ||
| + | # exit on Ctrl+C | ||
| + | pass | ||
| + | finally: | ||
| + | # reset and close the device | ||
| + | dwf.FDwfAnalogInReset(hdwf) | ||
| + | dwf.FDwfDeviceClose(hdwf) | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Testing ===== | ||
| + | <WRAP group> | ||
| + | Start the script with the following command: | ||
| + | < | ||
| + | To terminate the script and to close the file, press " | ||
| + | </ | ||
| + | ---- | ||
| + | |||
| + | ===== Next Steps ===== | ||
| + | <WRAP group> | ||
| + | The script can be modified as needed for your project. | ||
| + | |||
| + | For more information on WaveForms SDK, see its [[software: | ||
| + | |||
| + | For technical support, please visit the [[https:// | ||
| + | </ | ||

