-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPython3 SpeedSerial.py
More file actions
218 lines (169 loc) · 6.29 KB
/
Python3 SpeedSerial.py
File metadata and controls
218 lines (169 loc) · 6.29 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import serial
import time
tgCom = "/dev/tty.usbmodem81494301"
tgS = serial.Serial()
tgS.port = tgCom
tgS.baudrate = 115200
tgS.bytesize = serial.EIGHTBITS # number of bits per bytes
tgS.parity = serial.PARITY_NONE # set parity check: no parity
tgS.stopbits = serial.STOPBITS_ONE # number of stop bits
# tgS.timeout = None #block read
tgS.timeout = 0.5 # non-block read
tgS.xonxoff = False # disable software flow control
tgS.rtscts = False # disable hardware (RTS/CTS) flow control
tgS.dsrdtr = False # disable hardware (DSR/DTR) flow control
tgS.writeTimeout = 0 # timeout for write
try:
print("Activating Triggerscope...")
tgS.open()
except Exception as e:
print("ERROR: Triggerscope Com port NOT OPEN: " + str(e))
exit()
if tgS.isOpen():
try:
tgS.flushInput() # flush input buffer, discarding all its contents
tgS.flushOutput() # flush output buffer, aborting current output
op = "*"
tgS.write(op.encode() + "\n".encode('ascii')) # send an ack to tgs to make sure it's up
time.sleep(0.2) # give the serial port sometime to receive the data
print("Rx: " + tgS.readline().decode())
except Exception as e1:
print(" serial communication error...: " + str(e1))
else:
print("cannot open tg cell port ")
def writetgs(tgin):
'''send a serial command to the triggerscope...
Args:
tgin: input string to send. Note the command terminator should be included in the string.
Returns:
char string of whatever comes back on the serial line.
Raises:
none.
'''
tgS.flushInput() # flush input buffer, discarding all its contents
tgS.flushOutput() # flush output buffer, aborting current output
tgS.write(tgin.encode()) # send command
time.sleep(0.02) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
return bufa
def readStat():
tgS.flushInput() # flush input buffer, discarding all its contents
tgS.flushOutput() # flush output buffer, aborting current output
tgS.write("STAT?\n".encode()) # send command
time.sleep(0.02) # give the serial port sometime to receive the data 50ms works well...
for n in range(100):
time.sleep(0.2) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
print(bufa);
if(len(bufa) < 5):
break
def speedTestA():
# for x in range (5):
# time.sleep(1) # for the arduino reset
# print(x)
start = time.time()
print( writetgs("TIMECYCLES,3\n") )
print( writetgs("PROG_TTL,1,1,1\n") )
print( writetgs("PROG_TTL,1,2,0\n") )
print( writetgs("PROG_TTL,2,1,0\n") )
print( writetgs("PROG_TTL,2,2,1\n") )
print( writetgs("PROG_TTL,2,3,0\n") )
print( writetgs("PROG_TTL,3,1,0\n") )
print( writetgs("PROG_TTL,3,2,0\n") )
print( writetgs("PROG_TTL,3,3,1\n") )
print( writetgs("PROG_TTL,3,4,0\n") )
#readStat()
input(" Press Enter to ARM...")
print( writetgs("ARM\n") )
for n in range(100):
time.sleep(0.2) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
print(bufa);
if (len(bufa) < 5):
break
def speedTestB():
# for x in range (5):
# time.sleep(1) # for the arduino reset
# print(x)
start = time.time()
print( writetgs("TIMECYCLES,3\n") )
print( writetgs("PROG_FOCUS,32832,3276,4,0,0\n") )
print( writetgs("PROG_TTL,1,1,1\n") )
print( writetgs("PROG_TTL,1,2,0\n") )
print( writetgs("PROG_TTL,2,1,0\n") )
print( writetgs("PROG_TTL,2,2,1\n") )
print( writetgs("PROG_TTL,2,3,0\n") )
print( writetgs("PROG_TTL,3,1,0\n") )
print( writetgs("PROG_TTL,3,2,0\n") )
print( writetgs("PROG_TTL,3,3,1\n") )
print( writetgs("PROG_TTL,3,4,0\n") )
print( writetgs("ARM\n") )
for n in range(100):
time.sleep(0.2) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
print(bufa);
if (len(bufa) < 5):
break
def speedTestC():
# for x in range (5):
# time.sleep(1) # for the arduino reset
# print(x)
start = time.time()
print( writetgs("TIMECYCLES,3\n") )
print( writetgs("PROG_FOCUS,32832,3276,4,0,1\n") )
print( writetgs("PROG_TTL,1,1,1\n") )
print( writetgs("PROG_TTL,1,2,0\n") )
print( writetgs("PROG_TTL,2,1,0\n") )
print( writetgs("PROG_TTL,2,2,1\n") )
print( writetgs("PROG_TTL,2,3,0\n") )
print( writetgs("PROG_TTL,3,1,0\n") )
print( writetgs("PROG_TTL,3,2,0\n") )
print( writetgs("PROG_TTL,3,3,1\n") )
print( writetgs("PROG_TTL,3,4,0\n") )
print( writetgs("ARM\n") )
for n in range(100):
time.sleep(0.2) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
print(bufa);
if (len(bufa) < 5):
break
def PWMGen():
print(writetgs("TIMECYCLES,100\n")) #cycle this operation 100 times on camera input trigger
print(writetgs("PROG_TTL,1,1,1\n"))
print(writetgs("PROG_TTL,1,2,0\n"))
print( writetgs("ARM\n") ) #Arm sequence
for n in range(100): #read reply from triggerscope
time.sleep(0.2) # give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
print(bufa);
if (len(bufa) < 5):
break
def cyclettl():
for i in range(30):
print(writetgs("TTL1,1\n"))
time.sleep(0.05)
print(writetgs("TTL1,0\n"))
time.sleep(0.05)
def cycledac():
for i in range(30):
print(writetgs("DAC1,"+str(2184*i)+"\n"))
time.sleep(0.05)
#input(" Check for TTL 1 on and off @ 10Hz - Arm Oscilloscope Press Enter ...")
#cyclettl()
#input(" Check for DAC 1 ramp @ 10Hz - Arm Oscilloscope Press Enter ...")
#cycledac()
#input(" Sweep over Channel First - Arm Oscilloscope Press Enter ...")
#speedTestA()
input(" Sweep over Channel First - Arm Oscilloscope Press Enter ...")
speedTestA()
#input(" Sweep over Channel First - Arm Oscilloscope Press Enter ...")
#speedTestB()
#input(" Sweep over Channel First - Arm Oscilloscope Press Enter ...")
#speedTestC()
#readStat()