def _connect_to_otii(self):
        connection = otii_connection.OtiiConnection(self.hostname, self.port)
        connect_response = connection.connect_to_server()
        if connect_response["type"] == "error":
            print("Exit! Error code: " + connect_response["errorcode"] +
                  ", Description: " + connect_response["payload"]["message"])
            sys.exit()
        otii = otii_application.Otii(connection)

        return otii
Esempio n. 2
0
def _connect(job):
    try:
        connection = otii_connection.OtiiConnection(cfg.HOST["IP"],
                                                    cfg.HOST["PORT"])
        connect_response = connection.connect_to_server()
        if connect_response["type"] == "error":
            _append_string(
                job, "Exit! Error code: " + connect_response["errorcode"] +
                ", Description: " + connect_response["data"]["message"])
            sys.exit()
        try:
            return otii.Otii(connection)
        except otii_exception.Otii_Exception as e:
            _append_string(job, "Error connecting to Otii TCP server")
    except ConnectionRefusedError as e:
        _append_string(job, 'Otii ConnectionRefusedError')
def connect():
    connection = otii_connection.OtiiConnection(cfg.HOST["IP"], cfg.HOST["PORT"])
    connect_response = connection.connect_to_server()
    if connect_response["type"] == "error":
        print("Exit! Error code: " + connect_response["errorcode"] + ", Description: " + connect_response["data"]["message"])
        sys.exit()

    try:
        otii_object = otii.Otii(connection)
        devices = otii_object.get_devices()
        if len(devices) == 0:
            print("No Arc connected!")
            sys.exit()
        project = otii_object.get_active_project()
        if project == None:
            print("No active project")
            sys.exit()
    except otii_exception.Otii_Exception as e:
        print("Error message: " + e.message)

    return otii_object, project
"""
# Channel to get data from (name according to above list)
channel = "mc"
# Index of first value to fetch
index = 2
# No. values to fetch
count = 2

connection = otii_connection.OtiiConnection(cfg.HOST["IP"], cfg.HOST["PORT"])
connect_response = connection.connect_to_server()
if connect_response["type"] == "error":
    print("Exit! Error code: " + connect_response["errorcode"] +
          ", Description: " + connect_response["data"]["message"])
    sys.exit()
try:
    otii_object = otii.Otii(connection)
    devices = otii_object.get_devices()
    if len(devices) == 0:
        print("No Arc connected!")
        sys.exit()
    my_arc = devices[0]
    proj = otii_object.get_active_project()
    recording = proj.get_last_recording()
    if recording:
        get_channel_data_count(recording, my_arc.id, channel)
        get_channel_data(recording, my_arc.id, channel, index, count)
    else:
        print("No recording in project")
except otii_exception.Otii_Exception as e:
    print("Error message: " + e.message)