Entradas

Base64 Encoding

Imagen
Long time no see! Today I'm here to talk about Base64 encoding and how to do it in LabVIEW.What is Base64 and what is used for?Base64 is a six-bit based encoding mechanism that uses only printable characters from the ASCII table (lower and upper case letters, numbers, and three more characters, usually "+/="). This means it can be represented in any textual environment, though obviously adds an overhead respect to the original code since two bits of every byte are unused.You will find B64 mainly in mail applications (to send attachments), but lately it's been popular in URLs and HTML too. The concept is to insert small chunks of data directly as B64 text to avoid recurrent callings for files through the web. For example, you can embed an image inside your HTML or CSS file. It's not my intention to delve too deep in this aspect, but for an image tag the resulting HTML code would look like this (let's assume a JPG file):<img src="data:image/jpeg;base64,…

Alternative dialog box

Imagen
LabVIEW one-button and two-button dialogs are great but present some issues. The first one is permanency: they don't disappear unless the user clicks one button. This can be problematic if you need the code to continue executing even if there's not a human watching. Second, and less serious to an extent, they resize automatically to the text length; that can lead to really big gray boxes in the screen.So here you have an alternative dialog box. The main difference is, even being modal, it closes by itself if the time consumes without user action. In that case, the default value is returned (true for one-button mode, false for two buttons). You can select the waiting time in seconds (20 by default).Download (VI for LabVIEW 2016)Vertical scrollbar? Only when neededSurely it's a very simple VI, but please consider this piece of code:What we are doing here is to check if a vertical scrollbar is needed. Usually the vertical scrollbar is grayed out if the text area is not overfl…

Uptime

Imagen
Let's go back to LabVIEW. Have you ever wondered what's the meaning of the "Time" item in an event structure timeout case? Well, it's just the uptime, the time in milliseconds since the computer was started.Download (VI for LabVIEW 2016)So, if you need to recover the uptime you can use a VI just like this, an event structure that immediately closes and returns that value. It's a nice alternative for calculating execution times or, broadly, any instance when you just need relative and not absolute time measurements.

Balance text in web pages

Imagen
Today we'll set aside LabVIEW for a change and try something with JavaScript. Consider these two headings, which one do you think is better?Hopefully you will find the second one more appealing to the eye, as me, since the title lines are nearly balanced. If you are formatting a publication by yourself this is easily achieved adjusting the text by hand, but in a web page is difficult.In fact this was proposed as a CSS standard by Adobe some years ago, as text-wrap: balance property, but W3C didn't adopt it and no web browser that I know of implements it. So we'll have to do it ourselves, and with vanilla JavaScript no less so no external library is needed.The codeThe concept behind our function is to "shrink" left and right borders around the heading just until the text needs another line, and stop there. So basically:1) Find number of words and lines in the heading.2) If balancing can be applied, start shrinking borders.3) Still the same lines? Shrink a little m…

Required Outputs Wizard

Imagen
It's an old LabVIEW programmer's dream to be able to make VI outputs required, just as can be done with inputs. Some years ago I discovered a way of achieving it, through a deprecated scripting method. I checked with NI staff and they said it was clever but could cause unexpected problems, so I set it aside.But the time goes by and the functionality is still not available, so here we go, the Required Outputs Wizard is yours. I've been using it on and off for a long time and no errors have arisen, even when applying it to connectors with modern data types, such as classes (OOP). But I guess the risk is still there, so be cautious and test it first with unimportant VIs.Download (LLB for LabVIEW 2016)The bowels of the codeSo, how it works? Launch the top VI in the LLB, you can leave it there running. When a connected front panel indicator is selected, the "REQUIRED" button will be available. Just press it. Yeah, that's all, now your indicator connection is requi…

Coerce to Type

Imagen
I'm surprised the Coerce to Type primitive hasn't found yet its way to the public front. It was revealed some years ago and since then has proved being a reliable way of converting data types, much better than the classic Type Cast, but it's still not visible in the LabVIEW functions API.Consider the following code example. You're casting an U32 value (2) to U8 (you shouldn't, but shit happens). Type cast just casts it, so the resulting value is 0 (wrong!), but Coerce to Type understands what you are doing and returns 2 (correctly).To use Coerce to Type in your VIs, the easiest way is downloading the VI below into your drive.Download (VI for LabVIEW 2016)Next we're going to place it in the functions palette. So, open any block diagram and click Tools → Advanced → Edit Palette Set. Then select the palette you want to add the VI into (in this case I recommend Programming → Numeric → Data Manipulation) and click Insert → VI(s) and select the path to the VI.Now, im…

Antenna pointer

Imagen
Now let's get graphic!For satellite applications is always useful to know where to point your antennas. This LLB top VI draws the positions and the azimuth angle over an equirectangular projection, chosen because of its easiness (no coordinates conversion needed), though far north and south latitudes are deformed. Also provided is phi, the angle of incidence, important for asymmetric antennas.For your own calculations you'll find useful calculate azimuth.vi and calculate elevation.vi (also calculate phi.vi for angle of incidence). All of them are included in this LLB.Download (LLB for LabVIEW 2016)