LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching a network for devices using CVI?

I'm sure that someone out here has done this. I have a machine running CVI 2015 and it's connected via Ethernet to some test equipment. There is no network host so all of the devices (including the computer) will have an address of the sort 169.254.xx.xx. What I need is a method of easily scanning the port range to hunt for devices. Once I find something I can talk to it and ask it what it is to make sure I know what address each gadget ended up with.

 

I can write a loop that does a "ConnectToTCPServer" repeatedly an all possible addresses, but is there a better method?  Any pointers to Windows-friendly code are welcome, and I have beer money for useful answers. 🙂

 

In a perfect world you know where there's Windows code that can scan a network looking for active addresses. I'm not worried about port scanning since I know what ports the devices will be using. 

 

Thanks in advance!

0 Kudos
Message 1 of 6
(1,367 Views)

TCP/IP doesn't work like this! There is no inherent standard to enumerate devices on the network. Each device has to implement its own server where it listens on a "well known" (to its manufacturer) port for specific commands and responds with some information about its name and other stuff.

 

One standard Apple (and some consumer devices) implement is for instance the Bonjour service. Another one is the ubiquitous uPNP, which is built into Windows and many consumer network peripheral devices. For test and measurement you have the LXI/VXI-11 standard which is yet another one. And quite often the manufacturer is cooking his own private soup here.

 

Which one discovery protocol your device supports, if any, is sometimes mentioned in the little footprints in the User Manual or if there is a separate Programmer Manual, you have a little higher chances to find the information there. Welcome in the world of networking protocols! 😀

 

If your devices are smart they might implement some UDP channel, where one can send information as broadcast to a certain port number and then they all will throw out some information about their own address. With an UDP client you then can collect the responses and build a list of known devices. That saves you to scan all possible 64k addresses in the 169.254.x.x address range.But that only works IF there is actually a UDP port open on the device where a process is listening for those broadcast messages and reacting accordingly.

 

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(1,361 Views)

It has been a long time since I wrote firmware for an Ethernet device, but I remember having to make sure that the device responded to an ARP request packet.  I was hoping that the TCP/IP support available from Windows through CVI allowed me to either initiate an ARP request, or query the ARP table that the Windows machine probably was building anyway.

 

If I know a device if any kind exists on my cable then I can talk to it and find out who it is.  This is in a test situation so it's only going to be an oscilloscope or a power supply and nothing else. I get what you're saying about Bonjour but this is not a general purpose address sniffing application. It's more like "Scope, I know you're out there somewhere. Tell me where you are so I can figure out which of you is the scope and which is the power supply."

 

I'm actually kind of expecting that the power supply has no discovery method at all. The manufacturer's code for it requires you enter an IP address. If you want it will scan and I've watched that with Wireshark. I get a sense that's basically pinging all available address on the net - which is fine - but I hoped for something better.

 

Howard

0 Kudos
Message 3 of 6
(1,347 Views)

No, ARP operates directly on IP level, not on top of TCP/IP or UDP, so you can not make ARP traffic with standard LabWindows/CVI libraries. But you can call the Windows arp command through the command line if you really want to.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 6
(1,342 Views)

Ahh. That's the level of info I was missing. If I can't initiate a query from Windows then my only choice is to ping every possible address. That could take minutes.

 

I can also shell out to the 'arp' command, capture the output and get my address that way. I had hoped there was something less Rube Goldberg-ish.  😞

 

Your next beer is on me if you can accept something easy to mail like Amazon gift cards.  Thanks for the help!

0 Kudos
Message 5 of 6
(1,336 Views)

command line is NOT Rube-Goldberg. 😀

 

On Unix it is still THE way to most things. On Windows there are a few road bumps:

 

- process creation under Windows is relatively expensive, so calling command line tools repeatedly in a fast loop is a fairly slow process

 

- Windows in its infinite wisdom tends to localize everything including command line tools, which results in the standard IO being often in localized text too, so that parsing of the result is more complicated

 

Other than these few little gotchase they work pretty fine and can do a lot of things that are hard or impossible to do otherwise.

 

Of course you are always welcome to read about the Iphlpapi.h file and try to figure out what functions might give you the right result.

 

Maybe GetIpNetTable() might work for you! 

Rolf Kalbermatter
My Blog
0 Kudos
Message 6 of 6
(1,330 Views)