Recently I had connection issues as some of them are resulted by a previous aborted flash (application load).
For some reason around 1/20 of the cases the upload during login results a bad flash sector,
causing an exception at device side and it locks out the comm-cycle.
This looks like a serious problem on the hardware or runtime side. I think you should contact your vendor, to diagnose and solve the problem.
As a workaround I tried to erase the previous application (it might help) using the reset_origin()
but it didnt do anything.
1) is this function/method working properly?
This funciton should to the same as the "reset origin" Command available in for the user in the CODESYS menus.
If the user command works, but the script command does not work, please file a bug report via support department.
On the other hand, when the user command also does not work, the problem is probably on the runtime side (maybe due to the corrupted flash).
Reading the API reference I stumbled into this piece of description:
Never 0 Online change shall never be performed. In that case a full download is forced.
Try 1 Online change shall be tried. If not possible, a full download shall be performed.
Force 2 Online change shall be forced. If not possible, the action is terminated with no change.
While login has the following interface:
void login( OnlineChangeOption change_option, bool delete_foreign_apps )
2) what does onlinechange mean in this context? How is it possible to never perform online change while reflashing the application?
That's explained in the docu you cited yourself above:
Never 0 Online change shall never be performed. [b]In that case a full download is forced. [/b]
To restate it: If OnlineChangeOption.Never is used, a full download of the application is performed, instead of attempting an online change.
An online change means that only the differences to the currently running application are downloaded to the PLC, and the changes are applied while the application keeps running. In contrast, a full download stops the running application, removes it, and installs the new application in "stopped" state.
Whether an online change is possible depends on some preconditions - for example, the compiler needs the reference context of the code which is currently running on the PLC, and the changes must be "normal" code changes - operations like a "Clean", or change of compiler version, or similar operations prevent online changes.
If the compiler can assert that the code is exactly the same, a simple login is performed. If there are code changes, the compiler will calculate the changeset (which may include some copying and relocation of memory, e. g. if the size of a struct or FB did change), which will then be sent to the PLC and applied on the fly to the running application during the login.
3) what it that delete_foreign_apps for when I have the 'Never' option?
The "Never" option will just always perform a full download and not even attempt an online change, so why should it not be possible to delete the foreign applications?
Check out the CODESYS store: http://store.codesys.com/CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions