pdevs_client.alc 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. include "primitives.alh"
  2. include "services.alh"
  3. include "modelling.alh"
  4. include "object_operations.alh"
  5. include "utils.alh"
  6. include "io.alh"
  7. Boolean function main(model : Element):
  8. String port
  9. String the_input
  10. String devs_model
  11. port = comm_connect("pypdevs_simulator")
  12. log("(PDEVS) task name = " + get_taskname())
  13. log("(PDEVS) Sending model...")
  14. comm_set(port, read_attribute(model, set_pop(allInstances(model, "MyString/MyString")), "value"))
  15. log("(PDEVS) " + port)
  16. while (True):
  17. if (comm_hasInput(port)):
  18. log(cast_value(has_input()))
  19. the_input = comm_get(port)
  20. log("(PDEVS) Got input from simulator!")
  21. log("(PDEVS) " + the_input)
  22. output(the_input)
  23. if (has_input()):
  24. the_input = input()
  25. log("(PDEVS) Got input from console/ps simulator!")
  26. log("(PDEVS) " + cast_value(the_input))
  27. if (is_physical_string(the_input)):
  28. comm_set(port, the_input)
  29. else:
  30. comm_set(port, cast_value(the_input))
  31. sleep(0.05)