Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update measurement link examples to match dcpower example changes. #284

Merged
merged 23 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions examples/nidaqmx_analog_input/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import nidaqmx
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _nidaqmx_helpers import create_task
from nidaqmx.grpc_session_options import (
GRPC_SERVICE_INTERFACE_NAME,
GrpcSessionOptions,
Expand Down Expand Up @@ -60,14 +61,14 @@ def create_nidaqmx_tasks(sequence_context: Any) -> None:
timeout=0,
) as reservation:
for session_info in reservation.session_info:
session_kwargs["grpc_options"] = GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidaqmx.GRPC_SERVICE_INTERFACE_NAME
)
subash-suresh marked this conversation as resolved.
Show resolved Hide resolved
subash-suresh marked this conversation as resolved.
Show resolved Hide resolved
task = create_task(
session_info,
grpc_device_channel,
initialization_behavior=nidaqmx.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)

# Leave session open
task = nidaqmx.Task(new_task_name=session_info.session_name, **session_kwargs)
task.ai_channels.add_ai_voltage_chan(session_info.channel_list)

session_management_client.register_sessions(reservation.session_info)
Expand All @@ -88,13 +89,12 @@ def destroy_nidaqmx_tasks() -> None:
session_management_client.unregister_sessions(reservation.session_info)

for session_info in reservation.session_info:
grpc_options = GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidaqmx.GRPC_SERVICE_INTERFACE_NAME
)
subash-suresh marked this conversation as resolved.
Show resolved Hide resolved

task = nidaqmx.Task(
new_task_name=session_info.session_name, grpc_options=grpc_options
task = create_task(
session_info,
grpc_device_channel,
initialization_behavior=nidaqmx.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)
task.close()
41 changes: 13 additions & 28 deletions examples/nidigital_spi/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import nidigital
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _nidigital_helpers import create_session

import ni_measurementlink_service as nims
from ni_measurementlink_service.session_management import (
Expand Down Expand Up @@ -191,45 +192,29 @@ def _reserve_sessions(
)


def _create_nidigital_session(
grpc_channel_pool: GrpcChannelPoolHelper,
session_info: nims.session_management.SessionInformation,
initialization_behavior=nidigital.SessionInitializationBehavior.AUTO,
) -> nidigital.Session:
options: Dict[str, Any] = {}
if USE_SIMULATION:
options["simulate"] = True
options["driver_setup"] = {"Model": "6570"}

grpc_channel = grpc_channel_pool.get_grpc_device_channel(nidigital.GRPC_SERVICE_INTERFACE_NAME)
grpc_options = nidigital.GrpcSessionOptions(
grpc_channel,
session_info.session_name,
initialization_behavior=initialization_behavior,
)

return nidigital.Session(
resource_name=session_info.resource_name, options=options, grpc_options=grpc_options
)


def _create_new_nidigital_session(
grpc_channel_pool: GrpcChannelPoolHelper,
session_info: nims.session_management.SessionInformation,
) -> nidigital.Session:
return _create_nidigital_session(
grpc_channel_pool,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidigital.GRPC_SERVICE_INTERFACE_NAME
)
return create_session(
session_info,
nidigital.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
grpc_device_channel,
initialization_behavior=nidigital.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)


def _attach_nidigital_session(
grpc_channel_pool: GrpcChannelPoolHelper,
session_info: nims.session_management.SessionInformation,
) -> nidigital.Session:
return _create_nidigital_session(
grpc_channel_pool,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidigital.GRPC_SERVICE_INTERFACE_NAME
)
return create_session(
session_info,
nidigital.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
grpc_device_channel,
initialization_behavior=nidigital.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)
35 changes: 13 additions & 22 deletions examples/nidmm_measurement/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import nidmm
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _nidmm_helpers import create_session

import ni_measurementlink_service as nims

Expand Down Expand Up @@ -55,22 +56,13 @@ def create_nidmm_sessions(sequence_context: Any) -> None:
timeout=0,
) as reservation:
for session_info in reservation.session_info:
options: Dict[str, Any] = {}
if USE_SIMULATION:
options["simulate"] = True
options["driver_setup"] = {"Model": "4081"}

grpc_options = nidmm.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(nidmm.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=nidmm.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidmm.GRPC_SERVICE_INTERFACE_NAME
)

# Leave session open
nidmm.Session(
resource_name=session_info.resource_name,
options=options,
grpc_options=grpc_options,
create_session(
session_info,
grpc_device_channel,
subash-suresh marked this conversation as resolved.
Show resolved Hide resolved
initialization_behavior=nidmm.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)

session_management_client.register_sessions(reservation.session_info)
Expand All @@ -91,13 +83,12 @@ def destroy_nidmm_sessions() -> None:
session_management_client.unregister_sessions(reservation.session_info)

for session_info in reservation.session_info:
grpc_options = nidmm.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(nidmm.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=nidmm.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nidmm.GRPC_SERVICE_INTERFACE_NAME
)

session = nidmm.Session(
resource_name=session_info.resource_name, grpc_options=grpc_options
session = create_session(
session_info,
grpc_device_channel,
initialization_behavior=nidmm.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)
session.close()
37 changes: 13 additions & 24 deletions examples/nifgen_standard_function/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import nifgen
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _nifgen_helpers import create_session

import ni_measurementlink_service as nims

Expand Down Expand Up @@ -55,23 +56,13 @@ def create_nifgen_sessions(sequence_context: Any) -> None:
timeout=0,
) as reservation:
for session_info in reservation.session_info:
options: Dict[str, Any] = {}
if USE_SIMULATION:
options["simulate"] = True
options["driver_setup"] = {"Model": "5423 (2CH)"}

grpc_options = nifgen.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(nifgen.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=nifgen.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nifgen.GRPC_SERVICE_INTERFACE_NAME
)

# Leave session open
nifgen.Session(
resource_name=session_info.resource_name,
channel_name=session_info.channel_list,
options=options,
grpc_options=grpc_options,
create_session(
session_info,
grpc_device_channel,
initialization_behavior=nifgen.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)

session_management_client.register_sessions(reservation.session_info)
Expand All @@ -92,15 +83,13 @@ def destroy_nifgen_sessions() -> None:
session_management_client.unregister_sessions(reservation.session_info)

for session_info in reservation.session_info:
grpc_options = nifgen.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(nifgen.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
nifgen.GRPC_SERVICE_INTERFACE_NAME
)
session = create_session(
session_info,
grpc_device_channel,
initialization_behavior=nifgen.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)

session = nifgen.Session(
resource_name=session_info.resource_name,
channel_name=session_info.channel_list,
grpc_options=grpc_options,
)
session.close()
34 changes: 13 additions & 21 deletions examples/niscope_acquire_waveform/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import niscope
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _niscope_helpers import create_session

import ni_measurementlink_service as nims

Expand Down Expand Up @@ -56,22 +57,13 @@ def create_niscope_sessions(sequence_context: Any) -> None:
timeout=0,
) as reservation:
for session_info in reservation.session_info:
options: Dict[str, Any] = {}
if USE_SIMULATION:
options["simulate"] = True
options["driver_setup"] = {"Model": "5162 (4CH)"}

grpc_options = niscope.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(niscope.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
initialization_behavior=niscope.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
niscope.GRPC_SERVICE_INTERFACE_NAME
)

# Leave session open
niscope.Session(
resource_name=session_info.resource_name,
options=options,
grpc_options=grpc_options,
create_session(
session_info,
grpc_device_channel,
initialization_behavior=niscope.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)

session_management_client.register_sessions(reservation.session_info)
Expand All @@ -92,13 +84,13 @@ def destroy_niscope_sessions() -> None:
session_management_client.unregister_sessions(reservation.session_info)

for session_info in reservation.session_info:
grpc_options = niscope.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(niscope.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
niscope.GRPC_SERVICE_INTERFACE_NAME
)
session = create_session(
session_info,
grpc_device_channel,
initialization_behavior=niscope.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)

session = niscope.Session(
resource_name=session_info.resource_name, grpc_options=grpc_options
)
session.close()
32 changes: 13 additions & 19 deletions examples/niswitch_control_relays/teststand_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import niswitch
from _helpers import GrpcChannelPoolHelper, PinMapClient, TestStandSupport
from _niswitch_helpers import create_session

import ni_measurementlink_service as nims

Expand Down Expand Up @@ -56,22 +57,15 @@ def create_niswitch_sessions(sequence_context: Any) -> None:
timeout=0,
) as reservation:
for session_info in reservation.session_info:
resource_name = session_info.resource_name
session_kwargs: Dict[str, Any] = {}
if USE_SIMULATION:
resource_name = ""
session_kwargs["simulate"] = True
session_kwargs["topology"] = "2567/Independent"

session_kwargs["grpc_options"] = niswitch.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(niswitch.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
niswitch.GRPC_SERVICE_INTERFACE_NAME
)
create_session(
session_info,
grpc_device_channel,
initialization_behavior=niswitch.SessionInitializationBehavior.INITIALIZE_SERVER_SESSION,
)

# Leave session open
niswitch.Session(resource_name, **session_kwargs)

session_management_client.register_sessions(reservation.session_info)


Expand All @@ -90,13 +84,13 @@ def destroy_niswitch_sessions() -> None:
session_management_client.unregister_sessions(reservation.session_info)

for session_info in reservation.session_info:
grpc_options = niswitch.GrpcSessionOptions(
grpc_channel_pool.get_grpc_device_channel(niswitch.GRPC_SERVICE_INTERFACE_NAME),
session_name=session_info.session_name,
grpc_device_channel = grpc_channel_pool.get_grpc_device_channel(
niswitch.GRPC_SERVICE_INTERFACE_NAME
)
session = create_session(
session_info,
grpc_device_channel,
initialization_behavior=niswitch.SessionInitializationBehavior.ATTACH_TO_SERVER_SESSION,
)

session = niswitch.Session(
resource_name=session_info.resource_name, grpc_options=grpc_options
)
session.close()