Entradas

Retrieve CPU temperature

Imagen
Lately I had to check the CPU temperature in a critical acquisition system, and I thought it could be a good thing to share here. I know there are several applications to do this and much more, but getting it from our code allows to react conveniently to any event. Now, IMPORTANT, the VI doesn't work on its own. First you must download the Open Hardware Monitor . Extract OpenHardwareMonitorLib.dll from the zip file and put it in the same folder the VI is located. The objects exposed in it use .NET Framework 2.0 and above, but that shouldn't be a problem in any modern machine. On the other hand, this works only for Windows , obviously. And remember, the application (either an .exe or the LabVIEW IDE) must run with administrator rights (otherwise you'll get error 1172 ). Download (VI for LabVIEW 2016) Now, if you haven't worked with .NET functions in LabVIEW, this can be a good opportunity to familiarize with them. Let's take a look at the code. First we ...

Open folder in file explorer

Imagen
This is an useful snippet I've using for a long time, and still works fine in Windows 10 (though obviously won't in Linux machines). Say you have saved a new data file and you want to show it to the user. Well, this VI does it for you. If the input path is a folder, it just shows it. If it's a file, opens its containing folder and the file appears selected. It's really simple and uses a system call: Here you have it for LabVIEW '16. Download (VI for LabVIEW 2016) When managing files and folders, the function to release the current directory we saw some time ago can also be helpful.

Windows services management

Imagen
Wow, it's been a long time since I last updated the blog. Life, you know. OK, today I bring you a very simple library to manage the Windows services you may have created (either with LabVIEW or in another language, it doesn't matter). These VIs allow to install and uninstall the service, as well as running it, stopping it and getting its current status. A lot of extra functionalities could be added if ever needed, you'll see they're extremely easy to use and modify. Download Services LLB (library and class for LabVIEW 2016) The main part of the library is made up of service.lvclass , a LabVIEW class that wraps the provided functions: install, start, stop, get status and uninstall. Maybe using GOOP here is overkill, but it's easier this way, just deploy init and close to create and dispose an instance and call the other VIs in between. This class uses .NET methods inside and as such is only valid for a Windows OS, but we are talking about Windows services her...

Mail subject with non-standard characters

Imagen
I was thinking about good example uses for the Base64 Encoding utility I posted last week, and then I remembered: e-mails! Sending an e-mail from your application is a pretty common task. Let's say your client wants to be automatically informed when some conditions are met in the plant. So you do it, and probably use the Send Email using SMTP Cient.vi that comes with LabVIEW (since LV2013) and allows the use of secure mail servers, as Gmail. So far, so good. But what happens when you put some non-English characters in the subject line? This is usual for us Spanish speakers, and the results are not as intended, but garbage text on the other side. The answer is to use an encoded-word syntax . In this case we'll use Base64 and the VI I uploaded . The change needed in the mail client VI is minimum: Just encode the text in Base64, encapsulate it as indicated, and your subject line will be readable in any mail client, as you can see in the lower image.

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:imag...

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 needed Surely 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 t...

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.