FORUM CTRLX AUTOMATION
ctrlX World Partner Apps for ctrlX AUTOMATION
Dear Community User! We are updating our platform to a new
system.
Read more: Important
information on the platform change.
06-11-2024 11:13 AM
Hello,
I am using the ctrlX PLC Engineering Web API (2.4) in a powershell (7) scripting environment.
I combined the ProjectJobs "Open" and "SaveAndInstallIntoLibraryRepository" in a script. First the project is opened. The status of the Job ID is checked every 6 seconds until it is done, afterwards the library is installed.
A successful run gives these logs:
#################################
######### OPEN PROJECT ##########
#################################
Open project: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params: {"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\agent\\_work\\8\\s\\Sample.library", "keepProjectVersion": false}}
Open project Job ID: 124d964e073ebbb7
Open project state: Running
Open project state: Running
Open project state: Running
Open project state: Done
C:\\agent\\_work\\8\\s\\Sample.library opened successfully.
#################################
######## INSTALL PROJECT ########
#################################
Install: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params: {"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}
Save and Install into library repository Job ID: 22cff790bd9e7762
Save and Install into library repository state: Done
But every other time the same script fails with these logs:
#################################
######### OPEN PROJECT ##########
#################################
Open project: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params: {"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\agent\\_work\\8\\s\\Sample.library", "keepProjectVersion": false}}
Open project Job ID: 5265406ec5c9666c
Open project state: Done
C:\\agent\\_work\\8\\s\\Sample.library opened successfully.
#################################
######## INSTALL PROJECT ########
#################################
Install: C:\\agent\\_work\\8\\s\\Sample.library
Request job with params: {"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}
Save and Install into library repository Job ID: 32ea04d2bd4985ac
Save and Install into library repository state: Failed
Save and Install into library repository failed.
No open project found.
It is the exact same script.
It seems, like the Open job returns success, although the project was not opened.
Does anyone have an idea what can cause this?
Thank you and best regards
06-11-2024 01:39 PM - edited 06-11-2024 10:17 PM
Have you tried appending to your script a job to close the project? Does the script behave sporatically then?
Edit: The script below appears to be working properly for me in ctrlX PLC Engineering 2.6.
$ip_adr = "localhost:9004"
$result = Invoke-WebRequest `
-Uri http://$ip_adr/plc/engineering/api/v2/jobs `
-ContentType "application/json" `
-Method POST `
-Body '{"jobType":"ProjectJob","jobParameters":{"action": "Open", "path": "C:\\Users\\bostromc\\Desktop\\sample.library", "keepProjectVersion": false}}' `
| ConvertFrom-Json
$job_id = $result.id
$state = ""
Write-Output $result
while ($state -ne 'Done') {
start-sleep -seconds 1
$result = Invoke-WebRequest `
-Uri http://$ip_adr/plc/engineering/api/v2/jobs/$job_id `
-ContentType "application/json" `
-Method GET `
| ConvertFrom-Json
Write-Output $result
$state = $result.state
if ($state -eq 'Failed') {
Write-Error 'Invoke-WebRequest failed' -ErrorAction Stop
}
}
$result = Invoke-WebRequest `
-Uri http://$ip_adr/plc/engineering/api/v2/jobs `
-ContentType "application/json" `
-Method POST `
-Body '{"jobType":"ProjectJob","jobParameters":{"action": "SaveAndInstallIntoLibraryRepository"}}' `
| ConvertFrom-Json
$job_id = $result.id
$state = ""
while ($state -ne 'Done') {
start-sleep -seconds 1
$result = Invoke-WebRequest `
-Uri http://$ip_adr/plc/engineering/api/v2/jobs/$job_id `
-ContentType "application/json" `
-Method GET `
| ConvertFrom-Json
Write-Output $result
$state = $result.state
if ($state -eq 'Failed') {
Write-Error 'Invoke-WebRequest failed' -ErrorAction Stop
}
}
$result = Invoke-WebRequest `
-Uri http://$ip_adr/plc/engineering/api/v2/jobs `
-ContentType "application/json" `
-Method POST `
-Body '{"jobType":"ProjectJob","jobParameters":{"action": "Close"}}' `
| ConvertFrom-Json
pause
Note that if a project is already open in ctrlX PLC Engineering when the intial job request is made (i.e. action=open), the job fails as follows:
I think this is the correct behaviour.
06-11-2024 04:43 PM
You mean after the SaveAndInstallIntoLibraryRepository Job?
Not yet, I'll try.
06-12-2024 02:12 PM
Hi,
i added the close job. This job gives the same result as the SaveAndInstallIntoLibraryRepository job.
#################################
######### CLOSE PROJECT #########
#################################
Close project
Request job with params: {"jobType":"ProjectJob","jobParameters":{"action": "Close"}}
Close project Job ID: b7525e6698fde56c
Close project state: Failed
Close project failed.
No open project found.
It seems like there is no project open, although ctrlX returns success on the open project job.
And as mentioned before, I got 2 successful runs before the next failed run. So it works more often than it fails.