pdevs_client.alc 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  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(port)
  16. while (True):
  17. if (comm_hasInput(port)):
  18. log(cast_v2s(has_input()))
  19. the_input = comm_get(port)
  20. log("(PDEVS) Got input from simulator!")
  21. log(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(cast_v2s(the_input))
  27. if (is_physical_string(the_input)):
  28. comm_set(port, the_input)
  29. else:
  30. comm_set(port, cast_v2s(the_input))
  31. sleep(0.05)