From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From 11:00 PM CDT Friday, Nov 8 - 2:30 PM CDT Saturday, Nov 9, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
02-23-2011 11:51 AM - edited 02-23-2011 11:53 AM
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 ?
Solved! Go to Solution.
02-23-2011 12:01 PM - edited 02-23-2011 12:09 PM
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.
02-23-2011 12:37 PM
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...
02-23-2011 12:55 PM
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
02-23-2011 01:22 PM
Sometimes using strings is unavoidable, for those relatively rare cases there are some useful VIs in vi.lib to help with cross-platform issues.
02-23-2011 02:16 PM - edited 02-23-2011 02:21 PM
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).
02-23-2011 02:30 PM
@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.
02-24-2011 08:25 AM
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.