New domain and blog

New domain and blog
Please head over to my new domain to view my blog and current projects

Wednesday 23 April 2014

Online Tools

I have come across two online tools over the last few weeks which I have found really useful. I normally use offline programs to edit images, create images with transparent backgrounds and create diagrams and flow charts.

Online Developer Tools

There are some times that using an offline, installed program is not possible. Some companies restrict the type of programs that are installed, especially if they are free and open source. The reason for this list that I am going to build, is to help point people to websites that work, and also as a reminder to me when I need them again and don’t have access to my browser bookmarks.

I have also listed some of the offline tools that I use which offer a lot more functionality.

UML Diagrams and flowcharts (online):
  • draw.io is a free online diagram drawing application for workflow, BPM, org charts, UML, ER, network diagrams. There is also an addon for Google Chrome which can be found herehttps://www.draw.io/
Image Creators and Editors (online):
  • Free Online Image Editor is an editor where you can create your own animated gifs, resize and crop images, create images with transparent backgrounds and many other image manipulation tools. http://www.online-image-editor.com/
Image Creators and Editors (offline):
  • Inkscape is an open-source vector graphics editor similar to Adobe Illustrator, Corel Draw, Freehand, or Xara X. What sets Inkscape apart is its use of Scalable Vector Graphics (SVG), an open XML-based W3C standard, as the native format. http://www.inkscape.org/en/
  • GIMP is a raster graphics editor used for image retouching and editing, free-form drawing, resizing, cropping, photo-montages, converting between different image formats, and more specialized tasks. http://www.gimp.org/
Project Management:
  • Trello is the fastest, easiest way to organize anything, from your day-to-day work, to a favourite side project, to your greatest life plans. https://trello.com/
LabVIEW:
  • Revert by LabVIEW Hacker is an online tool that can be used to convert vi's to previous versions of LabVIEW. This tool is still in Beta form, but works and is really useful when you don't have access to the latest version of LabVIEW. https://www.labviewhacker.com/revert/
These are the ones that I have been using and have found to be really helpful lately. Please feel free to add others to the comments and I will then update the list above.

Greg

Tuesday 22 April 2014

This blog is moving…

After running Etching Pathways for a few years, I have decided to move it to my own domain. The idea will be the same, where I post about topics that interest me and projects that I have worked on. I have been a bit quiet over the last few months, this is due to me changing jobs and trying to find a new path for my career, where I can accomplish the goals that I have set out for myself.


One of the reasons for the move, is that I am starting to venture out of permanent employment and into contracting, specifically National Instruments LabVIEW Automated Test Development. This is an area of electronics that I enjoy, where I can use tools that I believe in and support and where I think I can make a difference.

I am half way through my first contract doing test development for an RF company, and so far it is going really well. I am enjoying the work, enjoying the industry as well as enjoying the flexibility that contracting offers. 

Another area that has been taking up my time is putting together a presentation for the UK CLD Summit to be hosted at the NI UK and Ireland headquarters during May. It is a project that I have been thinking about for some time and am making some good progress. The current goal is to do angular measurements of a mirror using LabVIEW Vision Development Module. Once I have everything working and my presentation complete, I will do a more in-depth post about it.


I also have a few other ideas to write about which I hope I can put together soon. To get to my new website and blog, please head over to www.labvolution.com.
Greg

Monday 13 January 2014

LabVIEW: Web Services Part 3

In Part 2 we had a look at connecting hardware and toggling the state on two LED’s using a form and a method VI.

Moving to the next stage of my project, I added a DS18B20 temperature sensor to log the temperature at set intervals. This interval is defined by using a variable constant. The temperature is logged to an SQLite3 database and when queried, displays the temperature profile in a Highcharts chart in the browser. Dates to display are chosen using a jQueryUI datepicker.


Logging temperature:

Temperature is logged every 60 seconds as set by Constants.lvlib:TemperatureLogDelay.vi. This VI is opened and run by reference from within Startup.vi when the server is started. It continues to run in the background as long as the server is running. 


Once the temperature has been read from the LaunchPad, it is logged in an SQLite3 database. I used a library written by Dr James Powell which can be downloaded from the LAVA Code Repository


The temperature is logged alongside the current date and time. The data and time string is used to choose what date range to display in the chart.

Query the temperature:

To query the database for the temperature range that we want to display, I use a jQueryUI datepicker. This gives me the dates that I want to look at and then I add the time in LabVIEW. I use a form with another GET method to pass the dates into LabVIEW and then I run the query there. 


The data gets returned from the query in the form or arrays.

Create JSON file:

Once I have an array of dates and temperatures, I need to reformat the arrays into a JSON string which Highcharts can understand. I start off my formatting each array into the correct format string and then create the complete JSON string. 


This string is then written to a .json file which is read by the javascript to display the chart.

Adding static files:

As we are using more API’s, we need to add these files to the static directories. To the static/css directory, add the jQuery datapicker theme. To the static/js directory, add the Highcharts, jQuery and jQuery datapicker js files. 


Editing chart.html:

The last thing to do is to add the <script> and html code to display the datepicker and chart. 


If no dates are selected, the today’s dates will be chosen by default.

A JSON file is then created from the query results. This file is saved into the static/json directory where it is read from within the script.

The webpage is then updated with the chart showing the temperatures for the dates selected. The settings of the chart and also the type of chart can be changed to whatever you like. Have a look at the Highcharts API for all the options. 

That is all for Part 3. You can find Part 2 here and Part 1 here. The completed project so far can be downloaded from here.

As always, comments and tips are always appreciated. 

Greg

Wednesday 8 January 2014

LabVIEW: Web Services Part 2

After making a basic webpage in my previous post, I wanted to expand on it by adding some control. I have used a TI MSP430 LaunchPad as my connected hardware.

To start off, you can download the updated project from here. You can also get the LaunchPad code here which has been compiled in CCS 5.5.

In this version, I added two radio buttons to the main page and two normal buttons to submit the selection. I then used an html form with a GET method to pass the selection from the webpage into LabVIEW. Depending on the selection made, LabVIEW controlled the state change of the LaunchPad LED’s through VISA functions.


The following instructions add on from the project in Part 1.

Editing the html page:

Start off by adding the <form></form> code to index.html. This will allow you to send data from the webpage back into LabVIEW at the press of a button. The method being used is GET and the action points to a VI which will handle the data.


This code will create two radio buttons and two normal buttons. When a button is pressed, the status of the radio button selected and which button pressed will be sent to the VI called ToggleLED in the WebService folder.

Creating the Web Resource:

We need to create a VI which will receive the data from the form. Right click on the Web Resources folder in the LabVIEW project and select New VI.


Save this file as ToggleLED.vi in a folder called ‘Web Resources’ in the root directory and close it. We will come back to it later.

Adding Private Content:

The private content that we need to add are the VI’s that communicate with the external hardware. Make a folder called ‘private content’ in the root directory. Right click on WebService in the project and select Add Private Content Folder. Navigate into the created folder and select Select Folder.


Copy over the VI’s from my download project into this Private Folder. These VI’s include the library to communicate with the LaunchPad, a Variable Constants library and the VI that sends the commands.

Adding a Startup VI:

A Startup VI will run when the server is started and continue to run until the server is stopped. We will be using this VI to open and close the connection to the LaunchPad as the server is started and stopped.


Save the VI in a ‘Startup VI’ folder. Either create a new VI or copy mine and add it in the project. The VI should look like this.


Create the GET VI:

Now that we have added all the dependencies, we can go back and complete ToggleLED.vi. This VI needs to read the form data, pass the data to CommunicateToLaunchPad.vi and then redirect back to the main page.


We use the function Read Form Data.vi located in Functions>>Connectivity>>Web Services. The data is then passed into a subVI where the decision is made on what command to send to the LaunchPad. Notice that I have used a Variable Constant for the VISA Resource Name.

Once the hardware communication is complete, I redirect back to the index page. To get the original URL, use the Read Request Variable.vi function with the variable name REFERER. This will return the URL which can be passed into Set HTTP Redirect.vi.

Complete project:

Now that we have added all the files, we should have a complete project that looks like this.


We should now be ready to test our website. Save the entire project and Start the server. Navigate to the URL and you should see the following page.


Once the server is running and the page is open in the browser, open ToggleLED.vi front panel from the LabVIEW project. Select one of the radio buttons and then press a button. You will now be able to see what commands were received by LabVIEW by inspecting the indicators in ToggleLED.vi.

I have disabled the VISA functions in the uploaded project. If you want to try them, all you need to do is remove the Diagram Disable Structures from Startup.vi and ToggleLED.vi. This will then communicate with the LaunchPad; however if there is no hardware connected, the redirect will not work and an XML page will be returned after a button is pressed. You will also need to change the VISA Resource in Constants.lvlib:VisaPortNumber.vi.

That’s all for Part 2. If you have any questions, comments or advice for me, please leave a comment below. Part 3 should be up once I have decided on what to add and figured out how to do it.

Greg

Tuesday 7 January 2014

LabVIEW: Web Services with Twitter Bootstrap

I have been playing around with the updated Web Services feature in LabVIEW 2013 the last few days. My plan is to write a few posts where I create a simple website hosted by LabVIEW which can control some hardware from the browser.

I have done this in the past with my Raspberry Pi, but wanted to give it a go using LabVIEW instead.

This first post will cover how to set up the project, how to serve static pages and also how to link in third party code. The two third party products that I will be using are Twitter Bootstrap and jQuery.

Here is the website that will be designed in the post.


Start off by creating a blank project from LabVIEW templates. Save the project and then in the project, right click on My Computer and select New > Web Service.


This creates the Web Service in your project.


Create the folder structure in Windows Explorer for your public content. I use the following structure created in the project root directory:


Once the folder structure has been created, it needs to be added to the project. Add the folder by right clicking on WebService in the project and selecting Add Public Content Folder. Navigate to the Public Content folder created in the previous step and click Select Folder.


Now that the folder structure has been created, we need to add the source files. Download my project here to get the Bootstrap, jQuery, html and images that I used. Add them in Windows Explorer and they will be automatically added in the project as the folders are set to Auto Populate. Once you are done the project should look like this.


Use the Bootstrap and jQuery links above to get the latest versions if you want. Then just replace the files.

Open the three html files in a text editor of your choice. I use Notepad++ which I think is the best editor that I have tried. It also colours the text depending on the language used and is open source.

When linking to the css, js, jpg files from html, the path is relative to the html path. In this project you will use the path “static/folder/file” where folder is the type of file and file is the full file name including extension. 

Now that we have the files and project in place we are ready to run the server and open the webpage, but first save the project and all the components.

Right click on WebService and select Start. This will bring up a dialog to display that the webserver is running.


Now you need to get the URL to connect to. Right click on index.html and select Show Public URL. Copy the URL that is shown in the dialog.


Once you have the URL copied, close the dialog and paste the URL into a browser. Your webpage should now run. Once running, you can navigate between the three html pages using the links at the top of the page.

If you decide to change the html code, you do not need to restart the server after each change. All you need to do is refresh the browser.

That is it for Part 1. I will now make some changes and get Part 2 up as soon as I can.

If you have any comments, questions or tips for me, please leave a message in the comments section below. Thanks for reading.

Greg

Tuesday 10 December 2013

LabVIEW: Getting started with LVOOP

I have been trying to get a handle on LVOOP for many months now but have been battling to get the concept into my head. I understand the concept of OOP, or at least I think I do, but really battling to convert that into the LabVIEW world.

Here is a list of resources that I used to try and figure it out:

There have been other articles that I have used, but none that I could find started from a blank project to build a basic application. 

So I set about to try write one from scratch. I used the example from the video of a Mammal Parent class with a few Child classes. Here is the UML diagram of what I had planned. I found a great online tool to create the UML diagrams. Have a look here.


As can be seen from the above diagram, I have a project with five classes, each has Dynamically Dispatched vi’s and one has vi’s for Data Member Access.

So that is the idea of my simple program, here is a step-by-step list of what I did:

Create a blank project and add five virtual folders. Add folders with the same names to the project directory on disk.

Create main.vi which will be your application.


Create the Mammal.lvclass inside the Mammal folder.


Save the class in the Mammel folder on the disk. 

Next you need to create the methods for Move() and Speak() using the Dynamic Dispatch Template.


Add a blank string indicator and wire it to the connector pane. Do this for Move.vi and Speak.vi.


You have now created the Parent class with two methods that can be overridden by the Child classes.

The next step is to create the Dog, Cat and Human classes that will inherit from Mammal class and the Baby Human class that will inherit from the Human class.

Dog, Cat, Human classes:

Create the new classes and leave the control blank. Save the classes to their folders that have been created on the disk. Then edit the Inheritance settings in the class properties dialog. Each class needs to inherit from Mammal.lvclass.


Create a ‘VI for Override’ vi for Move and Speak. Edit the block diagram for each to look like this. In total three extra Speak and three extra Move vi’s should be created. One each for the Dog, Cat and Human classes.



The string constant in the No Error case gets changed for each method. This is the string that will be displayed in the main application.

Baby Human class:

Create a new class called Baby Human.lvclass and set it to inherit from Human.lvclass.

Open the ‘Baby Human.ctl’ control and add two strings to the cluster. Name them Movement and Voice. By adding controls here, we will be able to change the string that gets displayed at runtime. (Note that the Movement and Voice was hard coded in Dog, Cat and Human)


Next you need to make four vi’s for Data Member Access. These vi’s will be public and used to read and write the private data.


Select ‘Read and Write’ for Movement and Voice. Edit the icon for each if you want and then save the created vi’s.

Next you need to create the vi’s that override the Human Move.vi and Speak.vi. Follow the steps above to create ‘VI for Override’. They should look like this.



All of the above steps should set up the classes that are needed to write main.vi. I am going to write a simple application which creates an object of each class, builds an array and then displays each Move and Speak value in a For Loop. When we add the Baby Human class, we need to Set the values for Movement and Voice before we bundle the array.

For each object that gets passed into the For Loop, the associated Move and Speak method will be dynamically called. 



If you change the Movement and Voice of the Baby Human class on the front panel, that change will be displayed when the application is run. 

After going through this exercise I think I am starting to get a better understanding of LVOOP. I have a very long way still to go, but I now feel that I am at least on the pathway. I hope this has made sense and is able to help someone getting started. 

If I made mistakes, please leave a comment so that I can correct it. You can get a copy of my project here.

Greg

Thursday 5 December 2013

LabVIEW: Creating Custom Templates and Sample Projects

The new ‘Create Project’ feature added to LabVIEW 2012 is great and I use it a lot when starting a program. However, I found myself making common changes to the templates before I started writing a program. The main changes were removing the ‘Something’ buttons and events. This isn’t a lot of work but does take time and becomes rather tedious.

One solution is to use the Create Project feature with a custom template. It is rather easy to set up and works really well after getting over a few minor hurdles.

I started off with creating a new QMH project from the default template. I made a few changes to the project and then saved the project how I wanted the template to work.


Some of the changes that I made were:
  • Removing the Something and Something Else buttons, events and cases
  • Changed the queue message from a String to a Type Def Enum. This makes the Consumer case a lot easier to set up and eliminates spelling mistakes
  • Added a case to read in a configuration XML file
  • Replaced constants with variable constants
  • Remove the Stop button to use the ‘X’ to stop the program

Once you have the template set up, save the project and close it. Navigate to the ‘LabVIEW Data’ folder in ‘My Documents’. Inside this folder, create new folders with the following structure. 
--ProjectTemplates
      |--CategoryOverides
      |--MetaData
      |--Source

Place your template into the Source folder. Make sure that Auto Populating Folders is DISABLED in the .lvproj. This caused me a lot of troubles getting set up.

The next thing to do is create an xml file in the MetaData folder. Call this file TemplateMetaData.xml. I used the default xml file as a template to get started. This is what my file looks like:

To get an explanation on the different keywords, have a look at this white paper from NI.
Once you have the xml file saved in the MetaData folder and the template project in the Source folder, you should be ready to go.



As can be seen from above, my custom project is now added to the Create Project wizard. Just follow the normal wizard to create a new project and get programming right away.

The main problem that I ran into was setting my folders to auto populate in the template. Once I switched that off everything ran smoothly.

Have fun creating new templates and projects.

Greg

Friday 22 November 2013

LabVIEW: Looking at constants differently

I have started listening to the LabVIEW podcast by VI Shots and am finding them really interesting. The last one I listened to was Five Tips to improve your LabVIEW Application with Fabiola De La Cueva. After listening to the podcast, I could relate to most of the tips and see where I was going wrong.

Then earlier this week I attended NI Days where I went to a presentation by LabVIEW Champion, Steve Watts and he spoke about the same subject. This triggered in my head that I should start to make an effort to create a set of rules for myself to stick to in all my applications.

So today I started by looking at constants differently.


This is from Fabiola’s presentation where she asks what is a constant?

As can be seen from the slide above, PI is a constant, the number of seconds in a minute is a constant but the number of flux capacitors in the DeLorean might change so is therefore not a constant. 

This means that using ‘constants’ in a program should be limited to ‘True Constants’ and ‘Variable Constants’ should either be wrapped in a vi or loaded from a configuration file.

Wrapping a constant in a vi and adding all your applications’ constants to the project makes them easy to manage and change if needed.
I have created a library which I will add to all my projects. This library will then be used as a template for the most common constants used in an application. I then make copies of each as needed, name them ‘xxx_constant.vi’ and use a comment in the application to indicate what the constant does.

I have tried to keep the icon colour the same as the default wire colour for each type making reading the application easier. You can get a copy of my library here if you want to have a look at it or use it.

The other method mentioned in the presentation is reading variable constants in from a configuration file. I have also tried this using an XML file which works well and is quick to implement. I will do another post with my vi’s I used some other time.

I hope this post has been able to help someone use better style. If I have done something wrong or not understood the concept properly, please leave a comment and let me know so that I can correct it and learn better style.

Greg

Monday 14 October 2013

LabVIEW: Certified LabVIEW Developer exam

After months of preparing and wondering when I am going to get to write the National Instruments Certified LabVIEW Developer exam, I managed to get back to the UK and into the September exam.

I felt really confident going into the exam, but a little nervous not knowing what to expect. The program I had to write was similar to the example questions with a few added twists thrown in. Doing the LabVIEW Core 3 course helped a huge amount.

I walked out of the exam rather unsure what had just happened. The first two hours went rather slowly and I thought I was doing well. Then the next two hours flew past without me even realising it. I managed to get to a natural break with about 15 minutes to go. I hadn't finished all the required functions, but what I had worked as it should so I decided to stop adding more functions. Then I spent the last 15 minutes cleaning up my style and making sure that all the code was commented. This is where most of the marks come from so I wanted to make sure I got them.

I walked out the exam not really knowing what to think. I hadn't finished the entire program which was a disappointment, but I knew what I had done worked, looked good and was commented. All I could do now was to wait. 

Four weeks later and then email I had been waiting for arrived. I opened it and saw that I had PASSED. So after months of practicing, weeks of nervous waiting, I can eventually say that I am CLD certified.


I am really grateful to everyone who helped me with advice and to National Instruments who presented amazing courses. The next step now is to find a job and get working. I can't wait and am really looking forward to putting into practice the skills that I have learnt over the last few months.

Greg

Monday 2 September 2013

LabVIEW and Raspberry Pi TCP/IP Communications

A few months ago I did the LabVIEW Connectivity course at National Instruments UK. I really enjoyed it but haven't got around to trying any of the concepts out yet. Last week I decided to write a TCP/IP chat program working between LabVIEW running on my Windows laptop and Python running my Raspberry Pi.


On the left of the you can see the LabVEIW front panel running the server. On the right is the putty terminal running a Python client. At the moment I only have the functionality to connect one client to the server. 

This little project got me thinking and I learnt quite a few new concepts. 

LabVIEW Server:

I used the LabVIEW example finder to get started. 


The LabVIEW server starts off my listening for connections. I have set a 60 sec timeout for this wait. Once connected, there are two parallel loops running. One loop is used to transmit strings and the other loop is used to receive strings. 

To transmit a string, the user types the string in the User Input control and presses the Return key. An end of line character is then concatenated onto the string which is transmitted using TCP Write. 

To receive a string, the TCP Read function listens with a timeout of 100 ms. If a string is received, it is concatenated onto the Response String indicator. 

Python Client:

This is where things got interesting. I needed to use threads, timeouts and sockets, each of which I have never used before. This client was written in Python 3.2.


I ended up using two threads. One for the transmit and the other for the receive controls.

I used a global variable which is used to stop the threads when the client or server is stopped. I also needed to use a timeout in both the transmit and receive thread because the recv() and readline() methods blocked the program flow which locked up the threads if the client was stopped.

With the timeout set, I could monitor the global variable and return cleanly from the thread when the client or server was stopped.

First start the LabVIEW server, then within 60 sec run the Python client. The connection will be established and you will be able to send strings between LabVIEW and the Raspberry Pi. To stop the programs, either use the Stop button in LabVIEW or CTRL+C in Python. Both methods will stop both the server and the client.

To download the LabVIEW and Python code, use this link.

I am sure there are many methods to do what I have done here, even better, cleaner ones. My Python is all self taught and only being used for my hobbies. I am using my Raspberry Pi for what is was designed for; learning. If you can recommend a better way to do this, please let me know because I am always keen to learn something new.

Greg