cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Need help navigating or using the PTC Community? Contact the community team. X

I need to programmatically reinitialize KEPServer EX v5.14

DL_9289070
4-Participant

I need to programmatically reinitialize KEPServer EX v5.14

I am using KEPServerEX 5.14. I have an excel spreadsheet with multiple DDE links to numerous PLCs across a network. Each PLC has an 90 element array for points i need to make calculations on each day. The spreadsheet opens at 12:01 each morning via batch file and windows task scheduler and then excel runs a macro that gathers the data i need from cells that update based on current data in the PLCs and closes Excel. The columns set from row 3-92 for example:  "=kepdde|RTU5PLC1!'AR1F32-0000031(x)" where x is the array element 0-89 and the RTU changes based on the device i am talking to. may be too much detail there, but it works for 7 different RTUs and 28 different arrays 100% of the time EXCEPT...

I have one specific RTU that brings in 8 arrays (columns a - h) and for some reason column D misses some of the data, ie. cells D3-D5 are not populated, D6-D9 are populated but D10-D23 are not and D24-D92 are good. The macro pukes every time it gets a "N/A" in any of it's fields so this is a problem. 

 

I can make it consistently populate all of the fields if i manually go to KEPServerEX in the task bar and right click it and select "Reinitialize" then restart the excel sheet. The problem is i need to reinitialize it each day and this is not a computer that is monitored daily. Does anyone know how i can do this in a batch file?   

1 ACCEPTED SOLUTION

Accepted Solutions

Hello, 

 

First some context for what you're seeing. By default, Kepware installs its core process - "server_runtime.exe" - as a System Service, and every system service can be stopped and restarted through a batch file that calls the Windows Service Control Manager with the "net stop" and "net start" commands referenced earlier in this thread. However, Windows does NOT permit System Services to interact directly with user-space applications like Excel using the Dynamic Data Exchange / DDE protocol. So, I can see you've configured Kepware to run as an Interactive application, which is also why you do not see "server_runtime.exe" / KEPServerEX V5 Runtime as an entry in your Service list for Kepware. Running KEPServer as an Interactive application is the only way to allow it to become a DDE data source for Excel.

 

This means that unfortunately, in V5 of Kepware running in interactive model, there is no programmatic mechanism that you can use to automatically stop and restart Kepware's runtime process "gracefully". If you are willing to purchase a support agreement, you can upgrade to the latest version of Kepware (V6.11) and this version offers a RESTful configuration API (based on HTTP) that you can use to script (through Powershell, for example) reinitialization of our runtime process. I actually have a sample Powershell script I can provide if you choose to upgrade.

 

The only option available to you would be to use command line interface commands via a batch file that "kills" our server_runtime.exe process, and then calls for it to be launched again. You're welcome to try that, however I cannot recommend that you terminate our process in this manner as it is not a graceful shutdown.

 

Have you looked into the problem related to your Excel macros that have it "break" when an N/A is received? You could also look at the reason why you receive N/A in the first place. On the surface, to me it seems like your macro is at some point providing Kepware an invalid tag address, which errors in Kepware and is why Excel renders "N/A" in that field. Kepware records all incorrect tag addressing attempts as "Attempt to add item" errors in the Kepware event log, so if you look in the Kepware event log it might offer clues about the area of your macro that needs adjustment.

 

Thanks!
Sam

View solution in original post

6 REPLIES 6

 Hi,

 

Here is a tip - "Programmatically starting and stopping Kepserver Runtime": https://steveunofficialguide.wordpress.com/2018/01/23/guide-no-4-pro-grammatically-starting-and-stopping-kepserver-runtime/ 

DL_9289070
4-Participant
(To:VladimirN)

thanks Vladimir,  

i did try that after searching the forums but it did not work as expected. i have three services running associated with KEPServer, 

KEPServer 5.14 Event Logger, KEPServer 5.14 Key Service, and KEPServer 5.14 OPC .NET. 

 

I made the batch stop and start all three and even paused for a few seconds to ensure they were back up but it did not help. To further investigate, i stopped all three above services and the EX icon is still showing in the task bar...could the service be named something other than KEPServer??

Hello, 

 

First some context for what you're seeing. By default, Kepware installs its core process - "server_runtime.exe" - as a System Service, and every system service can be stopped and restarted through a batch file that calls the Windows Service Control Manager with the "net stop" and "net start" commands referenced earlier in this thread. However, Windows does NOT permit System Services to interact directly with user-space applications like Excel using the Dynamic Data Exchange / DDE protocol. So, I can see you've configured Kepware to run as an Interactive application, which is also why you do not see "server_runtime.exe" / KEPServerEX V5 Runtime as an entry in your Service list for Kepware. Running KEPServer as an Interactive application is the only way to allow it to become a DDE data source for Excel.

 

This means that unfortunately, in V5 of Kepware running in interactive model, there is no programmatic mechanism that you can use to automatically stop and restart Kepware's runtime process "gracefully". If you are willing to purchase a support agreement, you can upgrade to the latest version of Kepware (V6.11) and this version offers a RESTful configuration API (based on HTTP) that you can use to script (through Powershell, for example) reinitialization of our runtime process. I actually have a sample Powershell script I can provide if you choose to upgrade.

 

The only option available to you would be to use command line interface commands via a batch file that "kills" our server_runtime.exe process, and then calls for it to be launched again. You're welcome to try that, however I cannot recommend that you terminate our process in this manner as it is not a graceful shutdown.

 

Have you looked into the problem related to your Excel macros that have it "break" when an N/A is received? You could also look at the reason why you receive N/A in the first place. On the surface, to me it seems like your macro is at some point providing Kepware an invalid tag address, which errors in Kepware and is why Excel renders "N/A" in that field. Kepware records all incorrect tag addressing attempts as "Attempt to add item" errors in the Kepware event log, so if you look in the Kepware event log it might offer clues about the area of your macro that needs adjustment.

 

Thanks!
Sam

Thank you Sam!

I will discuss with the customer whether they are willing to purchase the support agreement. That sounds like the best way to approach this. In the meantime, i have been killing the server_runtime.exe and i agree, this is not a good long term solution. I needed something to get this data while i was out of town and unable to manually update daily.

 

I will be in touch...

Thanks again!!

DL_9289070
4-Participant
(To:DL_9289070)

For anyone who may look at this post in the future...i hope this helps. 

I think i found a nuclear option that works. I kill the process "server_admin.exe" using taskkill in my batch file, wait 6 seconds then start server_admin.exe again. Then i can start excel and all of the cells are correctly populated!!

I have to call the batch by a shortcut to give it admin privileges otherwise taskkill gets denied. This is a trick i discovered awhile ago...make your batch file, create a shortcut to it, right click the shortcut and in properties>shortcut>advanced check "run as administrator"  then call the shortcut not the actual batch and it gets admin access.

this is NOT a graceful way to handle the problem but it is getting the job done. 

 

Disregard....this only worked a few times..back to square 1

I need a way to Reinitialize KEPServer from batch file 

Replied to your earlier post - see above. Note that server_admin is a separate process from our core communications server and stopping it / starting it has zero impact on server communications; unfortunately you had some false positives occur.

Top Tags