Hello Aimar,
Thanks for writing in.
RDK.waitDI() function cannot be used from the API, for the time being for simulation purposes. This is something we will definitely improve in the future. However, there is an easy way to go around it.
We can retrieve the Station Parameters using the RDK.getParam('in1') and simulate the DI being made 1 by the user by clicking 'Okay' on the message box pop up. By clicking on 'Cancel', an exception will be raised. Comments in the program below explain further.
Another important thing here is to check for the RDK.RunMode(), else you wont be able to generate program for the robot. Find attached the .rdk file.
Hope this helps.
Thanks for writing in.
RDK.waitDI() function cannot be used from the API, for the time being for simulation purposes. This is something we will definitely improve in the future. However, there is an easy way to go around it.
We can retrieve the Station Parameters using the RDK.getParam('in1') and simulate the DI being made 1 by the user by clicking 'Okay' on the message box pop up. By clicking on 'Cancel', an exception will be raised. Comments in the program below explain further.
Code:
def WaitForBox():
"""Wait for Digital Input 1 to be 1. This function will work in simulation mode as well as to generate the robot program.
For simulation, we run the statements under the first 'if' statement which simulate a waitDI and the code under the 'else' statement is used to generate robot program """
robot.setDO('out1',1)
di_param = 'in1'
di_value = 1
di_timeout = 2 #timeout in seconds
if RDK.RunMode() == RUNMODE_SIMULATE:
tstart = time.time()
while RDK.getParam(di_param) != di_value:
# If we want a timeout, check the timeout:
if di_timeout >= 0 and time.time() > (tstart + di_timeout):
# option to continue:
if mbox("Digital input timeout: " + di_param + "\nContinue?"):
break
raise Exception("Digital input timeout: " + di_param)
else:
robot.waitDI(di_param, di_value) #added to generate the robot program with waitDI
robot.setDO('out1',0)
Another important thing here is to check for the RDK.RunMode(), else you wont be able to generate program for the robot. Find attached the .rdk file.
Hope this helps.