LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Finding the right delimiter

Solved!
Go to solution

I have developed a cross-platform LabVIEW based application. It will run on Mac OSX, Linux and Windows. It needs to reliably detect the operating system it is running on to use the right delimiters for pathnames (I generate file names / folders based on other front panel input).

 

I have been using a kludge of sorts to do this. I use a VI server reference and use the OS Name property node, wire it into a search / replace string VI and count the number of times a substring "Windows" is replaced. If the number of replacements is greater than 0, I know it is Windows. Else, I test for Linux. Do the same thing. Then if it is neither Windows nor Linux, I assume it is Mac OSX.

 

This kludge which worked for the VIs running on Mac OSX and Windows, does not seem to work for the application compiled on Windows LabVIEW PDS (the absence of a gcc style cross-compiler for LabVIEW is a sort of a raw subject for me right now since NI forces developers to pick an OS by creating a needless barrier for cross-platform compilation, but we will not go into that). There are no other points in my code which detect the right delimiter to use (":" for Mac HFS, "/" for Linux filesystems and "\" for Windows FAT32 and NTFS).

 

I imagine that there are folks here who have tried to something of the sort. Is there a Detect OS and Find the right Delimiter.vi that someone may have and want to share ?

0 Kudos
Message 1 of 8
(4,003 Views)

This is why you should not create path names using strings. Use build path and it will be cross platform.

 

Edit: If you really need a kludge to find the path separator you can try something like this. I know it works on Windows but I can not say if it works for Linux or OSX. The Get System Directory vi returns the path separator as the last character on Windows so it depends on what the others do.

 

Capture.PNG

=====================
LabVIEW 2012


0 Kudos
Message 2 of 8
(3,997 Views)

You can use the Application.TargetOS property to determine what platform you are running on.

 

You can also use a vi in vi.lib\Utility\libraryn.llb called 'Is Name Multiplatform.vi' to validate your file name.

 

The Application.TargetOS property is used in this vi if you want an example.

 

As mentioned, always use Build Path; it will be much safer than concatenating strings...

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 3 of 8
(3,978 Views)

Also remembered that there was a blog entry on The MacView about path -> string and string -> path

 

http://themacview.blogspot.com/2008/04/its-little-things.html

 


Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
If you don't hate time zones, you're not a real programmer.

"You are what you don't automate"
Inplaceness is synonymous with insidiousness

0 Kudos
Message 4 of 8
(3,972 Views)
Solution
Accepted by m-s

Sometimes using strings is unavoidable, for those relatively rare cases there are some useful VIs in vi.lib to help with cross-platform issues.

 

sysinfoVIs.png

Message 5 of 8
(3,963 Views)

You have no idea how much effort you have saved me !

 

Is there a way to set the entire contents of vi.lib to be accessible from a right click on the block diagram ?

 

PS: Can't do anything about this complicated VI, but I get the message - use build path whenever possible.

 

Now, if only NI could bundle in a cross-compiler. The very existence of all these VIs shows that someone took a lot of care in creating a product that was pretty cross-platform. So, the absence of a cross-compiler in the Application Builder is both unaesthetic and inexplicable (not to mention, maddening to the nth degree).

0 Kudos
Message 6 of 8
(3,944 Views)

 


@m-s wrote:

 

Is there a way to set the entire contents of vi.lib to be accessible from a right click on the block diagram ?

 


I am afraid that there will be mostly chaff and relatively little wheat.  What I do is put VIs from vi.lib that I find useful on the BD of a "catalog" VI organized by group.  This is a handy place to find them and lets me check for issues when I upgrade.  A select few are added to a custom palette.

 

0 Kudos
Message 7 of 8
(3,937 Views)

 


Darin.K wrote: What I do is put VIs from vi.lib that I find useful on the BD of a "catalog" VI organized by group.

 


 

That catalog would be a great nugget if you are able to post it.

=====================
LabVIEW 2012


0 Kudos
Message 8 of 8
(3,883 Views)