mwstettler Posted November 7, 2017 Posted November 7, 2017 I am an experienced UNIX programmer who is successfully using background CPLCs in my DeltaTau application. However, there are some functions I would like to implement that would greatly benefit from an initialization routine (only called once at application startup), and a shutdown routine (only called once when the application is shut down). Specifically, I am using geomacro hardware and would like to open a communication port at initialization and close it as part of shutdown. I have a future requirement to send some position data to a remote system using UDP Ethernet, which will also require initialization and shutdown logic. I can imagine using multiple PLCs or a stand alone UNIX application to implement this, but am wondering if there is a more elegant way. Thanks!
Clopedandle Posted November 7, 2017 Posted November 7, 2017 For this kind of application, a basic Background C Application is the way to go. You can trap startup and exiting pretty easily that way. Just have your startup code run as the first block or function call inside where the template basically says "put your code here," trap your main communication loop in a while loop with a nanosleep() of some duration, a timeout condition, and a "check for kill flag," condition. If the timeout or kill flag go true, run your cleanup code block/function before you exit. I do not suggest using CPLCs for communication code.
Recommended Posts