10-16-2023 04:58 AM - edited 10-16-2023 04:59 AM
Dear Community members,
I am able to communicate PXIe-5160 using NISCOPE python module. However, when i am calling the fetch function in a while loop, code is acquiring the same array for every single iteration (Chan1 matrix is same for every iteration). Could anyone please suggest if any modification is needed to the below code ?
Also , could anyone also please suggest to reduce the latency of acquisition in the below code?
import niscope
import time
import datetime
from niscope import enums as session_enums
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage import shift
# Create a session to a PXI Oscilloscope
min_sample_rate1=100e6
pulse_rate=4000
min_num_pts1=int(0.99*min_sample_rate1/pulse_rate)
num_records1=100
fig=plt.figure()
ax=fig.add_subplot(111)
#l1,=ax.plot()
#l2,=ax.plot(np.zeros([min_num_pts1,1]))
with niscope.Session("PXI1Slot8") as session:
# Configure the vertical and horizontal settings
session.channels[0].configure_vertical(range=0.2, coupling=niscope.VerticalCoupling.AC)
session.channels[1].configure_vertical(range=1.0, coupling=niscope.VerticalCoupling.AC)
session.configure_horizontal_timing(min_sample_rate=min_sample_rate1,min_num_pts=min_num_pts1 , ref_position=0.0, num_records=num_records1, enforce_realtime=True)
session.configure_trigger_edge(trigger_source="TRIG", level=0.05, trigger_coupling=session_enums.TriggerCoupling.AC,slope=niscope.TriggerSlope.POSITIVE,holdoff=datetime.timedelta(seconds=0.0),delay=datetime.timedelta(seconds=0.0))
# Configure the trigger to be immediate
#session.configure_trigger_immediate()
# Initiate the acquisition
i=0
l1,=ax.plot(np.zeros([25782,1]))
l1,=ax.plot(np.zeros([25782,1]))
with session.initiate():
# Loop until the user presses Ctrl-C
try:
while True:
# Fetch the waveforms from both channels
#session.configure_trigger_edge(trigger_source="TRIG", level=0.01, trigger_coupling=session_enums.TriggerCoupling.AC,slope=niscope.TriggerSlope.POSITIVE,holdoff=datetime.timedelta(seconds=0.0),delay=datetime.timedelta(seconds=0.0))
timestamp_s = datetime.datetime.now()#.strftime("%Y-%m-%d %H:%M:%S.%f")
waveforms = session.channels[0,1].fetch(num_records=num_records1)
timestamp_f = datetime.datetime.now()#.strftime("%Y-%m-%d %H:%M:%S.%f")
# Print the trigger and waveform timestamps for each waveform
chan1 = [wfm.samples.tolist() for wfm in waveforms if wfm.channel == '0']
#l2.set_ydata(a.PS_cumm.transpose())
#plt.plot(waveforms[1].samples.tolist())
# for wfm in waveforms:
# # Calculate the trigger timestamp by subtracting the relative initial x from the t0
# trigger_timestamp = wfm.absolute_initial_x - wfm.relative_initial_x
# # Print the channel, record, trigger timestamp, and waveform timestamp
# print(f"Channel {wfm.channel}, record {wfm.record}:")
# print(f"Trigger timestamp: {trigger_timestamp}")
# print(f"Waveform timestamp: {wfm.absolute_initial_x}")
# print(f"timediff for 1 record:", timestamp_f-timestamp_s)
# Wait for 1 second before fetching again
i+=1
#time.sleep(1)
print(i)
except KeyboardInterrupt:
# User pressed Ctrl-C, exit the loop
print("Exiting...")