def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_minimal_snd") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create publisher pub = StringPublisher("Hello") msg = "HELLO WORLD FROM PYTHON" # send messages i = 0 while ecal_core.ok(): i = i + 1 current_message = "{} {:6d}".format(msg, i) print("Sending: {}".format(current_message)) pub.send(current_message) time.sleep(0.01) # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_person_rec") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create publisher sub = ProtoSubscriber("person", person_pb2.Person) # receive messages while ecal_core.ok(): ret, person, time = sub.receive(500) # deserialize person from message buffer if ret > 0: # print person content print("") print("Received person ..") print("person id : {}".format(person.id)) print("person name : {}".format(person.name)) print("person stype : {}".format(person.stype)) print("person email : {}".format(person.email)) print("dog.name : {}".format(person.dog.name)) print("house.rooms : {}".format(person.house.rooms)) # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_minimal_rec_cb") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create subscriber and connect callback sub = StringSubscriber("Hello") sub.set_callback(callback) # idle main thread while ecal_core.ok(): time.sleep(0.1) # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_person_rec_json") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create publisher sub = ecal_core.subscriberDynJSON("person") sub.set_callback(callback) # receive messages while ecal_core.ok(): time.sleep(0.1) # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_minimal_rec") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create subscriber sub = StringSubscriber("Hello") # receive messages while ecal_core.ok(): ret, msg, time = sub.receive(500) if ret > 0: print("Received: {} ms {}".format(time, msg)) else: print("Subscriber timeout ..") # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_person_snd") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create publisher pub = ProtoPublisher("person", person_pb2.Person) # create person instance and set content person = person_pb2.Person() person.name = "Max" person.stype = person_pb2.Person.MALE person.email = "*****@*****.**" person.dog.name = "Brandy" person.house.rooms = 4 # send messages while ecal_core.ok(): # change person id person.id = person.id + 1 # send person print("Sending person {}".format(person.id)) pub.send(person) # sleep 100 ms time.sleep(0.1) # finalize eCAL API ecal_core.finalize()
def main(): # print eCAL version and date print("eCAL {} ({})\n".format(ecal_core.getversion(), ecal_core.getdate())) # initialize eCAL API ecal_core.initialize(sys.argv, "py_minimal_service") # set process state ecal_core.set_process_state(1, 1, "I feel good") # create server "Ping" server = ecal_service.Server("DemoServer") # define the server method "foo" function def foo_req_callback(method_name, req_type, resp_type, request): print("'DemoService' method '{}' called with {}".format(method_name, request)) return 0, bytes("thank you for calling foo :-)", "ascii") # define the server method "ping" function def ping_req_callback(method_name, req_type, resp_type, request): print("'DemoService' method '{}' called with {}".format(method_name, request)) return 0, bytes("pong", "ascii") # define the server methods and connect them to the callbacks server.add_method_callback("foo", "string", "string", foo_req_callback) server.add_method_callback("ping", "ping_type", "pong_type", ping_req_callback) # create a client for the "DemoServer" service client = ecal_service.Client("DemoServer") # define the client response callback to catch server responses def client_resp_callback(service_info, response): if (service_info["call_state"] == "call_state_executed"): print("'DemoService' method '{}' responded : '{}'".format(service_info["method_name"], response)) print() else: print("server {} response failed, error : '{}'".format(service_info["host_name"], service_info["error_msg"])) print() # and add it to the client client.add_response_callback(client_resp_callback) # match all time.sleep(2.0) # call foo method i = 0 while ecal_core.ok() and i < 20: i = i + 1 request = bytes("hello foo {}".format(i), "ascii") print("'DemoService' method 'foo' requested with : {}".format(request)) client.call_method("foo", request) time.sleep(1.0) # call ping method i = 0 while ecal_core.ok() and i < 20: i = i + 1 request = bytes("ping number {}".format(i), "ascii") print("'DemoService' method 'ping' requested with : {}".format(request)) client.call_method("ping", request) time.sleep(1.0) # destroy client and server client.destroy() server.destroy() # finalize eCAL API ecal_core.finalize()