Menu

Tag Archives: LabVIEW

As anyone who has read my blog previously, you will know that I am a big fan of Actor Framework. It is a fantastic way of creating highly robust and scalable asynchronous process applications.

Having said all that, my biggest reservation about Actor has always been that because of the way the messaging between Actors works, out of the box Actors are strongly coupled. In a lot, maybe most instances this is not an issue as you may be putting together an application whereby the different Actors benefit from being strongly coupled or there is no benefit to decoupling them, but I’ve also come across a few use cases where I want to be able to completely decouple individual Actors for testing, and to allow multiple people to work on the same application.

One solution to this is abstract message classes, and one of the places where I’ve found this comes in really useful is adding a TCP/IP socket onto an existing Actor.

Initially this came from working on a project where I’d created a no abstract messages TCP/IP Actor, but then another project came along that also required TCP/IP control so I refactored my TCP/IP Actor with abstract messages to re-use it.

How this worked in practice is that in the original coupled TCP/IP Actor to communicate with its caller, I enqueued two messages to report the TCP/IP Actors status in terms of clients connected, and also to communicate messages received to the caller. The caller was then able to ‘Do’ these messages, and enqueue a message on the TCP/IP Actor to communicate back to a client.

The process to convert a non-abstract message to abstract is fairly straightforward using the following process:-

Create your message as usual using the Actor Framework Message Maker

Remove the ‘Do’ and ‘Send’ methods from the Message Class.

In the class properties, under the ‘Inheritiance’ Category, check ‘Transfer all Must Override requirements to descendant classes’.

To understand why you need to do this, open Message.lvclass from the ActorFramework directory under vi.lib. Under Item Settings in the class properties, if you select ‘Do.vi’ you will notice that the checkbox ‘Require descendant classes to override this dynamic dispatch VI’ is checked. This forces any classes that inherit from Message.lvclass to have to implement this method, by using ‘Transfer all Must Override requirements to descendant classes’ it removes this requirement from the class you are inheriting into, but pushes the requirement down to any child classes of itself and allows the class to compile.

Next you need to expose any properties of the Abstract Message, as we no longer have a send method to encapsulate these (although there’s no reason why you couldn’t create a new one and pass in the class type) so we will have to set them via property nodes and will use the Enqueue.vi directly.

Because the Do method has been removed, if the TCP/IP Actor wants to send the message to its caller, there won’t be anything to execute, so now you have to create a message class that inherits from the abstract class and create an instance of the Do method. This will be specific for the particular caller Actor you want to use it with.

Now you’ve inherited these Concrete classes from the Abstract classes, you now need to tell the TCP/IP Actor to use these classes at runtime, I personally tend to do this using a Constructor and passing in the concrete classes to be held in private data.

This means that now, when you want to send what was originally a specific caller message, you now have to pull what class the caller specified to use out of private data, populate its properties and enqueue it on the callers message queue.

You obviously also need to go back to your new Concrete classes and populate their Do methods for anything to happen.

Exploring the demo

If you follow the link below, you can find a zip file of a TCP – IP Test Actor, interfacing to my abstract TCP/IP Actor with abstract messages.

Start by running Main.vi from TCP – IP Test Actor.lvlib to bring up the Test Actor.

Then run Main.vi from TCP – IP Client GUI Actor.lvlib.

On the TCP – IP Client GUI the available commands are populated from TCP – IP Remote Control Actor\TCP – IP Client GUI Actor and are in a tsv format.

From the Remote Client GUI you should first of all click ‘Open’ to begin a session with the TCP – IP Remote Actor. You should notice that as well as the light on the Remote Client GUI lighting up, you should also see the Connections light on the TCP – IP Test Actor GUI also light up, and the No. Clients indicator show 1. NOTE: you can now open up another Remote Client GUI and do the same again, and this should increment to 2.

Now a session is open, you can select commands from the pulldown, and populate the parameters and these will update those on the TCP IP Test Actor, or alternatively if you use the GetNumeric, it will return the value of the Numeric Indicator.

The key to all of this working is the TCP – IP Test Actor.lvclass:Handle Remote Command.vi. This is called from the Do method of the Concrete class Remote Command handler MSG.lvclass, and there is an equivalent VI called from the Do method of Remote Connection Status Msg.lvclass.

You will also find a VI called ‘Basic Example.vi’ under TCP – IP Remote Control Actor.lvlib\Test that demonstrates how to make single writes to the remote actor.

There’s probably not much more to add so please have an explore of the code, and message me if you have any questions, problems, or recommendations. Feel free to re-use any parts of this demo, as by design you should be able to pick up the client GUI and remote control Actor and attach it to any of your own Actors, but please remember give me credit if you do 🙂 Thanks, Dave.

Most of my blogs so far have been very LabVIEW focused – not surprisingly as it is the tool I make the most use of in my day to day work, and of all the languages I do is the one I am the most fluent in and feel most comfortable using.

I consider it to be the best tool currently out there for doing test, control and measurement and certainly in the National Instruments (NI) world it is the ‘prima donna’, getting more exposure than probably all of NI’s other tools put together.

There is however another tool in the NI stable that is arguably the real star of the show and beats LabVIEW (and anything else I can think of) hands down when it comes to the particular task of test sequencing and that is TestStand.

TestStand Sequence Editor

It is a tool that as far as I’m aware is almost unique in the world – out of the box it allows highly complex sequences to be built up using LabVIEW, .NET and many other languages, a wide variety of synchronisation options such as while loops, if statements, delays etc. The ability to utilise multiple test sockets and manage them concurrently or individually. Full user management capabilities, the ability to load in limits from file or database, and a mind boggling array of reporting options.

This only scratches the surface of what TestStand can do and there is simply nothing else on the market that even gets close to it with just these features.

It goes further though, as if out of the box TestStand doesn’t do exactly what you want it to do, there are almost infinite ways in which you can customise and interface to it without losing that core sequencing ability – it is a marvel of software engineering, but one that does it’s business in the shadow of it’s far louder, brasher, more exciting brother.

What is so strange about me saying all of this is that at one point in my life I absolutely loathed TestStand, and couldn’t see why you’d want to use it over LabVIEW or .NET for instance.

My journey from hater to lover was a difficult one. I was working on a project testing a mega complex satellite payload equipment. Throughout the project I was on an almost vertical learning curve in many aspects – it was the first satellite payload I’d worked on, the first time I’d used much of the instrumentation being used, and all this working in a new company.

We were to use TestStand and LabVIEW to develop the test software, with test planning, and results handling being done by a very clever .NET application which interfaced to TestStand but not LabVIEW. I didn’t have much experience with TestStand at the time, but plenty with LabVIEW having already been a CLD for a couple of years and having recently passed my CLA, and having a certain aversion to TestStand I wanted to minimise my use of it to simply call large single blocks of LabVIEW that did a test and returned a big cluster of results that TestStand then reported to the test database.

As a pure bit of LabVIEW software I was very pleased with it. I’d made significant use of the newly released Object Orientated features of LabVIEW and created what I felt was a very well structured, lean and robust bit of code.

For the most part I was right, but I was soon to discover that doing it this way had a number of drawbacks all of which could have been avoided by using TestStand.

The first was that as much as LabVIEW block diagrams are easy to read for those of us who use the language on a daily basis, trying to demonstrate to RF engineers who have never used LabVIEW that you have implemented their procedure to the letter in a VI with looping etc was not easy, TestStand’s intuitive interface was a far better environment for doing this.

The second was that I had configured all my limits in LabVIEW – either hardcoded in VI’s (virtual suicide), or read from ini files. It seemed like a good idea at the time, but then the requirements changed, and it meant that rather than just modifying a completely separate file, I had to actually open the code, modify a limits VI, and then rebuild the software – utterly nuts looking back! The way I should have done it, and the way I have been doing it ever since is to configure limits within TestStand and then use the in-built property loader to export and import values at runtime and pass these into the LabVIEW code modules.

The third was that dealing with highly precise measurements, our RF engineer friends would go through the software with a fine toothcomb wanting to examine in minute detail every step of the test and would make requests like “could you run that step again with a different value”….My answer was no, as you can’t change values on the fly in LabVIEW – they are what they are. This particular problem was exacerbated by the fact that a couple of more experienced colleagues (and very smart ones at that) had done all of their test sequencing within TestStand, so they could do all of this.

A final reason was that with TestStand being the entry point and reporting tool, my clever colleagues with their detailed test sequences had oodles of detail in their test reports which meant every instrument setting, and returned result was there to be analysed. My sequences with my single step call to a LabVIEW VI had, well virtually none. It meant that whilst when one of their tests went wrong they had a raft of data to pour through to identify the problem, my software had virtually none, which meant that when the inevitable debate that usually eschews from this sort of thing of ‘is the problem with the DUT, instrumentation, bad calibrations, or your dodgy software’ kicked off I had no answer or evidence to prove that it wasn’t my software that was the problem.

I could probably add other reasons to my list of how using TestStand for sequencing rather than LabVIEW would have saved me a lot of pain and embarrassment, and I’ve probably made myself look like a bit of a dumbass to anyone reading this – maybe I was, but I’m fairly good at taking on-board criticisms (often from myself more than others!) and learning lessons from mistakes I’ve made.

I suppose there are two points here – the first is obviously related to the title of the blog, and that is that TestStand is an amazing sequencing tool in any kind of test environment, and has many advantages over using LabVIEW in this context. If you’re a die-hard LabVIEW developer, especially one who does a lot of sequencing, or is likely to then TestStand could save you an awful lot of pain – and even if you dislike it at first like so many LabVIEW developers do, I am certain that like me you will learn to love it.

The second point, and this is a more philosophical angle, is that the biggest lesson I learned from this episode is that regardless of how much faith or love you have for a particular tool, keeping an open mind to the fact that there may be better tools out there to use in certain contexts is a healthy state of mind to have, and having that attitude, and then learning to use those other tools will often reap far greater benefits than trying to make the ubiquitous square peg fit into a round hole.

I’ve had an interesting problem to solve at work this week involving creating, buffering, and then transmitting GPS signals using an NI RFSG but being able to alter those signals on the fly.

For the project as a whole we committed to using the Actor Framework early on as it is quite a complex asynchronous process application with significant inter-process communication with a strong requirement to be able to chop and change modules as well as adding new ones in at run time.

This admittedly could also be done using daemons, but the benefits of Actor such as the robust inter-communication, ease and speed of putting an infrastructure in place and the ability to very easily make an Actor Framework remote controllable and run headless via TCP/IP (which is a very common request from clients) made it a perfect fit for this job.

However, this particular problem also had state machine written all over it, and having tried to use Actor before to do state machines where you have a different VI for each state I have found that they very quickly become very difficult to debug and follow so I thought I’d have a crack at putting together something that would provide all the benefits of Actor and a single VI with a state machine and this is a demo I came up with to prove the design.

It is certainly not the most inspired demo you will ever see, it is simply an overridden Actor Core GUI with a FSM running behind it that simply cycles through states to set 4 colour boxes on the GUI and allow you to start/stop the cycling, and change the interval between each box being set.

GUI

On the GUI We have a State indicator which is set from the state machine itself and a Play, Stop, Reset Button, and FSM Interval(ms) control that trigger events in the Actor Core override and enqueue message handlers to be executed on the core.

Actor Core Override

Project

Actor Private Data

The FSM itself is a single VI that holds its state information in the Actor private data and simply iterates from an idle state to 4 states which set the colour of each color box with a one iteration delay between each.

Actor FSM

Now the cool bit, and one of the reasons I really like Actor. To run this as a state machine you use the Time-Delayed Send Message.vi to instruct the Actor Core to enqueue the state machine at certain intervals.

There are actually two ways you can do this, you can use the Time-Delayed Send Message.vi with the iterations option set to to 0 – this will enqueue the state machine at a set frequency ad-infinitum which is great, but I personally prefer the option to use Time-Delayed Send Message.vi with the iterations option set to 1 which means it will do a single enqueue of the specified message with a time delay which I do once in the overriden Actor Core to get the process started, and then at the end of every iteration of the FSM.

My main reason for this preference are primarly debug; If you use the infinite enqueue option (0) and you run the vi that is being enqueued with execution highlighting switched on, messages do not stop getting en-queued in the background so as soon as you turn off highlighting all those messages that have been en-queued will get executed one after another without any delay.

Another reason for my preference is that by en-queuing on each iteration it also means that you can alter you interval rate, so for instance when the state machine is in IDLE I enqueue an element with a delay of 1 second, then when the play button is pressed the interval is set from the from panel FSM Interval control – it is a neat little feature that I can think of many uses for i.e. the classic CLD car wash exam where you have to time each state using an elapsed time vi – well here you could simply use constants for going between states. I have also used Time-Delayed Send Message.vi quite extensively for data logging use cases where i have found it’s time to be remarkably accurate.

FSM State Enqueuer

In terms of the event handlers, well they simply set the next state of the FSM (but could obviously do a lot more) – another really nice feature of Actor in this context is that because all messages are executed in-line with the FSM it makes it very easy to debug and integrate user events with the state machine – although one thing to watch out for here is that if you are putting very small or possibly no delays between your FSM being en-queued for execution, it is worth giving you Event Handler messages high priority to ensure they always get executed as soon as an iteration of the FSM has finished or before if it is in a delayed state.

Play event handler.

Link below for project – possibly obvious, but run Main.vi to get started – LabVIEW 2013.

I am currently sitting on my sofa with way too many windows open on my laptop attempting to cram in as much information as possible for a multiple choice exam tomorrow that if I pass I will be 1/5 of the way toward becoming a National Instruments Certified LabVIEW Embedded Developer (CLED) – the other 4/5ths involve doing a 4 hour practical exam.

I need a bit of respite from the revision, so writing this is it!

This is a new exam being offered by National Instruments and has been born out of the fact that due to the distinct nature of embedded development in the LabVIEW environment having a CLD (Certified LabVIEW Developer) or CLA (Certified LabVIEW Architect) qualification doesn’t really cut it, and supposedly there have been a few issues with CLD’s and CLA’s rolling into companies proclaiming to be LabVIEW experts, working on embedded projects, and royally screwing up which isn’t only bad for the person who has screwed up, but is also not a very positive advert for the CLD and CLA community in general if someone who has jumped all the hurdles, and gone through all the pain in getting the qualifications then cannot actually do the job.

This isn’t all that surprising though. Developing for an embedded target be it a real time controller or an FPGA using LabVIEW involves first throwing out a huge swathe of best practices and habits learned over many years, and returning to basic principles such as working in bits and bytes, configuring registers, managing or at least considering memory yourself, and understanding timing constraints that are more akin to developing in say embedded C – so I think it’s a very positive thing that NI have devised this exam to test people in an embedded environment.

As part of this, NI have invited people from their alliance program to take part in a training course to prep people for the exam taught by the ever brilliant and knowledgeable Mike Bailey, and this is what I have been doing over the past couple of days with 11 other people from around the UK and Europe with all of us desperate to add to the current 7 CLED’s worldwide of which I believe only one is within Europe.

How do I rate my chances? Well it’s not looking too good right now. I’ve just finished doing the sample multiple choice paper and got a respectable 65%, but 5 short of the 70% needed to get through to the practical exam. My weaknesses are fairly clear to see; the exam is based on the real time and FPGA courses – of which I did the prior about 11 years ago, and the latter I did last summer – so no surprise that I only dropped a couple of questions in the FPGA section, and the rest of the marks in the real time section – I have a lot to learn tonight!

As ever when doing these things the question also pops up in my mind of whether all the hassle of doing certifications is really worth it i.e. the late nights revising, the stress, the time away from work taking courses, and the overall effort it takes to maintain a certification once it has been initially achieved – I mean, I know many software engineers far more successful than I think I’ll ever be and they wouldn’t touch certifications with a barge pole!

I initially decided to go the certification route about 10 years ago. The company I was working for at the time was keen on getting their employees certified and as a young graduate looking to learn and gain expertise as well as to gain the respect of his peers and improve his employment prospects it seemed like a good way to go, and I think gaining the CLD in 2004 and then the CLA for the most part achieved all of this, but 10 years on with almost 13 years of commercial development under my belt is it still really worth me maintaining existing certifications and acquiring new ones when have so much experience I can turn to?

My answer to all these questions (and this is on a personal level and not a rule I feel should be applied to everyone) is yes – for a number of reasons as follows:-

The certifications move with the products, and I believe that to survive as a software developer in most cases you have to keep up to date with the latest and greatest to keep a competitive edge renewing certifications and having to learn or refresh yourself on certain techniques is a great way to do this.

No job is forever, and I certainly don’t take my job for granted – we may be busy now where I work and I love the job, but things change rapidly; a few barren months or an undesirable change within the company that causes me to no longer enjoy working there and I could find myself back out on the job market where if things are still recessionary then every way I can differentiate myself from other candidates is welcome, and certification is definitely one way of doing this.

Customers like certifications, and it is a good marketing tool to be able to proclaim a number of certified people when bidding for work to give potential clients a certain amount of confidence that if they award you a contract then you have the skills to fulfill it – you’re low risk.

I like to have a sense that I am doing a job properly, and by following a certification track and learning best practices and understanding the various pitfalls of doing things a certain way this give me extra confidence that I am doing this. Even if I don’t necessarily always agree with every best practice or guideline, it is a good reference point and if anything, at least makes you think about things a bit more.

A major driver for me is simply the fact that I enjoy learning, but find it very difficult to do this without having a target to aim towards or a structure within which to do it, and certifications give me both of these.

Dare I say it, but like everyone I have an ego and it’s a nice feeling to be able to say you’ve achieved a qualification and to be able to add a few acronyms to the end of your name or on your LinkedIn profile and I like to think that it gives me a certain amount of authority when being consulted on LabVIEW or TestStand issues – it’s a nice way to re-assure people from the start that you know what you’re talking about.

Are there any drawbacks of certification (apart from the stress, late nights of revision etc!)? Again I’d say the answer to this is yes:

For one, there is a danger of Pigeon Holing yourself. I’ve done an awful lot of C, C++, C# Java, embedded etc over my career, but I am known as a LabVIEW and TestStand Architect, and certainly when I have interviewed for non LabVIEW or TestStand jobs this has come up as a problem because people view me as so closely aligned to these development tools that they question my other skills or assume that I am probably at best average when I can provide a decent amount of evidence that I am and would be more than competent in these other languages.

Being perceived as an expert can also sometimes be a problem with managing peoples expectations. Some people (mainly non tech savvy) wrongly assume that because you have a certification then you must have super powers and are able to tackle all problems in super fast time and produce consistently top quality output. I obviously strive for all of these qualities, but the truth is that just having a certification doesn’t instantly mean I always achieve all of this or will always be more efficient or deduce a better solution than someone who isn’t certified or won’t make mistakes – if a problem is hard it will be hard for most people, then having a certification is not going to magically diminish that problem – but I have come across this attitude usually accompanied a comment along the lines of “but you’re a CLA, this should be easy for you”! Arguably a nice position to be in in a funny sort of way though.

LabVIEW certification in itself can be a divisive – there are many people in the world who do not consider LabVIEW to be proper programming and almost think it’s like some sort of toy language and so can be very dismissive of the LabVIEW certifications themselves and by extension, your skills. I personally couldn’t disagree with this position more. Certainly LabVIEW is a far more abstracted language than say C++, and definitely has a far lower threshold at which you can become productive with it. In all other aspects though there really isn’t that much difference between developing in C, C++, Java etc and LabVIEW in my experience – they all have their quirks, nuances and pitfalls, but all require that you apply good development techniques to extract the best from them, and all will bite you if you don’t – LabVIEW in some ways more than most as it is very easy to write bad LabVIEW code that works and there are good and bad developers so I think it is wrong to consider it to be a lesser language.