Hello all,
It should be noted that on top of having just begun using NB products, its also been years since I've done any significant coding; so if some of my questions seem elementary, I apologize.
I have a MOD5270 with a development board. Ultimately, the implementation will have several NB modules on a mobile network that will need to be assembled, disassembled, and power cycled on a regular basis. Each NB is also going to need to be assigned some sort of simple identifier so that whatever computer is at the head of this network can easily decide which NB it needs to send/receive data from. For ease of use it would be preferential that each NB can be assigned an identifier inside the code using a dial of sorts attached to each NB. Basically, using a development board, I can set this identifier using the dip switch on the board. So if I want a NB to be identified as "Number 1" I can just set the dip switch to that number and have the code read that identifier.
At this current point in time, the program on the computer connects to the NB using a TCP connection, reads the value of the dip switch, and stores that value using the NB's currently assigned ip address (given out by a DHCP server) as the identifier for that NB. Example, the computer opens a TCP connection to x.x.x.101 and reads the dip switch value 5. Now anytime the computer wants to send/receive data on NB 5 it knows to select x.x.x.101. The complication arising when the network is power cycled, NB 5 may be assigned a different ip address and thus the TCP call for the identifier has to be done over again and restore the value on the computer.
So my question is this: for simplicity sake, is there an easy way to assign the NB a static ip address based on the dip switch value? This way the computer doesnt have to make the TCP call and store the identifiers after each power cycle, it can simply use the convention of NB 5 is always going to be at ip x.x.x.5, etc.
Setting static IP using development board?
-
- Posts: 26
- Joined: Wed Oct 19, 2011 8:40 pm
Re: Setting static IP using development board?
Use the IP-Setup utility
-
- Posts: 513
- Joined: Sat Apr 26, 2008 7:14 am
Re: Setting static IP using development board?
Actually it sounds like you want to set the IP dynamically based on the dipswitch setting. IPSetup only provides a static way of doing this manually by modifying the ConfigRecord. I think you can meet your needs though. Take a look at the SystemLibrary chapter in C:\nburn\docs\NetBurnerRuntimeLibrary/Netburner Runtime Libraries.pdf, and in particular the UpdateConfigRecord() and the getdipsw() functions. See also the example files at: C:\nburn\examples\DHCP\ChangeIP
Re: Setting static IP using development board?
I did this very thing about 6 years ago. I dug through some old source code and found this routine. Maybe it will help. No warranties as to the fitness of the code etc.
Code: Select all
//==============================================================================
// Set our IP according to the DIP switch. If we read 0 from the DIP switch
// we assume the hardware isn't present and we use DHCP to get our address.
// There is no guarantee that if the DIP isn't present we will get a 0 anything
// that pulls any of the anticipated DIP lines low will look to us like the DIP
// is there. In my test environment the lsb always comes back low.
//==============================================================================
void SetOurIp(void)
{
const long base_ip_address = AsciiToIp("192.168.1.50");
int netburner_id = NGpio::ReadBandId();
iprintf ("The netburner id is %d\n",netburner_id);
if (netburner_id !=0)
{
long this_ip_address = base_ip_address + netburner_id;
EthernetIP = this_ip_address;
//if we wanted to store this we could make the following call
//NNbSysUtils::UpdateIpAddress(this_ip_address);
//but we want to read the dip switch at every startup.
iprintf( "Static IP address of");
ShowIP( EthernetIP );
iprintf("\n");
}
if ( EthernetIP == 0 )
{
iprintf( "Trying DHCP\r\n" );
GetDHCPAddress();
iprintf( "DHCP assigned the IP address of :" );
ShowIP( EthernetIP );
iprintf( "\n" );
}
}