示例#1
0
 def _init_graph(self):
     data = np.random.normal(0, 20, 100)
     bins = np.arange(-100, 100, 5)
     hist, hist_edges = np.histogram(data, bins)
     p_data = []
     s_data = []
     for x in range(-50, 50, 1):
         y = 0.03 * x ** 2 + 2
         p_data.append(y)
         s_data.append(100 - y)
     self.page_graph = dashio.Page("graph_pg", "Graph")
     self.graph = dashio.Graph("graph1",
                               "Graph",
                               control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 1.0))
     self.graph.x_axis_label = "X Axis"
     self.graph.y_axis_label = "Y Axis"
     self.graph.x_axis_min = min(data) - 5
     self.graph.x_axis_max = max(data) + 5
     self.graph.x_axis_labels_style = dashio.GraphXAxisLabelsStyle.ON
     self.page_graph.add_control(self.graph)
     self.device.add_control(self.page_graph)
     self.device.add_control(self.graph)
     self.gl_line = GraphLine("graph_line", dashio.GraphLineType.LINE, color=dashio.Color.BLUE)
     data += 50
     self.gl_line.data = data.tolist()
     self.graph.add_line("graph_line", self.gl_line)
     self.gl_bar = GraphLine("graph_bar", dashio.GraphLineType.BAR, color=dashio.Color.GREEN)
     self.gl_bar.data = hist.tolist()
     self.graph.add_line("graph_bar", self.gl_bar)
     self.gl_segbar = GraphLine("graph_seg_bar", dashio.GraphLineType.SEGBAR, color=dashio.Color.YELLOW)
     self.gl_segbar.data = p_data
     self.graph.add_line("graph_segbar", self.gl_segbar)
     self.gl_peakbar = GraphLine("graph_peakbar", dashio.GraphLineType.PEAKBAR, color=dashio.Color.RED)
     self.gl_peakbar.data = s_data
     self.graph.add_line("graph_parkbar", self.gl_peakbar)
示例#2
0
 def _init_event_log(self):
     self.page_el = dashio.Page("EventLog", "Event Log")
     self.event_log = dashio.EventLog("eventlog",
                                      "Event Log",
                                      control_position=dashio.ControlPosition(0.0, 0.1, 1.0, 0.2))
     self.page_el.add_control(self.event_log)
     self.device.add_control(self.page_el)
     self.device.add_control(self.event_log)
示例#3
0
    def _init_selector(self):
        self.page_sel_slid = dashio.Page("slctr_pg", "Selector & Sliders")
        self.device.add_control(self.page_sel_slid)
        self.slctr1 = dashio.Selector("slctr1",
                                      "Selector",
                                      control_position=dashio.ControlPosition(0.0, 0.8, 1.0, 0.2))
        self.device.add_control(self.slctr1)
        self.slctr1.add_selection("Selection 1")
        self.slctr1.add_selection("Selection 2")
        self.slctr1.add_selection("Selection 3")
        self.slctr1.add_selection("Selection 4")
        self.slctr1.add_selection("Selection 5")
        self.slctr1.add_selection("Selection 6")
        self.sldr_single_solid = dashio.SliderSingleBar("sldr_single_solid",
                                                        "Single Slider Solid",
                                                        bar_style=dashio.SliderBarType.SOLID,
                                                        control_position=dashio.ControlPosition(0.0, 0.0, 0.25, 0.8))
        self.sldr_single_solid.message_rx_event += self.slider_1_event_handler
        self.sldr_single_segmnt = dashio.SliderSingleBar("sldr_single_segment",
                                                         "Single Slider Segmented",
                                                         bar_style=dashio.SliderBarType.SEGMENTED,
                                                         control_position=dashio.ControlPosition(0.25, 0.0, 0.25, 0.8))
        self.sldr_single_segmnt.message_rx_event += self.slider_2_event_handler
        
        self.sldr_dble_solid = dashio.SliderDoubleBar("sldr_double_solid",
                                                        "Double Slider Solid",
                                                        bar_style=dashio.SliderBarType.SOLID,
                                                        control_position=dashio.ControlPosition(0.5, 0.0, 0.25, 0.8))
        self.sldr_dble_solid.message_rx_event += self.slider_3_event_handler
        self.sldr_dble_segmnt = dashio.SliderDoubleBar("sldr_double_segment",
                                                         "Double Slider Segmented",
                                                         bar_style=dashio.SliderBarType.SEGMENTED,
                                                         control_position=dashio.ControlPosition(0.75, 0.0, 0.25, 0.8))
        self.sldr_dble_segmnt.message_rx_event += self.slider_4_event_handler
        self.page_sel_slid.add_control(self.slctr1)
        self.page_sel_slid.add_control(self.sldr_single_solid)
        self.page_sel_slid.add_control(self.sldr_single_segmnt)
        self.page_sel_slid.add_control(self.sldr_dble_solid)
        self.page_sel_slid.add_control(self.sldr_dble_segmnt)


        self.device.add_control(self.sldr_single_solid)
        self.device.add_control(self.sldr_single_segmnt)
        self.device.add_control(self.sldr_dble_solid)
        self.device.add_control(self.sldr_dble_segmnt)
示例#4
0
 def _init_dials(self):
     self.page_dials = dashio.Page("TestDials", "Dials")
     self.compass = dashio.Compass("TestCompass",
                                   "Direction",
                                   control_position=dashio.ControlPosition(0.24, 0.1, 0.54, 0.25))
     self.dial_std = dashio.Dial("DialSTD", "Dial Standard",
                                 style=dashio.DialStyle.STD,
                                 control_position=dashio.ControlPosition(0.24, 0.36, 0.54, 0.26))
     self.dial_inv = dashio.Dial("Dial",
                                 "Dial Inverted",
                                 style=dashio.DialStyle.INVERTED,
                                 control_position=dashio.ControlPosition(0.24, 0.61, 0.54, 0.26))
     self.page_dials.add_control(self.compass)
     self.page_dials.add_control(self.dial_std)
     self.page_dials.add_control(self.dial_inv)
     self.device.add_control(self.page_dials)
     self.device.add_control(self.compass)
     self.device.add_control(self.dial_std)
     self.device.add_control(self.dial_inv)
示例#5
0
 def _init_buttons(self):
     self.page_btns = dashio.Page("TestButtons", "Buttons")
     self.btn1 = dashio.Button("BTN1",
                               "Up",
                               icon_name=Icon.UP,
                               control_position=dashio.ControlPosition(0.24, 0.14, 0.54, 0.26))
     self.btn1.btn_state = ButtonState.ON
     self.btn1.message_rx_event += self.up_btn_event_handler
     self.btn2 = dashio.Button("BTN2",
                               "Down",
                               icon_name=Icon.DOWN,
                               control_position=dashio.ControlPosition(0.24, 0.44, 0.54, 0.26))
     self.btn2.btn_state = ButtonState.ON
     self.btn2.message_rx_event += self.down_btn_event_handler
     self.page_btns.add_control(self.btn1)
     self.page_btns.add_control(self.btn2)
     self.device.add_control(self.page_btns)
     self.device.add_control(self.btn1)
     self.device.add_control(self.btn2)
示例#6
0
 def _init_map(self):
     self.page_map = dashio.Page("map_pg", "Map")
     self.device.add_control(self.page_map)
     self.map = dashio.Map("map",
                           "Map",
                           control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 1.0))
     self.map_loc1 = dashio.SimpleMapLocation("Mt. Cook", -43.59412841615468, 170.14189062192213)
     self.map_loc2 = dashio.MapLocation("James Peak", -45.237101516008835, 168.84818243505748)
     self.map.add_location(self.map_loc1)
     self.map.add_location(self.map_loc2)
     self.page_map.add_control(self.map)
     self.device.add_control(self.map)
示例#7
0
    def _init_menu(self):
        self.page_menu = dashio.Page("menu_pg", "Menus")
        self.device.add_control(self.page_menu)
        self.menu = dashio.Menu("menu", "Menu", control_position=dashio.ControlPosition(0.18, 0.2, 0.7, 0.22))
        self.btn_group = dashio.ButtonGroup("btn_group",
                                            "Button",
                                            control_position=dashio.ControlPosition(0.18, 0.5, 0.7, 0.22))
        self.device.add_control(self.menu)
        self.device.add_control(self.btn_group)
        self.page_menu.add_control(self.menu)
        self.page_menu.add_control(self.btn_group)
        self.btn3 = dashio.Button("btn3", "Menu Button1", icon_name=Icon.LEFT)
        self.btn3.message_rx_event += self.left_btn_event_handler
        self.btn4 = dashio.Button("btn4", "Menu Button2", icon_name=Icon.RIGHT)
        self.btn4.message_rx_event += self.right_btn_event_handler

        self.btn5 = dashio.Button("btn5", "Group Button1", icon_name=Icon.LEFT)
        self.btn5.message_rx_event += self.left_btn_event_handler
        self.btn6 = dashio.Button("btn6", "Group Button2", icon_name=Icon.RIGHT)
        self.btn6.message_rx_event += self.right_btn_event_handler

        self.menu_tb = dashio.TextBox("txt1", "Menu TextBox")
        self.menu_sldr = dashio.SliderSingleBar("mnu_sldr", "Menu Slider")
        self.menu_sldr.max = 20
        self.menu_sldr.min = 0
        self.menu_slctr = dashio.Selector("sltr1", "Menu Selector")
        self.menu.add_control(self.btn3)
        self.menu.add_control(self.btn4)
        self.btn_group.add_button(self.btn5)
        self.btn_group.add_button(self.btn6)
        self.menu.add_control(self.menu_tb)
        self.menu.add_control(self.menu_sldr)
        self.menu.add_control(self.menu_slctr)
        self.device.add_control(self.btn3)
        self.device.add_control(self.btn4)
        self.device.add_control(self.btn5)
        self.device.add_control(self.btn6)
        self.device.add_control(self.menu_tb)
        self.device.add_control(self.menu_sldr)
        self.device.add_control(self.menu_slctr)
示例#8
0
    def _init_labels(self):
        self.page_label = dashio.Page("label_pg", "Labels")
        self.device.add_control(self.page_label)
        self.label_basic = dashio.Label("label_basic",
                                        "Basic",
                                        style=LabelStyle.BASIC,
                                        control_position=dashio.ControlPosition(0.18, 0.05, 0.7, 0.22))
        self.page_label.add_control(self.label_basic)
        self.device.add_control(self.label_basic)

        self.label_border = dashio.Label("label_border",
                                         "Border",
                                         style=LabelStyle.BORDER,
                                         control_position=dashio.ControlPosition(0.18, 0.31, 0.7, 0.3))
        self.page_label.add_control(self.label_border)
        self.device.add_control(self.label_border)

        self.label_group = dashio.Label("label_group",
                                        "Group",
                                        style=LabelStyle.GROUP,
                                        control_position=dashio.ControlPosition(0.18, 0.65, 0.7, 0.3))
        self.page_label.add_control(self.label_group)
        self.device.add_control(self.label_group)
示例#9
0
    def _init_knobs(self):
        self.page_knobs = dashio.Page("Testknobs", "Knobs")
        self.knb_normal = dashio.Knob("KNB_NORMAL",
                                      knob_style=dashio.KnobStyle.NORMAL,
                                      control_position=dashio.ControlPosition(0.24, 0.14, 0.54, 0.26))
        self.knb_normal.message_rx_event += self.knb_normal_event_handler
        self.knb_normal.title = "Knob Normal"
        self.knb_normal.max = 10
        self.knb_normal.red_value = 8
        self.page_knobs.add_control(self.knb_normal)

        self.knb_pan = dashio.Knob("KNB_PAN",
                                   knob_style=dashio.KnobStyle.PAN,
                                   control_position=dashio.ControlPosition(0.24, 0.44, 0.54, 0.26))

        self.knb_pan.message_rx_event += self.knb_pan_event_handler
        self.knb_pan.title = "Knob Pan"
        self.knb_pan.max = 10
        self.knb_pan.red_value = 8
        self.page_knobs.add_control(self.knb_pan)
        self.device.add_control(self.page_knobs)
        self.device.add_control(self.knb_normal)
        self.device.add_control(self.knb_pan)
示例#10
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("   Serving on: ZMQ")
        logging.info("Connection ID: %s", args.connection)
        logging.info("    Device ID: %s", args.device_id)
        logging.info("  Device Name: %s", args.device_name)

        self.device = dashio.dashDevice(args.connection, args.device_id,
                                        args.device_name)
        time.sleep(1)
        self.zmq_con = dashio.zmqConnection(pub_port=args.pub_port,
                                            sub_port=args.sub_port)
        time.sleep(1)
        self.zmq_con.add_device(self.device)

        self.connection = args.connection
        self.page_name = "TestZMQ: " + platform.node()

        self.page_test = dashio.Page("TestZMQ", self.page_name, 1)
        self.up_btn = dashio.Button("UP_BTN",
                                    control_position=dashio.ControlPosition(
                                        0.02, 0.01, 0.22, 0.12))
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = ""
        self.up_btn.text_color = dashio.Color.WHITE
        self.up_btn.title = "Up"
        self.up_btn.message_rx_event += self.up_btn_event_handler
        self.page_test.add_control(self.up_btn)

        self.down_btn = dashio.Button("DOWN_BTN",
                                      control_position=dashio.ControlPosition(
                                          0.02, 0.78, 0.22, 0.12))
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.text_color = dashio.Color.WHITE
        self.down_btn.title = "Down"
        self.down_btn.message_rx_event += self.down_btn_event_handler
        self.page_test.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar(
            "SLDR",
            control_position=dashio.ControlPosition(0.02, 0.13, 0.22, 0.65))
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value
        self.sldr_cntrl.message_rx_event += self.slider_event_handler
        self.page_test.add_control(self.sldr_cntrl)

        self.sldr_dbl_cntrl = dashio.SliderDoubleBar(
            "SLDR_DBL",
            control_position=dashio.ControlPosition(0.78, 0.01, 0.2, 0.89))
        self.sldr_dbl_cntrl.title = "Slider Double"
        self.sldr_dbl_cntrl.max = 5
        self.sldr_dbl_cntrl.slider_enabled = True
        self.sldr_dbl_cntrl.red_value
        self.sldr_dbl_cntrl.message_rx_event += self.slider_dbl_event_handler
        self.page_test.add_control(self.sldr_dbl_cntrl)

        self.knb_control = dashio.Knob("KNB",
                                       control_position=dashio.ControlPosition(
                                           0.24, 0.14, 0.54, 0.21))
        self.knb_control.title = "A Knob"
        self.knb_control.max = 10
        self.knb_control.red_value = 10
        self.knb_control.message_rx_event += self.knob_event_handler
        self.page_test.add_control(self.knb_control)

        self.dl_control = dashio.Dial("DIAL1",
                                      control_position=dashio.ControlPosition(
                                          0.24, 0.57, 0.54, 0.21))
        self.dl_control.title = "A Dial"
        self.dl_control.max = 10
        self.page_test.add_control(self.dl_control)

        self.text_cntrl = dashio.TextBox(
            "TXT1",
            control_position=dashio.ControlPosition(0.24, 0.78, 0.54, 0.12))
        self.text_cntrl.text = "Hello"
        self.text_cntrl.title = "A text control"
        self.text_cntrl.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl.close_key_board_on_send = True
        self.text_cntrl.message_rx_event += self.text_cntrl_message_handler
        self.page_test.add_control(self.text_cntrl)

        self.alarm_ctrl = dashio.Alarm("TestingAlarms", "Test Alarms", "Hello",
                                       "Test of Shared Alarms")
        self.device.add_control(self.alarm_ctrl)
        self.comp_control = dashio.Compass(
            "COMP1",
            control_position=dashio.ControlPosition(0.24, 0.35, 0.54, 0.22))
        self.comp_control.title = "A compass"
        self.page_test.add_control(self.comp_control)

        self.selector_ctrl = dashio.Selector(
            "TestSelector",
            "A Selector",
            control_position=dashio.ControlPosition(0.24, 0.01, 0.54, 0.13))
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")

        self.page_test.add_control(self.selector_ctrl)

        self.label_ctrl = dashio.Label(
            "LabelID",
            "A label",
            style=dashio.LabelStyle.GROUP,
            color=dashio.Color.BLUE,
            control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 0.93),
        )
        self.page_test.add_control(self.label_ctrl)

        self.device.add_control(self.label_ctrl)
        self.device.add_control(self.page_test)
        self.device.add_control(self.selector_ctrl)
        self.device.add_control(self.comp_control)
        self.device.add_control(self.text_cntrl)
        self.device.add_control(self.dl_control)
        self.device.add_control(self.knb_control)
        self.device.add_control(self.sldr_dbl_cntrl)
        self.device.add_control(self.sldr_cntrl)
        self.device.add_control(self.down_btn)
        self.device.add_control(self.up_btn)

        while not self.shutdown:
            time.sleep(5)
            self.comp_control.direction_value = random.random() * 360

        self.device.send_popup_message("TestControls", "Shutting down",
                                       "Goodbye")
        time.sleep(1)
        self.device.close()
        self.zmq_con.close()
示例#11
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("   Serving on: %s:%s", args.url, str(args.port))
        logging.info("    Device ID: %s", args.device_id)
        logging.info("  Device Name: %s", args.device_name)
        self.tcp_con = dashio.TCPConnection()
        self.device = dashio.Device("ControlTest", args.device_id, args.device_name)
        self.tcp_con.add_device(self.device)

        self.page_name = "TestTCP: " + platform.node()

        self.page_test = dashio.DeviceView("TestTCP", self.page_name)
        self.up_btn = dashio.Button("UP_BTN", control_position=dashio.ControlPosition(0.02, 0.01, 0.22, 0.12))
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = ""
        self.up_btn.title = "Up"
        self.up_btn.message_rx_event = self.up_btn_event_handler
        self.page_test.add_control(self.up_btn)

        self.down_btn = dashio.Button(
            "DOWN_BTN", control_position=dashio.ControlPosition(0.02, 0.86, 0.22, 0.12)
        )
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.title = "Down"
        self.down_btn.message_rx_event = self.down_btn_event_handler
        self.page_test.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar(
            "SLDR", control_position=dashio.ControlPosition(0.02, 0.13, 0.22, 0.73)
        )
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.bar_max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value = 10
        self.sldr_cntrl.message_rx_event += self.slider_event_handler
        self.page_test.add_control(self.sldr_cntrl)

        self.sldr_dbl_cntrl = dashio.SliderDoubleBar(
            "SLDR_DBL", control_position=dashio.ControlPosition(0.78, 0.01, 0.2, 0.98)
        )
        self.sldr_dbl_cntrl.title = "Slider Double"
        self.sldr_dbl_cntrl.bar_max = 5
        self.sldr_dbl_cntrl.slider_enabled = True
        self.sldr_dbl_cntrl.red_value = 5
        self.sldr_dbl_cntrl.message_rx_event += self.slider_dbl_event_handler
        self.page_test.add_control(self.sldr_dbl_cntrl)

        self.knb_control = dashio.Knob("KNB", control_position=dashio.ControlPosition(0.24, 0.14, 0.54, 0.21))
        self.knb_control.title = "A Knob"
        self.knb_control.dial_max = 10
        self.knb_control.red_value = 10
        self.knb_control.message_rx_event += self.knob_event_handler
        self.page_test.add_control(self.knb_control)

        self.dl_control = dashio.Dial(
            "DIAL1",
            style=DialStyle.BAR,
            units="m/s",
            number_position=DialNumberPosition.CENTER,
            precision=Precision.TWO,
            control_position=dashio.ControlPosition(0.24, 0.63, 0.54, 0.21)
        )
        self.dl_control.title = "A Dial"
        self.dl_control.dial_max = 10
        self.page_test.add_control(self.dl_control)

        self.text_cntrl = dashio.TextBox(
            "TXT1", control_position=dashio.ControlPosition(0.24, 0.84, 0.54, 0.12)
        )
        self.text_cntrl.text = "Hello"
        self.text_cntrl.title = "A text control"
        self.text_cntrl.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl.close_keyboard_on_send = True
        self.text_cntrl.message_rx_event += self.text_cntrl_message_handler
        self.page_test.add_control(self.text_cntrl)

        self.alarm_ctrl = dashio.Alarm("TestingAlarms", "Test Alarms")
        self.device.add_control(self.alarm_ctrl)
        self.comp_control = dashio.Direction(
            "COMP1",
            style=DirectionStyle.DEGPS,
            units="nm",
            precision=Precision.TWO,
            control_position=dashio.ControlPosition(0.24, 0.38, 0.54, 0.22)
        )
        self.comp_control.title = "A Direction control"
        self.comp_control.direction_text = "00"
        self.page_test.add_control(self.comp_control)

        self.selector_ctrl = dashio.Selector(
            "TestSelector", "A Selector", control_position=dashio.ControlPosition(0.24, 0.01, 0.54, 0.13)
        )
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")

        self.page_test.add_control(self.selector_ctrl)

        self.label_ctrl = dashio.Label(
            "LabelID",
            "A label",
            style=dashio.LabelStyle.GROUP,
            color=dashio.Color.BLUE,
            control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 1.0),
        )
        self.page_test.add_control(self.label_ctrl)

        self.device.add_control(self.label_ctrl)
        self.device.add_control(self.page_test)
        self.device.add_control(self.selector_ctrl)
        self.device.add_control(self.comp_control)
        self.device.add_control(self.text_cntrl)
        self.device.add_control(self.dl_control)
        self.device.add_control(self.knb_control)
        self.device.add_control(self.sldr_dbl_cntrl)
        self.device.add_control(self.sldr_cntrl)
        self.device.add_control(self.down_btn)
        self.device.add_control(self.up_btn)

        while not self.shutdown:
            time.sleep(5)
            self.comp_control.direction_value = random.random() * 360

        self.device.send_popup_message("TestControls", "Shutting down", "Goodbye")
        self.tcp_con.close()
        self.device.close()
示例#12
0
def main():
    # Catch CNTRL-C signel
    global shutdown
    signal.signal(signal.SIGINT, signal_cntrl_c)

    no_datapoints = 60

    args = parse_commandline_arguments()
    init_logging(args.logfilename, args.verbose)
    
    
    new_ini_file = False
    ini_file = args.ini_file
    config_file_parser = configparser.ConfigParser()
    config_file_parser.defaults()

    try:
        ini_f = open(ini_file)
        ini_f.close()
    except FileNotFoundError:
        default = {
            'DeviceID': shortuuid.uuid(),
            'DeviceName': args.device_name,
            'DeviceType': 'ServerMonitor',
            'username': args.username,
            'password': args.password
        }
        config_file_parser['DEFAULT'] = default
        with open(ini_file, 'w') as configfile:
            config_file_parser.write(configfile)
        new_ini_file = True

    if not new_ini_file:
        config_file_parser.read(ini_file)
    config_file_parser.get('DEFAULT', 'username')
    device = dashio.Device(
        config_file_parser.get('DEFAULT', 'DeviceType'),
        config_file_parser.get('DEFAULT', 'DeviceID'),
        config_file_parser.get('DEFAULT', 'DeviceName')
    )
    dash_conn = dashio.DashConnection(
        config_file_parser.get('DEFAULT', 'username'),
        config_file_parser.get('DEFAULT', 'password')
    )
    dash_conn.add_device(device)

    device.dashio_setable = False
    dash_conn.add_device(device)

    monitor_page = dashio.DeviceView("monpg", "Dash Server Monitor")
    gph_network = dashio.TimeGraph("NETWORKGRAPH", control_position=dashio.ControlPosition(0.0, 0.0, 1.0, 0.45))
    gph_network.title = "Server Network Traffic: {}".format(args.device_name)
    gph_network.y_axis_label = "Kbytes"
    gph_network.y_axis_min = 0.0
    gph_network.y_axis_max = 100000.0
    gph_network.y_axis_num_bars = 9
    network_rx = dashio.TimeGraphLine(
        "RX", dashio.TimeGraphLineType.LINE, color=dashio.Color.FUSCIA, max_data_points=no_datapoints, break_data=True
    )
    network_tx = dashio.TimeGraphLine(
        "TX", dashio.TimeGraphLineType.LINE, color=dashio.Color.AQUA, max_data_points=no_datapoints, break_data=True
    )

    gph_network.add_line("NET_RX", network_rx)
    gph_network.add_line("NET_TX", network_tx)
    last_tx, last_rx = get_network_rx_tx()

    gph_cpu = dashio.TimeGraph("CPULOAD", control_position=dashio.ControlPosition(0.0, 0.45, 1.0, 0.45))
    gph_cpu.title = "CPU load: {}".format(args.device_name)
    gph_cpu.y_axis_label = "Percent"
    gph_cpu.y_axis_max = 100
    gph_cpu.y_axis_min = 0
    gph_cpu.y_axis_num_bars = 9
    monitor_page.add_control(gph_network)
    monitor_page.add_control(gph_cpu)
    device.add_control(gph_network)
    device.add_control(gph_cpu)
    number_of_cores = psutil.cpu_count()

    cpu_core_line_array = []
    cpu_data = psutil.cpu_percent(percpu=True)
    for cpu in range(0, number_of_cores):
        line = dashio.TimeGraphLine(
            name="CPU:{}".format(cpu),
            line_type=dashio.TimeGraphLineType.LINE,
            color=dashio.Color(cpu + 1),
            max_data_points=no_datapoints,
            break_data=True
        )
        cpu_core_line_array.append(line)
        gph_cpu.add_line("CPU:{}".format(cpu), line)

    hd_dial = dashio.Dial("HD_USAGE", control_position=dashio.ControlPosition(0.0, 0.9, 1.0, 0.1))
    hd_dial.title = "Disk Usage"
    hd_dial.dial_value = psutil.disk_usage("/").percent
    hd_dial.dial_min = 0.0
    hd_dial.dial_max = 100.0
    hd_dial.red_value = 95.0
    hd_dial.show_min_max = True
    disk_usage = 0
    device.add_control(hd_dial)
    monitor_page.add_control(hd_dial)
    device.add_control(monitor_page)
    while not shutdown:
        time.sleep(10)

        Tx, Rx = get_network_rx_tx()

        network_rx.add_data_point(Tx - last_tx)
        network_tx.add_data_point(Rx - last_rx)

        last_tx = Tx
        last_rx = Rx

        gph_network.send_data()

        cpu_data = psutil.cpu_percent(percpu=True)

        i = 0
        for line in cpu_core_line_array:
            line.add_data_point(cpu_data[i])
            i += 1
        gph_cpu.send_data()
        du = psutil.disk_usage("/").percent
        if du != disk_usage:
            disk_usage = du
            # Only send if changed.
            hd_dial.dial_value = disk_usage

    device.close()
示例#13
0
    def __init__(self):

        # Catch CNTRL-C signel
        signal.signal(signal.SIGINT, self.signal_cntrl_c)
        self.shutdown = False
        args = self.parse_commandline_arguments()
        self.init_logging(args.logfilename, args.verbose)

        logging.info("Connecting to server: %s", args.server)
        logging.info("       Connection ID: %s", args.connection)
        logging.info("       Control topic: %s/%s/%s/control", args.username,
                     args.connection, args.device_id)
        logging.info("          Data topic: %s/%s/%s/data", args.username,
                     args.connection, args.device_id)

        device = dashio.dashDevice(args.connection, args.device_id,
                                   args.device_name)
        dash_conn = dashio.dashConnection(args.username, args.password)
        dash_conn.add_device(device)

        self.tmpage = dashio.Page("tmpage", "Test Alarm")
        self.test_menu = dashio.Menu("TestTheMenu",
                                     control_position=dashio.ControlPosition(
                                         0.3, 0.5, 0.5, 0.5))
        self.test_page = dashio.Page("TestCFG", "Test the Menus")
        device.add_control(self.test_page)

        self.up_btn = dashio.Button("UP_BTN")
        self.up_btn.btn_state = dashio.ButtonState.OFF
        self.up_btn.icon_name = dashio.Icon.UP
        self.up_btn.on_color = dashio.Color.GREEN
        self.up_btn.text = "Up Button"
        self.up_btn.text_color = dashio.Color.WHITE
        self.up_btn.title = "Up"
        device.add_control(self.up_btn)
        self.test_menu.add_control(self.up_btn)

        self.down_btn = dashio.Button("DOWN_BTN")
        self.down_btn.btn_state = dashio.ButtonState.OFF
        self.down_btn.icon_name = dashio.Icon.DOWN
        self.down_btn.on_color = dashio.Color.GREEN
        self.down_btn.text = ""
        self.down_btn.text_color = dashio.Color.WHITE
        self.down_btn.title = "Down"
        device.add_control(self.down_btn)
        self.test_menu.add_control(self.down_btn)

        self.sldr_cntrl = dashio.SliderSingleBar("SLDR")
        self.sldr_cntrl.title = "Slider"
        self.sldr_cntrl.max = 10
        self.sldr_cntrl.slider_enabled = True
        self.sldr_cntrl.red_value
        device.add_control(self.sldr_cntrl)
        self.test_menu.add_control(self.sldr_cntrl)

        self.text_cntrl1 = dashio.TextBox("TXT1")
        self.text_cntrl1.text = "Test box1"
        self.text_cntrl1.title = "TextBx1"
        self.text_cntrl1.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl1.close_key_board_on_send = True
        device.add_control(self.text_cntrl1)
        self.test_menu.add_control(self.text_cntrl1)

        self.text_cntrl2 = dashio.TextBox("TXT2")
        self.text_cntrl2.text = "Test box2"
        self.text_cntrl2.title = "TextBx2"
        self.text_cntrl2.keyboard_type = dashio.Keyboard.ALL_CHARS
        self.text_cntrl2.close_key_board_on_send = True
        device.add_control(self.text_cntrl2)
        self.test_menu.add_control(self.text_cntrl2)

        self.selector_ctrl = dashio.Selector("TestSelector", "A Selector")
        self.selector_ctrl.message_rx_event += self.selector_ctrl_handler
        self.selector_ctrl.add_selection("First")
        self.selector_ctrl.add_selection("Second")
        self.selector_ctrl.add_selection("Third")
        self.selector_ctrl.add_selection("Forth")
        self.selector_ctrl.add_selection("Fifth")
        device.add_control(self.selector_ctrl)
        self.test_menu.add_control(self.selector_ctrl)
        self.test_page.add_control(self.test_menu)
        self.button_group_test = dashio.ButtonGroup("TestButtonGRP",
                                                    "A group of buttons")
        self.test_page.add_control(self.button_group_test)
        self.button_group_test.add_button(self.up_btn)
        self.button_group_test.add_button(self.down_btn)
        device.add_control(self.test_menu)
        device.add_control(self.button_group_test)

        while not self.shutdown:
            time.sleep(5)

        device.close()
示例#14
0
def main():
    def up_btn_event_handler(msg):
        global COUNTER
        COUNTER += 1
        txt_box.text = f"{COUNTER}"

    def down_btn_event_handler(msg):
        global COUNTER
        COUNTER -= 1
        txt_box.text = f"{COUNTER}"

    signal.signal(signal.SIGINT, signal_cntrl_c)
    args = parse_commandline_arguments()
    init_logging(args.logfilename, args.verbose)

    new_ini_file = False
    ini_file = "dash_test.ini"
    config_file_parser = configparser.ConfigParser()
    config_file_parser.defaults()

    try:
        ini_f = open(ini_file)
        ini_f.close()
    except FileNotFoundError:
        default = {
            'DeviceID': shortuuid.uuid(),
            'DeviceName': 'DashIO Test',
            'DeviceType': 'DashIOTests',
            'username': args.username,
            'password': args.password
        }
        config_file_parser['DEFAULT'] = default
        with open(ini_file, 'w') as configfile:
            config_file_parser.write(configfile)
        new_ini_file = True

    if not new_ini_file:
        config_file_parser.read(ini_file)
    config_file_parser.get('DEFAULT', 'username')
    device = dashio.Device(config_file_parser.get('DEFAULT', 'DeviceType'),
                           config_file_parser.get('DEFAULT', 'DeviceID'),
                           config_file_parser.get('DEFAULT', 'DeviceName'))
    dash_conn = dashio.DashConnection(
        config_file_parser.get('DEFAULT', 'username'),
        config_file_parser.get('DEFAULT', 'password'))
    dash_conn.add_device(device)
    dview = dashio.DeviceView('Dashio_pg1', 'DashIO Public Test')

    up_button = dashio.Button('up',
                              'UP',
                              icon_name=dashio.Icon.UP,
                              control_position=dashio.ControlPosition(
                                  0.4, 0.22, 0.2, 0.2))
    up_button.title_position = dashio.TitlePosition.NONE
    up_button.message_rx_event = up_btn_event_handler
    up_button.btn_state = dashio.ButtonState.OFF
    down_button = dashio.Button('down',
                                'DOWN',
                                icon_name=dashio.Icon.DOWN,
                                control_position=dashio.ControlPosition(
                                    0.4, 0.53, 0.2, 0.2))
    down_button.title_position = dashio.TitlePosition.NONE
    down_button.message_rx_event = down_btn_event_handler
    down_button.btn_state = dashio.ButtonState.OFF

    txt_box = dashio.TextBox('txtbox1',
                             'Counter',
                             control_position=dashio.ControlPosition(
                                 0.0, 0.43, 1.0, 0.1))
    txt_box.keyboard_type = dashio.Keyboard.NONE
    txt_box.text_align = dashio.TextAlignment.CENTER
    txt_box.text = f"{COUNTER}"

    dview.add_control(up_button)
    dview.add_control(down_button)
    dview.add_control(txt_box)
    device.add_control(dview)
    device.add_control(up_button)
    device.add_control(down_button)
    device.add_control(txt_box)

    global SHUTDOWN
    while not SHUTDOWN:
        time.sleep(1)

    device.close()