This has been an on-going topic for CODESYS on the Raspberry Pi. The Raspberry Pi does not have non-volatile RAM, and so the built in PERSISTENT and RETAIN variables within IEC61131 do not function. The neatest solution I have seen is discussed in this forum posthttps://forum.codesys.com/viewtopic.php?t=5722 where 3S have provided some sample code that can write retain variables to a file on demand and then restore at power up.
Be careful about writing too frequently to the SDCard as you increase the chance of file system corruption if the power is interrupted whilst writing.
This should be possible if you have the appropriate Linux device drivers installed. This is really a feature of CODESYS for Raspberry PI - there is an explanation of how to do this in the CODESYS Forum https://forum.codesys.com/viewtopic.php?t=5699
Please note that if you support the USB serial device then my understanding is you will no longer be able to access the built in serial ports on the Neuron with CODESYS (Because CODESYS appends the COM port number to a base DeviceFile, and the internal ports would have a different base name to the USB ones.). If you need further detail on this issue I suggest that the CODESYS Raspberry Pi forum is the best place to get further assistance.
@lefrank01 thank you for sharing your tips. I have also had this reported once or twice and on each occasion starting from a clean install of Raspbian, installing CODESYS for Raspberry Pi and then running the script that ships with CODESYS for UniPi has resolved users problems.
I have seen this issue reported a couple of times. On each occasion it was resolved by a clean install of Raspbian, followed by an install of CODESYS for Raspberry Pi and running the install script that installed as part of CODESYS for UniPi (See the data sheet for install instructions).