Setting Controller IP via Code
Technical Support Guide
Table of Contents
Brand:
- AMX
Models:
- NI-Series Controllers
- NX-Series Controllers
Overview:
Below is an example of code that if implemented into your running program will allow you to set the IP address of the processor after first load of the program.
This alongside the file read command could also allow you to set the IP from a text or csv file loaded to the processors FTP.
Download:
Example Code:
PROGRAM_NAME='Main Source'
DEFINE_DEVICE
dvMaster = 00000:00:00
DEFINE_CONSTANT
TL_Poll_1 = 1 //Program
DEFINE_TYPE
DEFINE_VARIABLE
IP_ADDRESS_STRUCT GetIPAddress
IP_ADDRESS_STRUCT SetIPAddress
volatile long tlPollingIntervals_1[]= {1000}
DEFINE_LATCHING
DEFINE_MUTUALLY_EXCLUSIVE
Define_Function fnSetIP()
{
GET_IP_ADDRESS(dvMaster,GetIPAddress) // Read master IP Details
SetIPAddress.Flags = 0 // 0 = Static, 1 = DHCP
SetIPAddress.HostName = 'Netlinx' // Set Hostname
SetIPAddress.IPAddress = '192.168.1.161' // Set IP
SetIPAddress.SubnetMask = '255.255.255.0' // Set Mask
SetIPAddress.Gateway = '192.168.1.1' // Set Gateway
Select
{
Active(GetIPAddress.Flags != SetIPAddress.Flags):
{
SET_IP_ADDRESS(dvMaster,SetIPAddress) // Config master
REBOOT(dvMaster) // Reboot master
}
Active(SetIPAddress.Flags = 0 && GetIPAddress.HostName != SetIPAddress.HostName):
{
SET_IP_ADDRESS(dvMaster,SetIPAddress) // Config master
REBOOT(dvMaster) // Reboot master
}
Active(SetIPAddress.Flags = 0 && GetIPAddress.IPAddress != SetIPAddress.IPAddress):
{
SET_IP_ADDRESS(dvMaster,SetIPAddress) // Config master
REBOOT(dvMaster) // Reboot master
}
Active(SetIPAddress.Flags = 0 && GetIPAddress.SubnetMask != SetIPAddress.SubnetMask):
{
SET_IP_ADDRESS(dvMaster,SetIPAddress) // Config master
REBOOT(dvMaster) // Reboot master
}
Active(SetIPAddress.Flags = 0 && GetIPAddress.Gateway != SetIPAddress.Gateway):
{
SET_IP_ADDRESS(dvMaster,SetIPAddress) // Config master
REBOOT(dvMaster) // Reboot master
}
}
}
DEFINE_START
fnSetIP()
timeline_create(TL_Poll_1,tlPollingIntervals_1,length_array(tlPollingIntervals_1),TIMELINE_ABSOLUTE,TIMELINE_REPEAT)
DEFINE_EVENT
timeline_event[TL_Poll_1] //replaces DEFINE_PROGRAM
{
switch(timeline.sequence)
{
case 1:
{
}
}
}Table of Contents