Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| test-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2021/07/16 07:46] – [Connect Through a Terminal Emulator] Álmos Veres-Vitályos | test-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2022/10/04 11:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 51: | Line 51: | ||
| 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. | 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: | + | {{ reference: |
| </ | </ | ||
| Line 57: | Line 57: | ||
| Login with username: " | Login with username: " | ||
| </ | </ | ||
| - | {{ reference: | + | {{ reference: |
| </ | </ | ||
| </ | </ | ||
| ---- | ---- | ||
| - | ===== Enable Automounting | + | ===== Mount the Flash Drive ===== |
| <WRAP group> | <WRAP group> | ||
| - | Enable automounting of file systems on your device by entering the following command: | + | <WRAP group>< |
| + | Download {{ :test-and-measurement: | ||
| - | < | + | Plug the USB into the back of the Analog Discovery Pro. In the terminal, type < |
| + | </ | ||
| + | {{ reference: | ||
| + | </WRAP></ | ||
| - | When asked, enter the root password: " | + | <WRAP group>< |
| + | Make the drive contents accessible by entering | ||
| + | </ | ||
| + | {{ reference:test-and-measurement: | ||
| + | </ | ||
| + | </ | ||
| + | ---- | ||
| - | <code python> | + | ===== Script Overview |
| - | # Import FS infos | + | <WRAP group> |
| - | IMPORT{program}="/ | + | <WRAP group>< |
| - | # Get a label if present, otherwise specify one | + | Import |
| - | ENV{ID_FS_LABEL}!="", | + | </WRAP>< |
| - | ENV{ID_FS_LABEL}=="", | + | <code python># import modules |
| - | # Global mount options | + | from ctypes import * |
| - | ACTION==" | + | from dwfconstants import * |
| - | # Filesystem-specific mount options | + | from subprocess import call |
| - | ACTION==" | + | import sys |
| - | # Mount the device | + | |
| - | ACTION==" | + | |
| - | # Clean up after removal | + | |
| - | ACTION==" | + | |
| - | # Exit | + | |
| - | LABEL=" | + | |
| - | Hit "Ctrl+O" | + | # parameters |
| + | filename = "voltages.txt" | ||
| + | drive = "sda1"</ | ||
| + | </ | ||
| - | < | + | <WRAP group>< |
| + | Load the WaveForms SDK dynamic library, then open the device. | ||
| + | </ | ||
| + | < | ||
| + | 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), byref(hdwf)) | ||
| + | # 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) | ||
| + | </ | ||
| </ | </ | ||
| ---- | ---- | ||
| - | ===== Script Overview | + | ===== 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:// | ||
| + | </ | ||

