Author Topic: RESTART Statement and New IP address  (Read 14102 times)

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
RESTART Statement and New IP address
« on: September 28, 2014, 02:39:28 PM »
I'm struggling with the RESTART statement. I'm attempting to have the PLC set/change it's own IP address.  The documentation states:

"To perform a cold reboot of the PLC from within a CusFn. The effect is identical to a power-on-reset except that you execute this command without turning OFF power to the PLC.
RESTART may be necessary for some changes to take effect, such as for the PLC to assume new IP address after executing the SET_IP command."


My observations are that The RESTART statement does not do the job.  I find that I still must power off the PLC to get the IP to change.

I am using 2 custom functions for my debug code, "Init" once at 1st.Scan and displays the current IP address using the new Get_IPAddr.  The second custom function is "ToggleIP" it runs only in response to an INPUT and attempts to change the IP address back and forth between "192.168.1.16:9080" and "192.168.1.17:9080".

Init looks like this:

' Init
'
Get_IPAddr 1         ' Get PLC IP addres in DM[1..5]
A$ = str$(DM[1])+"."+str$(DM[2])+"."+str$(DM[3])+"."+str$(DM[4])+":"+str$(DM[5])

SetLCD 0,1,"\01"      ' Clear LCD display
SetLCD 0,1,Chr$(12)   ' No cursor
SetLCD 1,1, "PLC IP Address:"
SetLCD 2,1, A$
[/color]
ToggleIP looks like this:

' ToggleIP
'
Get_IPAddr 1         ' Get PLC IP addres in DM[1..5]
A$ = str$(DM[1])+"."+str$(DM[2])+"."+str$(DM[3])+"."+str$(DM[4])+":"+str$(DM[5])

SetLCD 0,1,"\01"      ' Clear LCD display
SetLCD 0,1,Chr$(12)   ' No cursor
SetLCD 1,1, "Current IP"
SetLCD 2,1, A$

Delay 4000      ' kill some time so the LCD can be read


' Toggle  IP address between 192.168.1.16:9080 and 192.168.1.17:9080
'
if DM[4] = 16
   DM[4] = 17
else
   DM[4] = 16
endif
A$ = str$(DM[1])+"."+str$(DM[2])+"."+str$(DM[3])+"."+str$(DM[4])+":"+str$(DM[5])

SetLCD 3,1, "Next IP"
SetLCD 4,1, A$
Delay 4000      ' kill some time so the LCD can be read

Set_IPAddr 1   ' Set new IP address

RESET         ' Update flash memory that holds the IP variables

RESTART         ' Force a cold reboot to restart the PLC and actually configure the
            '  PLC to the changed IP address.

[/color]

If I toggle the INPUT, I can see on the LCD, that the ToggleIP custom function runs.  I am convinced that the RESTART statement does restart the ladder logic scanning mechanism. However, the IP address shown on the LCD after the RESTAT, is not the actual IP address of the PLC.  The actual IP address is unchanged!

If I power down the PLC, then the PLC's IP does change to match the value on the LCD.

This is my evidence that RESTART is not the same the ultimate reset caused by killing power to the PLC.

Hardware info:  FMD1616 r82A

What am I missing?

Gary D
« Last Edit: September 28, 2014, 04:44:18 PM by garysdickinson »

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:RESTART Statement and New IP address
« Reply #1 on: September 28, 2014, 04:24:29 PM »
I added another couple lines to the init function to display the "current" IP address using the Print #4 "<IP>" approach to confirm that the RESTART is not working.  

My current Init code looks like this:

' Init
'
Get_IPAddr 1         ' Get PLC IP addres in DM[1..5]
A$ = str$(DM[1])+"."+str$(DM[2])+"."+str$(DM[3])+"."+str$(DM[4])+":"+str$(DM[5])

SetLCD 0,1,"\01"      ' Clear LCD display
SetLCD 0,1,Chr$(12)   ' No cursor
SetLCD 1,1, "PLC IP Address:"
SetLCD 2,1, A$

Print #4 "<IP>"         ' Get IP address, another way
A$ = INPUT$(4)
SetLCD 3,1, A$
[/color]

The the "LCD" screen looks like this after the RESTART:

Gary D

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RESTART Statement and New IP address
« Reply #2 on: September 29, 2014, 09:04:53 AM »
The problem is that you put a RESTART statement after the RESET statement.

When RESET is run, the PLC stop execution of the current program and clear all memory, then start running the PLC program from the beginning of the ladder logic scan.  So it means that RESTART was not executed.

If you want to backup the changed non volatile memory to flash (for FMD and Nano-10 only, not needed for F or Fx series PLCs), a better method is to use the SETSYSTEM 252,0 instead of RESET. You can then execute the RESTART after SETSYSTEM command. (We will clarify this point in the help files for future i-TRiLOGI releases).

Note: When the RESTART or REBOOT command is executed you will see the 3 status LED lights up for 1 second and then then two red LEDs should go off. If that did not happen it means RESTART was not executed.


« Last Edit: September 29, 2014, 10:56:23 AM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS

garysdickinson

  • Hero Member
  • Posts: 502
  • Old PLC Coder
    • View Profile
Re:RESTART Statement and New IP address
« Reply #3 on: September 29, 2014, 12:38:35 PM »
The use of SETSYSTEM 252,0 rather than RESET got me the results that I was expecting.

I wasn't getting the 3 status LEDs so, the RESTART command was not executing.

So if I understand things,

SETSYSTEM 252,0     ONLY copies the simulated EEPROM contents to the physical  EEPROM so that changes to the COUNTER and TIMER SV will be restored following power on reset. Similary changes made to the  IP, DNS, GateWay, SubNetMask and the alike are saved to the physical EEPROM so that they can become effective on the next power on reset.

RESET forces variables to Zero, OUTPUTs to zero, clears relays, saves simulated EEPROM variables to physical EEPROM (same as SETSYSTEM 252,0)  and then restarts the ladder logic. RESET does not perform a power on reset, so changes to the IP address of the PLC will not changed (but the SV for COUNTERs and TIMERs are).  The documentation for RESET mentions "SET_IPAddr", but does not mention, that backing the changed IP address up to physical EEPROM doesn't change the IP address.  RESET is the last statement executed in a custom function.

RESTART doesn't save anything to physical non-volatile memory.  RESTART is the last statement that will execute in a custom function.  RESTART is equivalent to powering the PLC down and then re-applying power.

The documentation for "SET_IPAddr" is rather misleading:
  • For Nano-10 and FMD PLCs,  you should soft-reset (using the RESET command) and restart (cold boot) the PLC after changing the IP address so that the new IP address will be saved into the virtual EEPROM
  • The PLC will only assume the new IP address after it has been rebooted (via the RESTART command or power-on reset).

In the first bullet I read RESET Command followed by restart.  I interpreted "restart" to mean the RESTART command.

The second bullet, emphasized that I needed to use the RESTART statement, but the RESTART statement cannot follow the RESET statement as it will never execute.

Thanks, I think I got it,


Gary D
« Last Edit: September 29, 2014, 12:52:39 PM by garysdickinson »

support

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3174
    • View Profile
    • Internet Programmable PLCs
Re:RESTART Statement and New IP address
« Reply #4 on: September 29, 2014, 02:31:23 PM »
What you have listed down are accurate.

The emulated EEPROM is emulated in RAM so that they are byte changeable. When you run the SETSYSTEM 252,0 they get backed up into the flash memory (which can only be erased a block at a time and not individual bytes). Nano-10 and FMD do not have FRAM/EEPROM bullt-in so the emulated EEPROM is used to store both the user EEPROM data as well as the timer and counter SVs and the system parameters such as IP address etc.

Note that even if you add the FRAM-RTC-xxx option, only the user EEPROM port is shifted to the real FRAM but the system parameters such as IP address, timers and counter SVs are still stored in the emulated EEPROM so running SETSYSTEM 252,0 is necessary to store them into the flash memory permanently. RESET command actually calls the SETSYSTEM 252,2 before it does the reset of the reset function as you mentioned.

We will update the help files to remove the ambiguity. Thanks again for your feedback.
« Last Edit: September 29, 2014, 02:34:21 PM by support »
Email: support@triplc.com
Tel: 1-877-TRI-PLCS