Thursday, September 6, 2018

Why you should not use Labview in a control environment


 

  • Not deterministic Since you have no control of threads on how and why they are set. There is no way that you can force the code to be deterministic. LV hides the threading to try to remove users from having to deal with treading models. The problem is how you make it deterministic if you have no control of the priority and implementation of threads. If you do not understand coding then this is a good thing, but if the users do not understand coding then maybe they should not be coding. For example I can have a thread taking from 1 to 6 seconds to execute. How can I fix this if I cannot see what is blocking it from executing as that is hidden from me. Is there a critical section blocking or a thread blocking. The nice thing with forcing the user to write the code is that they have to physically create threads and handle critical sections. Since they create it then they are forced to understand it.
  • Loading libraries Loading any VI contributes loading everything that is referenced. Therefore if you just want to look at one VI it must load everything. This in turn makes a simple view tedious and time consuming.
  • Wait for new technology up to 5 Years New methods introduced with Visual Studio have about 5 year lag time once Microsoft releases it until Lab View adds it to their code. Of course this add in is only available when you buy new software. No free service packs. Example Task based threading available since 2010 will reduce thread time x10, but is not available in Lab View today.
  • Data type conversions Converting data types like class or objects are convoluted and hard to understand. For instance if I just want to take an object and then pull out the states of the object to log them it takes an awful lot of effort. In CSharp this is a simple override (object)obj.
  • Cost VS professional is $700 with unlimited releases, while Lab View is running at over $4,000. Debug versions will cost you $900 per computer to run Lab view. $$$$ So we have 300 PC in the factory 300 x 900 = $270,000 for license. By the way if you want the fixes to the LV bugs you will have to pay for another license upgrade. More $$$.
  • Licensing Lab View and all NI products are licensed to the machine and not the developer. So you are limited to where you can run it. VS is per developer on any machine.
  • Speed The execution speed of Lab View is x1000 slower than CSharp. For instance I ran a test loop in CSharp and the loop time was 24 uSecs. The same functionality in Lab View was 24 mSecs throwing out all the loading of Lab View and just using loop execution time.
  • Limited functionality Lab View basically limits you the functionality of their controls. Can only base your coding on what vi building blocks NI has deemed you need, therefore you must change your coding to fit into their available block sets. This in its self would be a major rejection of the type of software to use. You cannot limit a developer to force change to program flow based on you lack of methods to do that code. This puts a major limit on what you can do with this code. Will increase development time substantially and make building models to prove out test cases impossible.
  • Deviates to far from normal coding The deviation from standard code is so different from c, c++, and c# that it will not even allow for code method reuse. For example string manipulation is not following the same syntax. I am not sure why you would deviate from standard string format syntax when at the end of the day the low level coding of Lab View is a call cpp, C#. Why would you change the format so then when you build the code you have to reconvert the format back.
  • Vi Model selections The help groups will show vi models with jpg views. The problem is you have to try to find the vi’s they are calling in the jpg’s. This waste time as some of them do not even exist or are hard to find.
  • Coding Diffs vi graphical contents make it extremely hard to do differences on the code line to try to find the changes between versions. Since lab view can only do diff on vi’s in memory it basically cannot do diff on PVA projects, as the links will not work on loading. Therefore the only option you have for diff is manually review the vi’s on separate PC’s. Normal textual based code allows for complete differences in the code to be made with an easy in determining the changes that were made. Since you have to open the project to do diff the file you want to diff must be renamed. Also you cannot open two different files with the same name. How can you compare when you have to rename to open. Diff is essentially worthless for big projects as all it will do is circle a vi diff abstractly. It will not highlight the actual diffs.
  • Vi stored in memory LV has to store everything in RAM just to try to pretend it is fast. The problem with doing this in large projects is that all available memory is hogged up by LV. In order to make changes to a file outside of LV you have to make LV release it from memory.
  • How do you find functions When looking at functions all you get are pictures of the functions, then you have to try to find a match like finding squares. If they were smart they would have an option to right click and find the functions in the tool panel. That way it would take you straight to the function you are needing.
  • Crashes repeatably Easy to make debugger crash while doing simple things like find in the code view. Not a stable program.
  • No Backwards compatibility of vi If you update Lab view to a newer version then all the vi that you make changes to are no longer compatible with the old version. Basically you cannot maintain code between versions of Lab View. No changes can be made with the new version or all other tools are force to upgrade to use them.
  • File links are auto created NI creates the file links automatically, but if they are broken or changed then there is no way to manually fix them. You have to go into each vi and try to remove it and hope it fixes it for you. In a lot of cases it cannot fix them and then you have dangling links to deleted files. File links tend to be updated once you close project, this should be a button to update links instead of close and reopen projects. Then you can hope it fixes them or breaks code once reopened. For some links you physically have to open the vi then allow it to fix links. How tedious is this going to be on a large project.
  • Cannot find broken vi Lab view will just ignore broken vi’s and build the project. The problem is the broken vi is not found until the vi is called. Therefore you can have a lot of bugs in the code just waiting to blow up when the vi is called.
  • Wires! Everywhere! The paradigm of using wires instead of variables makes some sort of sense, except that for anything reasonably complex, you spend more time trying to arrange wires than you do actually coding. Worse, finding how data flows by tracing wires is tedious. Especially since you can’t click and highlight a wire to see where it goes – clicking only highlights the current line segment of the wire.  And since most wires aren’t completely straight, you have to click through each line segment to trace a wire to the end. [edit: A commenter pointed out double clicking a wire highlights the entire wire, which helps with the tracing problem]
  • Spatial Dependencies. In normal code, it doesn’t matter how far away your variables are. In fact, in C you must declare locals at the top of functions. In Lab VIEW, you need to think ahead so that your data flows don’t look like a rat’s nest. Suddenly you need a variable from half a screen away? Sure you can wire it, but then that happens a few more times and BAM! Suddenly your code is a mess of spaghetti.
  • Verbosity of Mathematical Expressions. You thought low-level BLAS commands were annoying? Try Lab VIEW. Matrices are a nightmare. Creating them, replacing elements, accessing elements, any sort of mathematical expression takes forever. One-liners in a reasonable language like MATLAB become a whole 800×800 pixel mess of blocks and wires.
  • Inflexible Real-Estate. In normal text-based code, if you need to add another condition or another calculation or two somewhere, what do you do? That’s right, hit ENTER a few times and add your lines of code. In Lab VIEW, if you need to add another calculation, you have to start hunting around for space to add it. If you don’t have space near the calculation, you can add it somewhere else but then suddenly you have wires going halfway across the screen and back. So you need to program like it’s like the old-school days of BASIC where you label your lines 10, 20, 30 so you have space to go back and add 11 if you need another calculation. Can’t we all agree we left those days behind for a reason? [edit: A commenter has mentioned that holding Ctrl while drawing a box clears space]
  • Unmanageable Scoping Blocks. You want to take something out of an if statement? That’s easy, just cut & paste. Oh wait no, if you do that, then all your wires disappear. I hope you remembered what they were all connected to. Now I’m not saying Lab VIEW and the wire paradigm could actually handle this use case, but compare this to cut & paste of 3 lines of code from inside an if statement to outside. 3 seconds, if that compared to minutes of re-wiring.
  • Unbearably Slow. Why is it when I bring up the search menu for Functions that Lab VIEW 2010 will freeze for 5 seconds, and then randomly shuffle around the windows, making me go back and hunt for the search box so I can search? I expect better on a quad core machine with 8 gb of RAM. Likewise, compiles to the real-time target are 1-5 minute long operations. You say, “But C++ can take even longer” and this is true. However, C++ doesn’t make compiles blocking, so I can modify code or document code while it compiles. In Lab VIEW, you get to sit there and stare at a modal progress bar.
  • Breaks ALT-TAB. Unlike any other normal application, if you ALT-TAB to any window in Lab VIEW, Lab VIEW completely re-orders Windows Z-Buffer so that you can’t ALT-TAB back to the application you were just running. Instead, Lab VIEW helpfully pushes all other Lab VIEW windows to the foreground so if you have 5 subVIs open, you have to ALT-TAB 6 times just to get back to the other application you were at. This of course means that if you click on one Lab VIEW window, Lab VIEW will kindly bring all the other open Lab VIEW windows to the foreground, even those on other monitors. This makes it a ponderous journey to swap between Lab VIEW and any other open program because suddenly all 20 of your Lab VIEW windows spring to life every time you click on.
  • Limited Undo. Visual Studio has nearly unlimited undo. In fact, I once was able to undo nearly nearly 30 hours of work to see how the code evolved during a weekend. Lab VIEW on the other hand, has incredibly poor undo handling. If a subVI runs at a high enough frequency, just displaying the front-panel is enough to cause misses in the real-time target. Why? I have no idea. Display should be much lower priority than something I set to ultra-high realtime priority, but alas LabVIEW will just totally slow down at mundane things like GUI updates. Thus, in order to test changes, subVIs that update at high frequencies must be closed prior to running any modifications. Of course, this erases the undo. So if you add in a modification, close the subVI, run it, discover it isn’t a good modification, you have to go back and remove it by hand. Or if you broke something, you have to go back and trace your modifications by hand.
  • A Million Windows. Please, please, please for the love of my poor taskbar, can we not have each subVI open up two windows for the front/back panel? With 10 subVIs open, I can see maybe the first letter or two of each subVI. And I have no idea which one is the front panel
    and which is the back panel except by trial and error. The age of tabs was born, oh I don’t know, like 5-10 years ago? Can we get some tab love please?
  • Local Variables. Sure you can create local variables inside a subVI, but these are horribly inefficient (copy by value) and the official documentation suggests you consider shift registers, which are variables associated with loops. So basically the suggested usage for local variables is to create a for loop that runs once, and then add shift registers to it. Really LabVIEW, really? That’s your advanced state-of-the-art programming?
  • Copy & Paste . So you have a N x M matrix constant and want to import or export data. Unfortunately, copy and paste only works with single cells so have fun copying and pasting N*M individual numbers. Luckily if you want to export a matrix, you can copy the whole thing. So you copy the matrix, and go over to Excel and paste it in and……….suddenly you’ve got an image of the matrix. Tell me again how useful that is? Do you magically expect Excel to run OCR on your image of the matrix? Or how about this scenario: you’ve got a wire probed and it has 100+ elements. You’d like to get that data into MATLAB somehow to verify or visualize it. So you right click and do “Copy Data” and go back to MATLAB to paste it in. But there isn’t anything to paste! After 10 minutes of Googling and trial and error, it turns out that you have to right click and “Copy Data”, then open up a new VI, paste in the data, which shows up as a control, which you can then right-click and select “Export -> Export Data to Clipboard”. Seriously?!? And it doesn’t even work for complex representations, only the real part is copied! I think nearly every other program figured out how to copy and paste data in a reasonable manner, oh say, 15 years ago?
  • Counter-Intuitive Parameters. Let’s say you want to modify the parameters to a subVI, i.e. add a new parameter. Easy right? Just go to the back panel with the code and tell it which variables you want passed in. Nope! You have to go to the front panel, right-click on the generic looking icon in the top right hand corner, and select Show Connector. Then you select one of those 6×6 pixel boxes (if you can click on one) and then the variable you want as a parameter. Lab VIEW doesn’t exactly go out of its way to make common usage tasks easy to find.
  • No separation of concerns. The vi’s do not show any separation of concerns. Modern software should be setup where the code is separate between the GUI and the back end. This movement of MVVC was implemented to make the GUI and code separate to maximize code reuse. It looks like Lab view has not bought onto this since the vi method has no separation.
  • Calling classes. When you invoke a class there is no way to see what class was involked, I am expecting to be able to see the classes and where they are coming from. You cannot view where the class is being called from by clicking on the involker. How can you tell what the code is running if you cannot know what it is calling. (Come on NI, that is just poor)
  • No try and catch. Try and catch is not supported so any bugs will kill the application and generate an exception error. You cannot have robust code if you cannot handle exceptions.
  • Excruciatingly complex. Simple coding written in lab view gets exceeding complex to implement not to mention maintain. I can do the same thing in Csharp with 1/10 the amount of code and complexity. Why would someone even think that this is the proper code to use?
     

Thursday, August 14, 2014

DOTNET 4.0 with TestStand 2010

      If you are using Teststand 2010 with DOTNET 4.0 you will get an error as Teststand 2010 was build with DOTNET 2.0. The work around for this is to create a file called SeqEdit.exe.config. In this file add the following:

 <?xml version="1.0"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
</assemblyBinding>
</runtime>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>
</configuration>

   Adding supportedRuntime = v4.0 will set Teststand to use the DOTNET 4.0 runtime engine. Then all you need to do is save this file in the Teststand directory. <Teststand>\Bin. In my case it was C:\Program Files (x86)\National Instruments\TestStand 2010 SP1\Bin. Once it is in this location restart Teststand and you should now be able to use DOTNET 4.0 libraries.  Typically in my case I use CSharp DLL's to do the main part of my code and Teststand is just the sequencer.

Saturday, August 9, 2014

Click Once Deployment

     I have been to busy and have gotten out of the habit of doing blogs. So now I am going to restart up my blogs. The post will be on how to create a click once deployment with CSharp. Click once provided a means to deploy applications to you users and then it allows the user to update when you make changes. This is nice if you have a lot of clients and want to ensure they get the latest releases.
    The first step is to go to properties page and click publish on the bottom left. For the location I user the \\servername that the client will have access to.




     If you click on prerequisites you can select any items needed. Normally the default setting will install all the required items.

 
 
    Under updates I normally select the application should check for updates before it starts. This will check for new versions and allow the user to update the application is they want to.


  Under options I select description and for the publisher name this will end up being the main menu item group under the start short cut. The product name will be the name of the program. So when the program is installed the start menu will have a short cut called MTCode->TestDeployment.



  The other change I normally make is to click options and under manifests select create short cut on desktop. I find this a good option as some users have trouble finding it otherwise.

 
 
   Once all the setting are done then the next step is to save and deploy. The property page has a deploy option on the bottom, but sometimes this dose not seam to work and give an error. So normally I go to the build tab and publish form there.


 
 
 
  Once deploy is successfully done you will see the proper directory on your server location with the setup files. Then the user just needs to run the installer and the program installs. After that every time they run the program is will check for new updates and allow the user the option to upgrade if needed.

Friday, August 16, 2013

USB Virtual Comport Assignements

In this article I am going to go over how to force a USB device with a virtual comport to use the same comport.

HKEY_LOCAL_MACHINE\SYSTEM/CurrentControlSet/Control/USBFlags

Add REG_BINARY  value 01 key named IgnoreHWSerNum"VID""PID"
VID = 10C4
PID = EA70
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB
IgnoreHWSerNum10C4EA70










HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/COM Name Arbiter

  • COMDB = 03 00 00 00, if you have 2 built-in serial ports (or 01 00 00 00 if you only have one built-in COM port).
  • NOTE: 03 in binary is 0000 0011 so the lowest bit set (the 1 on the right) means COM1 is in use, and the bit to its left, in the 2 position, means COM2 is set. You will also want to clean keys for any non-standard serial ports from these places:
  • HKEY_LOCAL_MACHINE/HARDWARE/DEVICEMAP/SERIALCOMM
  • HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows NT/CurrentVersion/Ports You should be able to power down and reinstall the Digi adapter if it had been removed from the system. If it is installed, reboot the system. The adapter should be redetected and the driver installed. The com ports should now default to start at COM3 (or COM2 with only one built-in serial).
  • Saturday, September 8, 2012

    Creating an Occasionally Connected Smart Device Application a working example with emulator

      In this blog I plan on going thru how to create an occasionally connected smart device application and get it working correctly. I found this example Smart Device Example link to explain how to create and connect to the emulator. The problem is this is not a complete and working example, so after spending several days just trying to get this to work I will try to go back thru what I did. I will start with this example with my added changes and present a working version of this example.
      The first issue I ran into when trying to create this project is which Visual Studio version should I use. After searching thru the web from the best that I can see I the newest version that still supports winCE is VS2008, so I started with this version. The first step is to make sure you install all the prerequisites as listed below:

    Prerequisites


    To complete this walk through you must:
       One mistake I made was to not install all of the preequisites, since I noticed I already had MSQL Server Comact 3.5 installed. You must make sure you install the Service pack 1 for this or you will get connection errors when you try to do your remote connection with the compact framework. Mine would blow up on the client side of code listed below:

    Microsoft.Synchronization.Data.

      This would give the following cryptic error unhandled Message="TargetInvocationException" and I had to seach lots of articles to finally figure this out. Once I added service pack 1 that error went away. 
      After fixing that I then got a client error in Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize(); for the following ArgumentException error on the client side.
       The first thing to do is see if IE can connect to the WCF service to ensure it is still working. To do this I set theMiddleTierServiceLibrary as the startup project and then select the start without debugging option in the Debug menu. This will bring up the deployment window where I will just select cancel and then in the deployment errors click continue. Figure 1 shows the WCF screen and from here I just copy the http://10.83.4.96:8080/NorthwindCacheSyncService/ from the WC F test client and paste it in IE where you should see the page as listed in figure 2. From this I now know that the WCF service is working and a client can connect to it.
     





    Figure 1


    Figure 2

        Once I know a client can connect I then set SmartDeviceSyncClient as the start up project. Then I just select start debugging from the Debug menu option. Once the code runs I will get the ArgumentException error  so I ignore the error and let the code run. My next step is to try to connect thru IE on the PocketPC emulator with the saem address as listed above. As Shown below you can see that connection files and I cannot connect to the WCF service from the PocketPC.  




    Figure 3
    
        No back to reading more articles on this problem and I come up with this. How is the PocketPC able to establish a connection to the service. Some how it has to have a enet connection and know how to resolve it to an IP address. So the way to do this is in VS IDE Tools->Device Emulator Manager. Once this is selected it bring up a panel with all the emulation devices. On this screen I selected window Mobile 5.0 and right click on it. The right click option and select connect.



    Figure 4

    Once the device is connected you should see the phone and active sync screens pop up and establish a connect. Now the PocketPC has a ENET connect thru active sync and it should be able to connect to WCF service. But in my case using  http://10.83.4.96:8080/NorthwindCacheSyncService/ still did not connect with the same connection error. So the next thing I tried was to use ppp_peer:8080 as the connection name as this is the default name for the emulated device and behold it was able to connect. Great now I know I can connect on ppp_peer with IE, but what about the client application.




    Figure 5




       After running the Smart Device Client code I was still getting a argument error and from this I see that it cannot connect to the WCF service thru IP address directly. So for a test I inserted strHostName = Convert.ToString(Dns.GetHostEntry(Dns.GetHostName()).AddressList[0]); into the Sync() function just to see what the address was that it returned. The address returned was 192.168.55.101 and this was what I was expecting. Then I just let the code run and magic it now started to work.
    string


    Figure 6



      So from this I am not sure what caused it to start working, but I tested it several times and it seams to run and connect correctly now. I would assume that forcing a DNS look up made the look up table instantiate the connection. I will test this further in another article, but for not it works.


    ServerSyncProviderProxy syncProxy =new Microsoft.Synchronization.Data.ServerSyncProviderProxy(svcProxy);

    Thursday, June 14, 2012

    Regular Expressions for Date/Time Validation

    On one of my projects I was asked to validate the date/time input into a textbox. So my solution was to use the built in Validator controls in VS2008. Since this project is based on 2008 I will use that for the IDE on this project.

    The first step for this project was to select the RegularExpressionValidator from the toolbox under Validation tab. Once I dragged it to the project all I had to do was add the ControlToValidate, some text on error and then add the ValidationExpression. This is where it got a little tricky as I assumed all I had to do was find someone that already had a sample that worked and add it. Here is a link that has some good examples on validation.Self-Validating-Text-Box




    The problem was for the examples I found none of them seamed to work correctly. So then I had to dive into Regular Expressions and try to figure out how to make the one I downloaded work.

    Here is a link on using regular expressions:The-30-Minute-Regex-Tutorial. After reading this I then downloaded Expresso and installed it on my computer. From here I could then use Expresso to test and validate my expressions.

    Here is the expression I found on the internet:

    \A(?:1[0-2]|0[1-9])[/.-](?:3[01]|[12][0-9]|0[1-9])[/.-][0-9]{4}[ \t]+(?:1[0-2]|0[1-9])[:.](?:1[0-9]|0[1-9])[:.][0-5][0-9][ \t]+(?:AM|PM)

    This seamed to work fine on my first test case, so I put it in my code and of course it did not work. Therefore I then put it into the Expresso tool and started to run test cases.


      

    So with a date/time of 06/13/2012 02:11:10 AM it worked fine, but when I changed the date/time to 06/13/2012 02:31:10 AM it did not work. So from here I needed to dive into regular expressions to see why it was not working. The first step I took was to review the Regex Analyzer on the right screen of Espresso. This will explain what the commands are doing and as listed below I went thru each on of them.
     
    \A - Beginning of string
     Date
    (?:1[0-2]|0[1-9]) 
    • () - grouping
    • ?:  match : 0 or 1 times
    • 1[ looking for 1
    • [0-2] range of 0 to 2
    • 0[ looking for 0
           This will match the month forcing it to be 1 to 12

    [/.-] - Match [] operator so this will match / . -

            This will match the /

    (?:3[01]|[12][0-9]|0[1-9])
    • () - grouping
    • ?:  match : 0 or 1 times
    • 3[ looking for 3
    • [01] - match 01
    • [12] match 12
    • [0-9] range of 0 to 9
    • 0[ looking for 0
    • [1-9] range of 1 to 9
           This will match the day forcing it to be 0 to 31

    [/.-]  Match [] operator so this will match / . -

           This will match the /

    [0-9]{4} - any class from 0-9 repeat 4 times

         This will match the year to 2012

    [ \t]+ match \t tab with any repetitions

         This will match any tabs

    Time

    (?:1[0-2]|0[1-9])
    • () - grouping
    • ?:  match : 0 or 1 times
    • 1[ looking for 1
    • [0-2] range of 0 to 2
    • 0[ looking for 0
    • [1-9] range of 1 to 9
            This will match 1 and force it to 0 to 2 and 0 to 1 to 9. Which will work for the first test case but not anthing greater then 1.

    [:.] - any character in this class


    (?:1[0-9]|0[1-9])

    • () - grouping
    • ?:  match : 0 or 1 times
    • 1[ looking for 1
    • [0-9] range of 0 to 9
    • 0[ looking for 0
    • [1-9] range of 1 to 9
            This will match only 1 from 0 to 9 and 0 from 1 to 9. 

    [:.]- any character in this class


    [0-5][0-9]
    • [0-5] - match 0 to 5
    • [0-9] - match 0 to 9
           This will match the data to the range 00 to 59

    [ \t]+ match \t tab with any repetitions
         This will match any tabs

    (?:AM|PM) - Match AM or PM
          This will get the AM or PM

    So from this break down I can see a couple of my problems in the time.

    1. (?:1[0-2]|0[1-9]) I need this to go from 0 to 5
    2. (?:1[0-9]|0[1-9]) I need this to also go from 0 to 5
    3. [ \t]+  I need to also handle space
    4. [/.-]  I only want to match /
    Below I have listed my new changes. I ran thru testing on expression and it appears to work. Hopefully this will help some else out on implementing this functionaly.
    \A(?:1[0-2]|0[1-9])[/](?:3[01]|[12][0-9]|0[1-9])[/][0-9]{4}[ \s]+(?:1[0-2]|0[1-9])[:.](?:[1-5][0-9]|0[1-9])[:.][0-5][0-9][ \s]+(?:AM|PM)




     Also you can easily use regex in CSharp to validate or filter data just like grep. All you need to do is add using System.Text.RegularExpression and then call RegEx.IsMatch(...) to evaluate the data of interest.

    Monday, June 4, 2012

    There were deployment errors. Continue! Missing popup

    For this blog I will go thru how to enable the delpoyment errors measage box if it is not showing in VC2008.


    I ran into this problem on one of my PC's while testing a WCF service for a smart device. When I configure this device to deploy I will select cancel and then hit yes to continue to test out the WCF interface. Below is a snapshot of the WCFTest client.




    Well for one of my PC's this was working, but for the other I would just get a deployment error. In order to enable this option got to tools->options->Projects and Solutions->Build and Run->On Run, when build or deplyment errors occur: Prompt to Launch.