The main effort in setting up a LabRAD system consists of writing the customized server modules that interface LabRAD with your specific experiment. If you are lucky, all the servers you need have already been written and are available in the Modules section, but chances are you have to write at least some of them yourself. But no worries, writing a LabRAD Server Module usually does not take any more effort than writing a conventional package, unit, or sub-VI that performs the same tasks (which you need either way). In fact, sometimes it can be quite a bit easier, especially if you have to worry about concurrent resource access, which LabRAD mostly manages for you.
For the purposes of continuing this tutorial, let's assume you have all your server modules running. Then, your LabRAD System will provide you with ways to configure your next data taking run and to request one or more data-points at a time. At that point, all you have to do is to write small scripts that collect these data-points and pass them straight to the Data Vault for storage, plotting, etc.
Let's simulate this functionality with a server that allows you to take data on different fractals.
Simply run FractalServer-v1.0.1.exe like always and make sure it shows up in the Explorer. The Fractal Server's main window will look like this:
The Explorer will again allow you to quickly look over the functions that this server provides and how to use them.
To simulate a data-taking session, we will have the Fractal Server generate a small Dragon Curve and we will pass the result on to the Data Vault so we can look at it with the Grapher.
In normal operation, the first things that your data taking scripts will do is to prepare a new dataset with the Data Vault to hold the incoming data-points. Next, your script sets up all instruments and parameters that will define the data run. Let's do this for our Dragon Curve.
To initialize the dataset, make a packet for the Data Vault containing a single record for the cd setting with content ['', 'Test', 'Fractals'], True. Notice that True here will tell the Data Vault to create all needed sub-directories if they don't already exist. In the Grapher, navigate into the >> Test >> Fractals directory and make sure you have the Live View window showing. Back in the Explorer, make a new packet for the Data Vault with two records, one for the new setting with content 'Dragon Curve', [('x','')], [('y','','')] and one for the add parameter setting with content 'Iterations', 6. Send the packet and the Data Vault will create the new dataset and store the parameter we gave it. The Grapher will detect this and open the new dataset.
Now, we need to configure our data taking run, i.e. initialize the Dragon Curve generator, by telling it the iteration depth to use for the curve. Send a packet to Fractals with one record for Init Dragon containing 6. The answer you will get will tell you how many points are in the Dragon Curve; for 6 iterations it will be 129. Since the number of points in the curve scales exponentially with the number of iterations, this is a good check for you to determine whether your request is feasible.
We're now ready to "take our data". We'll do this by sending a packet to Fractals with a record for the Dragon setting containing 129. With this, we are asking the Fractal Server to return all 129 points in the curve in one shot. The answer packet will contain a long list of numbers that you need to copy to the clipboard by clicking on the Copy button in the top right of the content editor. Now open your favorite text-editor, like Notepad.exe, and paste the data into it. Use the editor's replace all feature to convert all parentheses into square brackets, i.e. replace ( by [ and ) by ]. This step is necessary since the Fractal Server returns an array of clusters of values, but the Data Vault expects a 2D array of values (This will change in the Delphi version of the Data Vault). Copy the modified data back onto the clipboard.
Now, back in the Explorer, make a new packet for the Data Vault with a record for the add setting and paste the data into the content editor using the Paste button. Send the packet and the Dragon Curve will appear in the Grapher's plot and you can compare it with the ones shown on Wikipedia. The plot you get should look like this (after turning the dots off):
Feel free to generate more Dragon Curves with different iteration counts this way, but you probably won't want to play with any of the other fractals using the Explorer since they will require larger amounts of data to be shuffled around.
Note on Performance: You probably can NOT use the Explorer very well to estimate the performance you will be able to get out of LabRAD. The main reason for this is that the code in the Explorer that fills the Content Editor and highlights the text is EXTREMELY inefficient. Thus, things will always seem very sluggish if you edit, view, or copy/paste large data structures in the Content Editor. You can get a slightly better idea if you look at the responsiveness of the Grapher in browsing and displaying datasets. But even though its code is much more optimized, the bottleneck still is the GUI management.
Even though you could, using the Explorer is definitely not the way you want to be taking data on your real LabRAD Setup. For that, you will need to use one of the programming languages supported by one of the LabRAD APIs. In the next part of this tutorial, you will select your favorite programming language to write some data-taking scripts to automate the things you just did in the Explorer. Then you will also get a first glimpse at the true performance you will be able to get out of a LabRAD Setup on your computer.
At this point, I would like to encourage you to make sure you check out the Python API at some point. For quick scripting, Python is an amazingly efficient language, which makes it perfect for taking data once your LabRAD Setup is ready. It is also very well suited for the development of Server Modules, since they usually don't require a GUI interface. In fact, many of the premade LabRAD Modules you will find will most likely be written in Python, because of its rapid development capabilities. And on top of it all: Python is FREE and cross-platform! Can't beat that!
Since some of the following tutorials will be provided by other developers, I would like to take this moment to thank you for your interest in our project and I hope that it will improve the code-base, performance, and turn-around times in your lab as much as it did in ours. Please let us know if you have any comments about or problems with this tutorial by posting your feedback in the Tutorial Discussion Forum of this project. We're looking forward to hearing from you!
Best wishes,
Markus Ansmann
... Python
... Delphi
... LabVIEW
... Java
~ Markus Ansmann, Feb 20th, 2008
Discussion: 788280
Wiki: APIs
Wiki: QuickStart
Wiki: QuickStartDataVaultAndGrapher
LabRAD for LabVIEW: Wiki: MainTutorial
LabRAD Modules: Wiki: Home