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.
... View more