def main(): root = Root('camtest', device_nr=my_device_nr, security='certchainfile=myhome-bundle.crt') ioterminal.start(root) Connection(root, "127.0.0.1", "tls,down,dynamic", user='******', password='******') camera_buffer = BrickBuffer(root, "exp.gina1.cafenet", "imp.gina1.cafenet", "rec_", timeout=-1) camera_buffer.set_receive(True) while (ioterminal.run(root)): data = camera_buffer.get() if data != None: print(data) time.sleep(0.01) root.delete()
def main(): global root root = Root('netconftest', security='certfile=bob.crt,keyfile=bob.key') root.queue_events() ioterminal.start(root) epoint = EndPoint(root, flags='tls,dynamic') while (ioterminal.run(root)): e = root.wait_com_event(1000) if e != None: print(e) event = e[0] mblk_name = e[3] device_name = e[2] network_name = e[1] # New device. This has a potential problem. if event == 'new_device': #set_network_conf(device_name, network_name) # get_network_conf(device_name, network_name) # print(root.setconf(device_name + "." + network_name, str.encode("Dummy config data"))) # print(root.getconf(device_name + "." + network_name)) print(root.getconf(device_name + "." + network_name, 3)) # default network configuration root.delete()
def main(): device_name = 'mydevice' device_nr = 3 full_device_name = device_name + str(device_nr) root = Root(device_name, device_nr=device_nr, network_name='cafenet', security='certchainfile=myhome-bundle.crt') root.queue_events() ioterminal.start(root) exp = MemoryBlock(root, 'up', 'exp') imp = MemoryBlock(root, 'down', 'imp') conf_exp = MemoryBlock(root, 'up', 'conf_exp') conf_imp = MemoryBlock(root, 'down', 'conf_imp') with open('test_device.json', 'r') as file: signal_conf = file.read() data = json2bin(signal_conf) info = MemoryBlock(root, 'up,auto', 'info', nbytes=len(data)) info.publish(data) connection = Connection(root, "127.0.0.1", "tls,up") frd_cmd = Signal(root, "frd_cmd") tod_cmd = Signal(root, "tod_cmd") stream = root.initconf(full_device_name, flags='device') while (ioterminal.run(root)): imp.receive() conf_imp.receive() # If this device receives "what is congifuration" command, return it. Here massive "Hulabaloo" # for any persistent block number. state_bits, cmd = frd_cmd.get_ext() if (state_bits & 2) and cmd == 1: print( root.setconf(full_device_name, str.encode("Hulabaloo"), flags='device')) # If this device receives "configure youself" command, just print the received configuration. state_bits, cmd = tod_cmd.get_ext() if (state_bits & 2) and cmd == 1: print(root.getconf(full_device_name, flags='device')) exp.send() conf_exp.send() time.sleep(0.03) root.delete()
def build(self): assembly_data = {} self.root = LinearCameraItem("lcam_flat") self.root.set_device(Root('testwidget'), "gina2.cafenet", assembly_data) return self.root
def main(): root = Root('mydevice', device_nr=10000, network_name='cafenet', security='certchainfile=myhome-bundle.crt') root.queue_events() ioterminal.start(root) myinputs = MemoryBlock(root, 'up,auto', 'exp', nbytes=256) data = json2bin(signal_conf) info = MemoryBlock(root, 'up,auto', 'info', nbytes=len(data)) info.publish(data) connection = Connection(root, "127.0.0.1", "tls,up") hor = Signal(root, "hor") i = 1 while (ioterminal.run(root)): hor.set(i) i = i + 1 time.sleep(0.01) # connection.delete is needed, should not be # hor.delete() # myinputs.delete() # info.delete() # connection.delete() root.delete()
def main(): root = Root('spy', device_nr=10000, network_name='cafenet', security='certchainfile=myhome-bundle.crt') root.queue_events() ioterminal.start(root) connection = Connection(root, "127.0.0.1", "tls,down,dynamic") while (ioterminal.run(root)): e = root.wait_com_event(1000) root.delete()
def connect(self, source_object, *args): if self.ioc_root != None: self.disconnect() ioc_user = args[0] ioc_password = args[1] self.ioc_params = args[2] transport_flag = self.ioc_params['transport'].lower() if transport_flag == 'serial': parameters = self.ioc_params['serport'] else: parameters = self.ioc_params['ip'] if self.ioc_params['role'] == "CLIENT": if transport_flag == 'tls': self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet', security='certchainfile=' + self.ioc_params['cert_chain']) self.ioc_root.queue_events() self.ioc_connection = Connection(self.ioc_root, parameters=parameters, flags=transport_flag + ',down,dynamic,bidirectional', user=ioc_user, password=ioc_password) else: self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet') self.ioc_root.queue_events() self.ioc_connection = Connection(self.ioc_root, parameters=parameters, flags=transport_flag + ',down,dynamic,bidirectional', user=ioc_user) else: if transport_flag == 'tls': self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet', security='certfile=' + self.ioc_params['serv_cert'] + ',keyfile=' + self.ioc_params['serv_key']) self.ioc_root.queue_events() self.ioc_epoint = EndPoint(self.ioc_root, flags=transport_flag + ',dynamic') else: self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet') self.ioc_root.queue_events() if transport_flag == 'serial': self.ioc_epoint = EndPoint(self.ioc_root, parameters=parameters, flags=transport_flag + ',dynamic') else: self.ioc_epoint = EndPoint(self.ioc_root, flags=transport_flag + ',dynamic') self.set_displayed_page(None, 'wait') self.start_mytimer()
class MainApp(App): def __init__(self, **kwargs): super(MainApp, self).__init__(**kwargs) self.ioc_root = None self.my_action_bar = None self.my_scroll_panel = None self.my_view = None self.ioc_devices = {} self.ioc_selected_device = None self.ioc_selected_page = 'signals' def connect(self, source_object, *args): if self.ioc_root != None: self.disconnect() ioc_user = args[0] ioc_password = args[1] self.ioc_params = args[2] transport_flag = self.ioc_params['transport'].lower() if transport_flag == 'serial': parameters = self.ioc_params['serport'] else: parameters = self.ioc_params['ip'] if self.ioc_params['role'] == "CLIENT": if transport_flag == 'tls': self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet', security='certchainfile=' + self.ioc_params['cert_chain']) self.ioc_root.queue_events() self.ioc_connection = Connection(self.ioc_root, parameters=parameters, flags=transport_flag + ',down,dynamic,bidirectional', user=ioc_user, password=ioc_password) else: self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet') self.ioc_root.queue_events() self.ioc_connection = Connection(self.ioc_root, parameters=parameters, flags=transport_flag + ',down,dynamic,bidirectional', user=ioc_user) else: if transport_flag == 'tls': self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet', security='certfile=' + self.ioc_params['serv_cert'] + ',keyfile=' + self.ioc_params['serv_key']) self.ioc_root.queue_events() self.ioc_epoint = EndPoint(self.ioc_root, flags=transport_flag + ',dynamic') else: self.ioc_root = Root('ispy', device_nr=9000, network_name='cafenet') self.ioc_root.queue_events() if transport_flag == 'serial': self.ioc_epoint = EndPoint(self.ioc_root, parameters=parameters, flags=transport_flag + ',dynamic') else: self.ioc_epoint = EndPoint(self.ioc_root, flags=transport_flag + ',dynamic') self.set_displayed_page(None, 'wait') self.start_mytimer() def disconnect(self): if self.ioc_root != None: self.stop_mytimer() for device_path in self.ioc_devices: self.my_action_bar.remove_my_device(device_path) self.ioc_devices = {} self.set_displayed_page(None, None) self.ioc_root.delete() self.ioc_root = None def check_iocom_events(self): e = self.ioc_root.wait_com_event(0) if e != None: print(e) event = e[0] # mblk_name = e[3] device_name = e[2] network_name = e[1] device_path = device_name + '.' + network_name # Device connected if event == 'new_device': a = self.ioc_devices.get(device_path, None) if a == None: print("new device " + device_path) d = IoDevice() self.ioc_devices[device_path] = d d.set_device(self.ioc_root, self.ioc_params, device_path) self.set_displayed_page(self.ioc_selected_device, None) self.my_action_bar.add_my_device(device_path) # Device disconnected if event == 'device_disconnected': a = self.ioc_devices.get(device_path, None) if a != None: del self.ioc_devices[device_path] self.my_action_bar.remove_my_device(device_path) self.set_displayed_page(None, None) def mytimer_tick(self, interval): self.ioc_root.receive("*") self.check_iocom_events() for d in self.ioc_devices: self.ioc_devices[d].run() if self.my_view: self.my_view.run() self.ioc_root.send("*") def start_mytimer(self): Clock.schedule_interval(self.mytimer_tick, 1.0 / 30) def stop_mytimer(self): Clock.unschedule(self.mytimer_tick) # kivy gui build def build(self): self.title = 'i-spy' self.root = BoxLayout(orientation='vertical') self.my_widget_home = self.root action_bar = MyActionBar() action_bar.bind(on_button_press=self.button_press) self.my_action_bar = action_bar self.my_widget_home.add_widget(action_bar) self.set_displayed_page(None, 'connect') return self.root def set_displayed_page(self, device_path, page_name): if len(self.ioc_devices) == 0: if self.ioc_root == None: page_name = 'connect' else: page_name = 'wait' self.ioc_selected_device = None if page_name == None: page_name = self.ioc_selected_page if self.ioc_selected_device != None: if self.ioc_selected_device not in self.ioc_devices: self.ioc_selected_device = None if self.ioc_selected_device == device_path and device_path != None and self.ioc_selected_page == page_name: return if self.my_scroll_panel != None: self.my_widget_home.remove_widget(self.my_scroll_panel) self.my_scroll_panel = None if self.my_view != None: self.my_view.delete() self.my_view = None if self.my_view != None: self.my_widget_home.remove_widget(self.my_view) self.my_view.delete() self.my_view = None if page_name == 'connect': connect_dlg = MyConnectDialog() connect_dlg.bind(on_connect=self.connect) self.my_view = connect_dlg self.root.add_widget(connect_dlg) return my_scroll_view = ScrollView() self.my_widget_home.add_widget(my_scroll_view) self.my_scroll_panel = my_scroll_view if page_name == 'wait': dlg = WaitPanel() self.my_view = dlg my_scroll_view.add_widget(dlg) return if device_path != None: if device_path not in self.ioc_devices: device_path = None if device_path == None: device_path = next(iter(self.ioc_devices)) d = self.ioc_devices[device_path] if page_name == 'signals' or page_name == None: page_name = 'signals' dlg = d.create_signal_display() elif page_name == 'configure': dlg = ConfigurationPanel() dlg.set_device(self.ioc_root, device_path) elif page_name == 'program': dlg = ProgramPanel() dlg.set_device(self.ioc_root, device_path) elif page_name == 'memory': dlg = MemoryBlockPanel() dlg.add_mblk_to_page(self.ioc_root, device_path) else: dlg = None print("Unknown page name " + page_name) self.ioc_selected_device = device_path self.ioc_selected_page = page_name if dlg != None: self.my_view = dlg my_scroll_view.add_widget(dlg) # kivy gui action bar button handling def button_press(self, source_object, *args): button_text = args[0] if button_text == 'close': self.disconnect() self.stop() if button_text == 'disconnect': self.disconnect() self.set_displayed_page(None, 'connect') elif button_text == 'signals' or button_text == 'memory' or button_text == 'configure' or button_text == 'program': self.set_displayed_page(self.ioc_selected_device, button_text) elif button_text in self.ioc_devices: self.set_displayed_page(button_text, None)
def build(self): self.root = ProgramPanel() self.root.set_device(Root('testwidget'), "gina2.cafenet") return self.root
import pyglet, random, math, time from pyglet.window import key from game import physicalobject, resources from iocompython import Root, MemoryBlock, Connection, Signal, json2bin my_player_nr = 9000 # 9000 = select device number automatically data_vector_n = 0 with open('resources/asteroid-signals.json', 'r') as file: signal_conf = file.read() root = Root('spacepilot', device_nr=my_player_nr, network_name='cafenet', security='certchainfile=myhome-bundle.crt') exp = MemoryBlock(root, 'up', 'exp') imp = MemoryBlock(root, 'down', 'imp') data = json2bin(signal_conf) info = MemoryBlock(root, 'up', 'info', nbytes=len(data)) info.publish(data) # connection = Connection(root, "192.168.1.220", "tls,up") connection = Connection(root, "127.0.0.1", "tls,up") # connection = Connection(root, "3.135.236.95", "tls,up") # Setup Python access to exported IO signals. These pass user keyboard control to the asteroid service. exp_force_x = Signal(root, "force_x") exp_force_y = Signal(root, "force_y") exp_rotation = Signal(root, "rotation") exp_engine_visible = Signal(root, "engine_visible") exp_shoot = Signal(root, "shoot")
def main(): global root, callback_queue root = Root('asteroid', security='certfile=myhome.crt,keyfile=secret/myhome.key') root.queue_events() ioterminal.start(root) epoint = EndPoint(root, flags='tls,dynamic') random.seed(time.time()) while (ioterminal.run(root)): e = root.wait_com_event(100) root.receive('*') root.send('*') if e != None: print(e) event = e[0] mblk_name = e[3] device_name = e[2] network_name = e[1] # New network, means a new game board if event == 'new_network': running_apps[network_name] = asteroidapp.start( root, network_name) # Close the game board if event == 'network_disconnected': a = running_apps.get(network_name, None) if a != None: a[1].put('exit ' + network_name) del running_apps[network_name] # Switch 'imp' and 'exp' memory blocks to manual synchronization if event == 'new_mblk': mblk_path = mblk_name + '.' + device_name + '.' + network_name # New player if event == 'new_device': a = running_apps.get(network_name, None) if a != None: a[1].put('new_player ' + device_name) # Player dropped off if event == 'device_disconnected': a = running_apps.get(network_name, None) if a != None: a[1].put('drop_player ' + device_name) root.delete()