Answers
Dec 18, 2019 - 10:10 AM
Thanks to a helpful hint from your colleague George (PSCAD support) I could finally implement the license check functionality into our automation tool: The solution is the licensed()-method from the automation.pscad.PSCAD() class. You find the exemplary definition of my function called allocate_pscad_license() below:
sys.path.append(r"C:\Program Files (x86)\PSCAD\Automation\Lib\mhrc")
import automation.controller
(...)
# PSCAD LICENSE FUNCTION
def allocate_pscad_license(pscad_version, opts):
print('Allocating a PSCAD license...')
print('')
# Initialization
controller = automation.controller.Controller()
pscad = controller.launch(pscad_version, options=opts)
time.sleep(10) #wait until PSCAD is fully launched and has obtained the eventually available license
pscad_license = pscad.licensed()
# Repeat PSCAD launch until a license is successfully assigned
i=0
while not pscad_license==True:
#Close the currently hold unlicensed PSCAD object
pscad.quit()
#Create an animated status output for the console window
if i==0:
print("There is currently no PSCAD license available. Waiting for a license...", end="")
else:
print('.', end="")
i = i+1
#Next try of obtaining a PSCAD license
pscad = controller.launch(pscad_version, options=opts)
time.sleep(10) #wait until PSCAD is fully launched and has obtained the eventually available license
pscad_license = pscad.licensed()
#Successfully assigned a license
print('')
print('Successfully allocated a PSCAD license!')
return pscad
The following code can be used to call the function:
## Launch PSCAD; variable 'licensed_pscad_object' is an object of Class automation.pscad.PSCAD()
# Check if there is a PSCAD license available and allocate it (if no license is available, the function will wait for the next available license)
opts = dict(silence=True, minimize=True)
licensed_pscad_object = allocate_pscad_license(pscad_version, opts)
However, with this solution it is quite annoying that the PSCAD GUI opens and closes the entire time of excuting the python script. Is there maybe a way to launch PSCAD in a "hidden" state, i.e. to not show the PSCAD window at all when launching PSCAD?
Best regards
Hendrik
By
Hi Hendrik,
This is a great question and it is clearly outlined. In order for this question to get in front of a developer, or at least an advanced/experienced user of the PSCAD Automation Library, I suggest that you send an email directly to the PSCAD support team (support@mhi.ca).
Regards,
Mathias
By
Hi Mathias,
Thanks for this hint. I have sent an email to the PSCAD support team in which I refer to this thread.
It would be very nice, if they could assist here with an answer.
However, in case there is no working method available in the PSCAD Python Automation Library yet for checking the availibility of a license, it would still be a great feature for the next update of the Automation Library.
I'll keep this thread updated.
Regards,
Hendrik
Add New Comment