This lab was an introduction to LabVIEW, which is a programing language for (generally) National Instruments lab equipment.
I began the lab by forking the github project form PhD. Koch’s github page. Since this my first experience with LabVIEW, I started reading the basics from the “Intro to LabVIEW” webpage (http://www.ni.com/gettingstarted/labviewbasics/) until I decided to just learn the rest by trying to recreate PhD. Koch’s code right away. However, I did reference the intro page while I was working throughout the coding process.
The purpose of the program, or virtual instrument (VI), was to generate a random amount of exponentially distributed numbers, as well as create a histogram and a spreadsheet text file of these numbers.
Creating the Code
Just to clarify, LabVIEW has two windows: a block diagram (where you write your code aka the inside of the instrument) and a front panel (where the results of your code run aka the ‘front panel’ of the instrument). Hence, I started coding in the block diagram.
Brief overview: The main feature of the code is a forloop. The commands that go inside the forloop to create –ln(x) were the easiest to find, so I began inserting those first and attached the numerical controls to the forloop. From inside the forloop I connected the waveform graph. Then I connected the other numerical control, the histogram, and the XY graph together and connected the numerical control to the wire connecting the waveform graph and the forloop. This plots the histogram of the random numbers. From the XY graph I connected the case structure. The case structure contained the spreadsheet with a couple of commands to organize the compatibility of the datatypes. This transfers the random numbers to a text file. Finally, I added a boolean data type which turns the option of saving the text file on or off since saving the file is an inherent property of the case structure.
After I was done coding, I saved the files to the git directory on the lab computer. Then added, commited and pushed them to github.
Problems and Solutions
- Commands and functions.
Finding some of the commands and functions was difficult, namely the waveform graph and the XY graph. I found out I wasn’t able to find them before because I was looking for them in the block diagram functions– it turns out the front panel has its own functions (!) and can be accessed by right-clicking anywhere on the front panel.
Different colored wires carry different datatypes. This became evident when I tried connecting the data from the XY graph to the spreadsheet directly and obtained an error. It turns out you need to connect the XY graph to the unbundle command (splits datatypes) , which needs to be connected to the build array command (compiles the separate arrays into one n-dimentional array), which is connected to the spreadsheet.
The biggest difficulty in creating the spreadsheet was actually covered in #2. However, there were some extra elements of the spreadsheet that were also tricky. As mentioned before, the case structure automatically pops up the “Save as” window for the spreadsheet text file. To manage this, the boolean datatype was connected to the case structure. Now the “Save as” window can be turned on or off.
– ctrl h : pops up a help window which will give a brief overview depending on which function/command you place your curser over
– ctrl e : switches between the front panel and the block diagram
– git status : gives you a status on your files, whether they’re tracked or not
– git add nameofyourfile : adds untracked files one by one
– git add * : adds ALL the untracked files to the staging area, which is the step before commiting (figure 2)
– git commit : commits the files on the repository of the local machine
– git push origin master : pushes the files from repository to github
– You can press tab to fill in the name of a file or directory
Figure 2. A situation where git add * is preferable over git add.
PhD. Koch helped me with setting up a new key (I had to switch to another lab computer), forking the project, the three problems mentioned above, and pretty much explained each command or tip listed (including others which aren’t listed since I forgot to write them down) in the toolbox.