03-25-2009 03:52 PM
I REALLY need to programmatically change my PC from DHCP to a static IP address (192.168.0.215) for my application. It appears there is no way to do this in LabWindows/CVI. Am I right?
There are many Microsoft OS calls to do this. I can't believe there are no LabWindows/CVI equivalents.
03-26-2009 06:05 AM
this is generally part of the configuration of the machine you are building: you setup the network once then let it run this way. i don't see the point of switching regularly between DHCP assigned and static ip address.
you also wrote: "It appears there is no way to do this in LabWindows/CVI". this is wrong, you can do this by calling the Windows SDK functions: don't mix the development environment, which is an ANSI C compiler packaged with an IDE, and the library, which is the set of functions conveniently grouped by NI to provide some layer of abstraction around the OS. if you need to know which functions from the SDK you must call, then ask, we will be glad to tell you how to do that.
also, if CVI had a function for every features provided by the OS, national instruments would be making an operating system, not a development environment.
03-26-2009 09:13 AM
Hey dummy_decoy,
Thanks for your reply. However, just because you don't see the point in me changing back and forth between DHCP and static doesn't mean there isn't a good reason. In fact, there's a very good reason. My PC app has to communicate via ethernet to an embedded app on a tank. The embedded app absolutely requires the PC IP address to be set to static 192.168.0.215. So I must change it when my app starts up, and restore it (required by my customer) when my app terminates.
The set of TCP functions provided by the LabWindows/CVI library basically constitute an ethernet driver. Connect, write, read, clients, servers, etc. And what such driver would be complete without a method of changing back and forth between DHCP and static IP? Is it too much to ask an ethernet driver library package to provide this most basic service? No. Microsoft code libraries go to great lengths to provide such comprehensive services, even if they do a bad overall job.
In your reply, you stated "if you need to know which functions from the SDK you must call, then ask, we will be glad to tell you how to do that.". OK, I'm asking...
03-26-2009 11:14 AM
In an effort to simplify coding task (which ultimately is money ) couldn't you add a second network card connected to your device with static IP address and keep the first one with dynamic address?
Just my 2c...
03-26-2009 01:24 PM
03-26-2009 01:54 PM
I didn't considered military standards...
The only alternative I can think of besides coding an IP address change (which I can't help you with) is the use of the Alternate Network Configuration available in XP as described in this msdn article : hope this can help you.
03-27-2009 07:22 AM
Microsoft's WMI provides a method for change IP address/DNS/etc. I haven't verified it, but I'd also guess you can set static/DHCP through it as well. It's a COM module, so it is a bit of a pain to use in CVI, but it can be done. If you want to do it programmatically instead of through a shell interface, then I would say that this is the only way to go.
You can also change it via the registry, but I don't know how you can get the network subsystem to "read" the new values without restarting windows....
If you search google for "using WMI to change IP address" you'll get a lot of hits. Most are in C# or a scripting language, so you can only use them as a reference to what WMI methods you need, but with some persistence you should be able to get it to work in plain ole C in CVI.
03-31-2009 04:22 PM
Just to save some taxpayer's money 🙂
DHCP:
netsh interface ip set address "Local Area Connection" dhcp
Static:
netsh interface ip set address "Local Area Connection" static 192.168.1.50 255.255.255.0
you can call above from system (); //