11-23-2021 02:12 PM
LV 2018 SP1..
Consider this:
I want to display for the user, the IP address he should use to connect his instrument to the host CPU.
If I use the single-result mode, I get the IP number for something else (I have VMWare Workstation installed, but not running, when this screenshot was taken).
What I want is the "1.30" result (in this case).
What are the rules here? What order do these come back in?
I don't know if it will always be a "192.168.1.xxx" subnet or not.
Can I always use the LAST one in the array returned?
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-23-2021 08:51 PM - edited 11-23-2021 08:55 PM
In this case I would probably run Ipconfig with the Systemexec.vi saving the output and parse the string.
Probably look for "Ethernet Adapter Ethernet:" and go from there.
11-23-2021 10:24 PM
I've used this on several occasions without any ambiguity, but realized that I was "asking the reverse question" -- I was running this from the PC and asking it about "devices that could be detected". Yes, there can be several devices out there (in particular, I'm currently "detecting" a myRIO, but if I go into MAX and look at "Remote Systems", I can find several myRIOs and a few other things (an sbRIO, for example). So my code looks at how many IPs were returned -- if 0, I tell the User that there's "no There there", if 1 I just connect, and if >1, I populate a ComboBox that shows me the IPs and names of the Devices and lets me choose which one to use. Here's a Snippet (since not even I am seriously using LabVIEW 2021 yet). The sub-VI "Choose" is a Dialog box that shows the Message "Choose Target" and populates a ListBox with the "Choices" returned by the System request, returning the single Choice the User selected.
Bob Schor
11-24-2021 03:23 AM
Depending on the required reliability, I would recommend to avoid parsing the ipconfig output. Windows provides plenty of tools to report the network configuration that are more suitable to machine consumption and can be made to report precisely the interface You are looking for. See, for example, netsh or, if you want to skip parsing altogether, the System.Net namespace
11-24-2021 03:45 AM
There is no trivial way to do that not even with parsing multiple command line tool outputs. Nowadays computers can have many different network adapters active at the same time. That can be virtual network adapters such as for your VmWare, built in adapters, WIFI adapters and adapters through docking stations, but even a USB port can be seen as an actual network adapter if the according device connected has a USB-LAN device class.
On my computer the String to IP node in array mode returns typically 6 or more IP addresses. So on such a computer your simple logic of trying to enumerate all IP addresses and eliminating things like VmWare will not work. And for the rest you can not rely on the name of physical network adapters, they can easily be renamed by the user.
11-24-2021 07:50 AM
It looks like even LabVIEW itself gets it wrong: The *.ALIASES file for the project lists "My Computer" as "192.168.6.1"
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-24-2021 08:08 AM
Technically it is not wrong. That IP address is a valid address for your computer. That it is only useful when you want to talk from one of the VmWare instances configured to use VMNet8 (by default the NAT mode) to your host computer is simply a technical detail. 😁
The problem here is simply that the String to IP function uses the Winsock library to get the valid IP addresses. And Winsock seems to consider your VMNet8 address as the default address and therefore returns it as the first one.
11-24-2021 08:17 AM
I am not a networking expert (The more I find out about networking, the more I realize I don't know anything) and not even sure if this what you are looking for, but here is something I did a while ago that seemed to work for my needs. It lists all "real" IP address on your PC (ignoring the virtual ones)
11-24-2021 08:19 AM
Rolf, are you a lawyer by any chance? 😂
It's wrong for my purposes, at least. I cannot dial into 192.168.6.1 from outside the box and connect to a LabVIEW listener. That's not even on the same subnet.
If I use RESOLVE MACHINE ALIAS with an argument of "My Computer", it comes back with "localhost". (Not 192.168.6.1 as the ALIASES file has it). Not helpful.
If I set up a listener and wait on a connection, while connecting from another thread, the remote address comes in as "localhost", or "127.0.0.1" Not helpful.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
11-24-2021 08:41 AM
It lists all "real" IP address on your PC (ignoring the virtual ones)
Frozen, I'm not sure how that helps. In my case it lists:
192.168.1.30
192.168.8.1
192.168.6.1
That's exactly the same as STR-IP (multiple) but in the reverse order. I'm not sure I can depend on the one I want being first.
Blog for (mostly LabVIEW) programmers: Tips And Tricks