Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Python API - How to use CloseStation()

I am trying to create a unit test suite to test the validity/existence of multiple Items in my RoboDK station. The station is opened each time the tests are run, so after running the tests few times the station tree becomes extremely crowded with multiple copies of the original station. To avoid having to repeatedly close each copy individually, I would like to write a cleanup method to close the station after the tests are finished. The method 'CloseStation()' defined in the Robolink Python API seems to be exactly what I am looking for, but the documentation is not very clear on how it is meant to be used and everything I try seems to cause errors. Can someone please explain the proper usage of this method? Sample code of it working would be extremely helpful.

Below is the code I have tried so far and the corresponding results. It seems to me that the first code snippet should be the correct usage since CloseStation() is defined as a member of the class Robolink() in

1.) Calling the method directly on a Robolink() object:  

Result (from console): 
Quote: line 521, in _check_status
    raise Exception(self.LAST_STATUS_MESSAGE)
Exception: Invalid item provided: The item identifier provided is not valid or it does not exist. 

2.) Calling the method on a station Item object:
Quote:station = robolink.Robolink().ActiveStation()

Quote:AttributeError: 'Item' object has no attribute 'CloseStation'
You should create a Robolink() object to create a connection to RoboDK (usually done once):
RDK = robolink.Robolink()

This will open RoboDK if it is not already running.

Then you can do:

More information and examples here:
For anyone else experiencing this, it appears to be the result of incompatibility between old versions of the robodk Python package and newer versions of the RoboDK app. Updating both to the most recent version resolved the issue for me.

Users browsing this thread:
1 Guest(s)