-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
77 lines (60 loc) · 2.35 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import time
import winsound
from time import sleep
import pyvisa
from termcolor import colored
from pyvisa import constants
import numpy as np
def printMessage(message, headerStr, footerStr):
print(colored(len(message) * headerStr, "magenta"))
print(colored(message, "magenta"))
print(colored(len(message) * footerStr, "magenta"))
def sendCommandToInstrument(instrument, command, terminator, delayBefore, delayAfter):
sleep(delayBefore)
instrument.write_raw(command + terminator)
sleep(delayAfter)
def main():
delay = 0.5
rm = pyvisa.ResourceManager()
l_resources = rm.list_resources()
printMessage("Looking for pyVisa Resources......", "*", "*")
printMessage(l_resources, "*", "*")
hv_source = rm.open_resource("GPIB0::" + str(20) + "::INSTR", send_end=True,
write_termination="\n",
read_termination="",
access_mode=constants.AccessModes.no_lock)
sleep(delay)
sendCommandToInstrument(hv_source, "ID", "", 0, delay)
response = hv_source.read_raw() # type(response) =--> bytes
decoded_response = response.decode(encoding='ascii', errors='ignore')
print(decoded_response)
# sendCommandToInstrument(hv_source, "U,0.5kV", "\n", 0, delay)
time.sleep(2)
sendCommandToInstrument(hv_source, "*RST", "", delay, delay)
time.sleep(2)
sendCommandToInstrument(hv_source, "*CLS", "", 0, delay)
time.sleep(2)
frequency = 1000 # Set Frequency To 2500 Hertz
duration = 1000 # Set Duration To 1000 ms == 1 second
winsound.Beep(frequency, duration)
# time.sleep(1)
# sendCommandToInstrument(hv_source, "HV,ON", "", 0, delay)
#
# startVolage = 0.0
# stopVoltage = 1.0
# step = 0.1
# sweep = np.arange(startVolage,stopVoltage,step)
# print(sweep)
# for v in sweep:
# print("sending command...")
# sendCommandToInstrument(hv_source, "U,"+str(v)+"kV", "\n", 0, 0)
# time.sleep(5)
#
# sendCommandToInstrument(hv_source, "U," + str(0.0) + "kV", "\n", 0, 0)
# sendCommandToInstrument(hv_source, "HV,OFF", "", 0, delay)
#
# # response = hv_source.read_raw() # type(response) =--> bytes
# # decoded_response = response.decode(encoding='ascii', errors='ignore')
# # print(decoded_response)
if __name__ == "__main__":
main()