Skip to content

Commit 098536b

Browse files
wrapped in main
1 parent 9df72d6 commit 098536b

2 files changed

Lines changed: 70 additions & 63 deletions

File tree

pica/keithley/k6517b/Pyroelectricity/Instrument_Control/PyroDataVisualization_Simple.py

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -34,55 +34,58 @@ def select_file():
3434
return tempdir
3535

3636

37-
# Call the function to select the file
38-
selected_file = str(select_file())
37+
def main():
38+
# Call the function to select the file
39+
selected_file = str(select_file())
3940

40-
# Print the selected file path
41-
print(f"Selected file: {selected_file}")
41+
# Print the selected file path
42+
print(f"Selected file: {selected_file}")
4243

43-
# Load data from CSV file
44+
# Load data from CSV file
4445

46+
# Set up the plot
47+
plt.style.use('fivethirtyeight')
48+
fig, axs = plt.subplots(3, 1, figsize=(9, 12))
4549

46-
# Set up the plot
47-
plt.style.use('fivethirtyeight')
48-
fig, axs = plt.subplots(3, 1, figsize=(9, 12))
4950

51+
def animate(i):
52+
# Reload data from CSV (in case it has changed)
53+
data = pd.read_csv(selected_file)
54+
x = data['Time (s)']
55+
y1 = data['Temperature (K)']
56+
y2 = data['Current (A)']
5057

51-
def animate(i):
52-
# Reload data from CSV (in case it has changed)
53-
data = pd.read_csv(selected_file)
54-
x = data['Time (s)']
55-
y1 = data['Temperature (K)']
56-
y2 = data['Current (A)']
58+
# Clear previous plots
59+
for ax in axs:
60+
ax.clear()
5761

58-
# Clear previous plots
59-
for ax in axs:
60-
ax.clear()
62+
# Update subplots
63+
axs[0].plot(x, y1, label='T', color='b', linewidth=0.8)
64+
axs[0].scatter(x, y1, color='b')
65+
axs[0].set_title('T vs time', fontsize=13)
66+
axs[0].set_xlabel('Time (s)', fontsize=13)
67+
axs[0].set_ylabel('Temperature (K)', fontsize=13)
68+
axs[0].legend(loc='upper left')
6169

62-
# Update subplots
63-
axs[0].plot(x, y1, label='T', color='b', linewidth=0.8)
64-
axs[0].scatter(x, y1, color='b')
65-
axs[0].set_title('T vs time', fontsize=13)
66-
axs[0].set_xlabel('Time (s)', fontsize=13)
67-
axs[0].set_ylabel('Temperature (K)', fontsize=13)
68-
axs[0].legend(loc='upper left')
70+
axs[1].plot(x, y2, label='I', color='g', linewidth=0.8)
71+
axs[1].scatter(x, y2, color='g')
72+
axs[1].set_title('I vs time', fontsize=13)
73+
axs[1].set_xlabel('Time (s)', fontsize=13)
74+
axs[1].set_ylabel('Current (A)', fontsize=13)
75+
axs[1].legend(loc='upper left')
6976

70-
axs[1].plot(x, y2, label='I', color='g', linewidth=0.8)
71-
axs[1].scatter(x, y2, color='g')
72-
axs[1].set_title('I vs time', fontsize=13)
73-
axs[1].set_xlabel('Time (s)', fontsize=13)
74-
axs[1].set_ylabel('Current (A)', fontsize=13)
75-
axs[1].legend(loc='upper left')
77+
axs[2].plot(y1, y2, label='I vs T', color='r', linewidth=0.8)
78+
axs[2].scatter(y1, y2, color='r')
79+
axs[2].set_title('I vs T', fontsize=13)
80+
axs[2].set_xlabel('Temperature (K)', fontsize=13)
81+
axs[2].set_ylabel('Current (A)', fontsize=13)
82+
axs[2].legend(loc='upper left')
7683

77-
axs[2].plot(y1, y2, label='I vs T', color='r', linewidth=0.8)
78-
axs[2].scatter(y1, y2, color='r')
79-
axs[2].set_title('I vs T', fontsize=13)
80-
axs[2].set_xlabel('Temperature (K)', fontsize=13)
81-
axs[2].set_ylabel('Current (A)', fontsize=13)
82-
axs[2].legend(loc='upper left')
8384

85+
ani = FuncAnimation(plt.gcf(), animate, interval=1000, cache_frame_data=False)
8486

85-
ani = FuncAnimation(plt.gcf(), animate, interval=1000, cache_frame_data=False)
87+
plt.tight_layout()
88+
plt.show()
8689

87-
plt.tight_layout()
88-
plt.show()
90+
if __name__ == "__main__":
91+
main()

pica/utils/GPIB_VISA_InterfaceTest_Simple_Instrument_Control.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@
2323

2424
import pyvisa
2525

26-
# Initialize the tool to find connected instruments
27-
rm = pyvisa.ResourceManager()
28-
instrument_addresses = rm.list_resources()
29-
30-
# Check if any instruments were found
31-
if not instrument_addresses:
32-
print("No instruments found. Check connections and VISA installation.")
33-
else:
34-
print(
35-
f"Found {len(instrument_addresses)} instrument(s). Checking them now...\n")
36-
37-
# Loop through each instrument and try to get its ID
38-
for address in instrument_addresses:
39-
try:
40-
# Connect to the instrument (connection closes automatically)
41-
with rm.open_resource(address) as instrument:
42-
instrument.timeout = 2000 # Set a 2-second timeout
43-
idn = instrument.query('*IDN?')
44-
print(f"Address: {address}\n ID: {idn.strip()}\n")
45-
except Exception as e:
46-
# If something goes wrong, print an error and continue
47-
print(f"Address: {address}\n Error: Could not get ID. {e}\n")
48-
49-
print("Scan complete.")
26+
def main():
27+
# Initialize the tool to find connected instruments
28+
rm = pyvisa.ResourceManager()
29+
instrument_addresses = rm.list_resources()
30+
31+
# Check if any instruments were found
32+
if not instrument_addresses:
33+
print("No instruments found. Check connections and VISA installation.")
34+
else:
35+
print(
36+
f"Found {len(instrument_addresses)} instrument(s). Checking them now...\n")
37+
38+
# Loop through each instrument and try to get its ID
39+
for address in instrument_addresses:
40+
try:
41+
# Connect to the instrument (connection closes automatically)
42+
with rm.open_resource(address) as instrument:
43+
instrument.timeout = 2000 # Set a 2-second timeout
44+
idn = instrument.query('*IDN?')
45+
print(f"Address: {address}\n ID: {idn.strip()}\n")
46+
except Exception as e:
47+
# If something goes wrong, print an error and continue
48+
print(f"Address: {address}\n Error: Could not get ID. {e}\n")
49+
50+
print("Scan complete.")
51+
52+
if __name__ == "__main__":
53+
main()

0 commit comments

Comments
 (0)