示例#1
0
def download_xst(subband: int,
                 integration_time_s: int,
                 url: str = 'localhost',
                 port: int = 50000):
    """
    Download cross correlation statistics

    Args:
        subband (int): Subband number
        integration_time_s (int): Integration time in seconds
        url (str): URL to connect to, defaults to 'localhost'
        port (str): Port to connect to, defaults to 50000

    Returns:
        Tuple[datetime.datetime, np.ndarray, int]: UTC time, visibilities (shape n_ant x n_ant),
                                                   RCU mode

    Raises:
        RuntimeError: if in mixed RCU mode
    """
    client = Client("opc.tcp://{}:{}/".format(url, port), timeout=1000)
    client.connect()
    client.load_type_definitions()
    objects = client.get_objects_node()
    idx = client.get_namespace_index(DEFAULT_URI)
    obj = client.get_root_node().get_child(
        ["0:Objects", "{}:StationMetrics".format(idx), "{}:RCU".format(idx)])

    obstime, visibilities_opc, rcu_modes = obj.call_method(
        "{}:record_cross".format(idx), subband, integration_time_s)

    client.close_session()
    client.close_secure_channel()

    rcu_modes_on = set([mode for mode in rcu_modes if mode != '0'])
    if len(rcu_modes_on) == 1:
        rcu_mode = int(rcu_modes_on.pop())
    elif len(rcu_modes_on) == 0:
        rcu_mode = 0
    else:
        raise RuntimeError(
            "Multiple nonzero RCU modes are used, that's not supported yet")

    assert (len(visibilities_opc) == 2)  # Real and complex part
    visibilities = np.array(visibilities_opc)[0] + 1j * np.array(
        visibilities_opc[1])

    return obstime, visibilities, rcu_mode
from opcua import Client

client = Client('opc.tcp://127.0.0.1:51213')
client.connect()
client.get_namespace_array()
objects_node = client.get_objects_node()
# Print children nodes
print(objects_node.get_children(), flush=True)
# Get directly a specific node
temperature = client.get_node('ns=2;s="temperature"')
# get a node value (if it's a variable)
temperature.get_value()

light_bulb_state = client.get_node('ns=2;s="light_bulb_state"')
# If the variable is writable, its value can be set from the client side
light_bulb_state.set_value(True)

# Close client session (the servere remains connected)
client.close_session()
示例#3
0
        myfloat = client.get_node("ns=4;s=Float")
        mydouble = client.get_node("ns=4;s=Double")
        myint64 = client.get_node("ns=4;s=Int64")
        myuint64 = client.get_node("ns=4;s=UInt64")
        myint32 = client.get_node("ns=4;s=Int32")
        myuint32 = client.get_node("ns=4;s=UInt32")
 
        var = client.get_node(ua.NodeId("Random1", 5))
        print("var is: ", var)
        print("value of var is: ", var.get_value())
        var.set_value(ua.Variant([23], ua.VariantType.Double))
        print("setting float value")
        myfloat.set_value(ua.Variant(1.234, ua.VariantType.Float))
        print("reading float value: ", myfloat.get_value())


        handler = SubHandler()
        sub = client.create_subscription(500, handler)
        sub.subscribe_data_change(var)

        device = objects.get_child(["2:MyObjects", "2:MyDevice"])
        method = device.get_child("2:MyMethod")
        result = device.call_method(method, ua.Variant("sin"), ua.Variant(180, ua.VariantType.Double))
        print("Mehtod result is: ", result)


        embed()
        client.close_session()
    finally:
        client.disconnect()