Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
test-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2021/07/16 07:47] – [Connect Through a Terminal Emulator] Álmos Veres-Vitályostest-and-measurement:analog-discovery-pro-3x50:logging-data-to-usb [2022/10/04 11:38] (current) – external edit 127.0.0.1
Line 62: Line 62:
 ---- ----
  
-===== 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><WRAP column half> 
 +Download {{ :test-and-measurement:analog-discovery-pro-3x50:logger.zip |this}} package and extract the contents onto the USB drive.
  
-<code>sudo nano /etc/udev/rules.d/11-media-by-label-auto-mount.rules</code>+Plug the USB into the back of the Analog Discovery Pro. In the terminal, type <code>sudo fdisk -l</code> to find the USB device path. It should look like ///dev/sd<drive letter><partition number>//. This guide will use /dev/sda1 in its text and images, and care must be taken to match the drive letter and partition number of your USB drive. 
 +</WRAP><WRAP column half> 
 +{{ reference:test-and-measurement:analog-discovery-pro-3x50:fdisk-output.png?400 |}} 
 +</WRAP></WRAP>
  
-When asked, enter the root password: "digilent". In the opened text editor copy the following lines:+<WRAP group><WRAP column half> 
 +Make the drive contents accessible by entering the command <code>sudo mount /dev/sda1 /mnt</code> and then <code>cd /mnt</code> to navigate into the USB's directory. 
 +</WRAP><WRAP column half> 
 +{{ reference:test-and-measurement:analog-discovery-pro-3x50:mount-usb.png?400 |}} 
 +</WRAP></WRAP> 
 +</WRAP> 
 +----
  
-<code python>KERNEL!="sd[a-z][0-9]", GOTO="media_by_label_auto_mount_end"   +===== Script Overview ===== 
-# Import FS infos   +<WRAP group> 
-IMPORT{program}="/sbin/blkid -o udev -p %N"   +<WRAP group><WRAP half column> 
-# Get a label if present, otherwise specify one   +Import the necessary Python packages, then define the name of the output file and the drive letter and number of the USB drive. 
-ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"   +</WRAP><WRAP half column> 
-ENV{ID_FS_LABEL}=="", ENV{dir_name}="usbhd-%k"   +<code python># import modules 
-# Global mount options   +from ctypes import * 
-ACTION=="add", ENV{mount_options}="relatime"   +from dwfconstants import * 
-# Filesystem-specific mount options   +from subprocess import call 
-ACTION=="add", ENV{ID_FS_TYPE}=="vfat|ntfs", ENV{mount_options}="$env{mount_options},utf8,gid=100,umask=002"   +import sys
-# Mount the device   +
-ACTION=="add", RUN+="/bin/mkdir -p /media/%E{dir_name}", RUN+="/bin/mount -o $env{mount_options} /dev/%k /media/%E{dir_name}"   +
-# Clean up after removal   +
-ACTION=="remove", ENV{dir_name}!="", RUN+="/bin/umount -l /media/%E{dir_name}", RUN+="/bin/rmdir /media/%E{dir_name}"   +
-# Exit   +
-LABEL="media_by_label_auto_mount_end"</code>+
  
-Hit "Ctrl+O" to save the file, then "Ctrl+X" to exit the editor. Reload the device manager with the following command:+# parameters 
 +filename = "voltages.txt" 
 +drive = "sda1"</code> 
 +</WRAP></WRAP>
  
-<code>sudo udevadm control --reload-rules</code>+<WRAP group><WRAP half column> 
 +Load the WaveForms SDK dynamic library, then open the device. 
 +</WRAP><WRAP half column> 
 +<code python># load WaveForms SDK 
 +if sys.platform.startswith("win"): 
 +    dwf = cdll.dwf  # on windows 
 +elif sys.platform.startswith("darwin"): 
 +    dwf = cdll.LoadLibrary("/Library/Frameworks/dwf.framework/dwf") 
 +else: 
 +    dwf = cdll.LoadLibrary("libdwf.so") 
 + 
 +# global variables 
 +hdwf = c_int()  # device handle 
 + 
 +# open device 
 +dwf.FDwfDeviceOpen(c_int(-1), byref(hdwf))  # open first device 
 +# check for errors 
 +if hdwf.value == hdwfNone.value: 
 +    print("failed to open device")  # display error 
 +    quit()</code> 
 +</WRAP></WRAP> 
 + 
 +<WRAP group><WRAP half column> 
 +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. 
 +</WRAP><WRAP half column> 
 +<code python>try: 
 +    # initialize the oscilloscope 
 +    # enable the channel 
 +    dwf.FDwfAnalogInChannelEnableSet(hdwf, c_int(0), c_bool(True)) 
 +    # set 0V offset 
 +    dwf.FDwfAnalogInChannelOffsetSet(hdwf, c_int(0), c_double(0)) 
 +    # set the range from -5V to +5V 
 +    dwf.FDwfAnalogInChannelRangeSet(hdwf, c_int(0), c_double(5)) 
 +    # start the oscilloscope 
 +    dwf.FDwfAnalogInConfigure(hdwf, c_bool(False), c_bool(False)) 
 + 
 +    # mount the USB strorage 
 +    call(["sudo", "mount", "/dev/" + drive, "/mnt"]) 
 + 
 +    # set file path 
 +    filename = "/mnt/" + filename</code> 
 +</WRAP></WRAP> 
 + 
 +<WRAP group><WRAP half column> 
 +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. 
 +</WRAP><WRAP half column> 
 +<code python>    # create/open the file 
 +    with open(filename, "w") as f: 
 +        while True: 
 +            # measure voltage 
 +            # load internal buffer 
 +            dwf.FDwfAnalogInStatus(hdwf, False, None) 
 +            voltage = c_double()    # buffer for raw values 
 +            # save the internal buffer 
 +            dwf.FDwfAnalogInStatusSample(hdwf, c_int(0), byref(voltage)) 
 +            voltage = float(voltage.value)   # get voltage values 
 + 
 +            # save voltage 
 +            f.write("{}\n".format(voltage))</code> 
 +</WRAP></WRAP> 
 + 
 +<WRAP group><WRAP half column> 
 +Finally, exit the script on "Ctrl+C", then reset the used instruments and disconnect from the device. 
 +</WRAP><WRAP half column> 
 +<code python>except KeyboardInterrupt: 
 +    # exit on Ctrl+C 
 +    pass 
 +finally: 
 +    # reset and close the device 
 +    dwf.FDwfAnalogInReset(hdwf)  # reset the oscilloscope 
 +    dwf.FDwfDeviceClose(hdwf)   # disconnect the device</code> 
 +</WRAP></WRAP>
 </WRAP> </WRAP>
 ---- ----
  
-===== Script Overview =====+===== Testing ===== 
 +<WRAP group> 
 +Start the script with the following command: 
 +<code>sudo python3 /mnt/logger.py</code> 
 +To terminate the script and to close the file, press "Ctrl+C" on the keyboard. When the script is exited, the file is saved on your USB flash drive. 
 +</WRAP> 
 +----
  
 +===== Next Steps =====
 +<WRAP group>
 +The script can be modified as needed for your project.
 +
 +For more information on WaveForms SDK, see its [[software:waveforms:waveforms-sdk:start|Resource Center]].
 +
 +For technical support, please visit the [[https://forum.digilentinc.com/forum/8-test-and-measurement/|Test and Measurement]] section of the Digilent Forums.
 +</WRAP>