-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample python serial for triggerscope.py
More file actions
82 lines (71 loc) · 2.54 KB
/
example python serial for triggerscope.py
File metadata and controls
82 lines (71 loc) · 2.54 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
import serial
import time
tgsCom = "/dev/cu.usbmodem14201"
tgS = serial.Serial()
tgS.port = tgsCom
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, 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
tgS.write("*\n") #send an ack to tgs to make sure it's up
time.sleep(0.1) #give the serial port sometime to receive the data
print("Rx: " + tgS.readline())
except Exception, e1:
print "triggerscope serial communication error...: " + str(e1)
else:
print "cannot open triggerscope 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) #send an ack to tgs to make sure it's up
time.sleep(0.01) #give the serial port sometime to receive the data 50ms works well...
bufa = ""
bufa = tgS.readline()
return bufa
def loadTgs():
print "Loading prog array.."
for i in range(10):
sout = ("PROG_TTL,%d,8,1\n" % (i+1) ) #prog command for triggerscope
writetgs(sout)
print sout
time.sleep(0.01)
print"done."
def armTgs():
sout = ("ARM\n") #prog command for triggerscope
writetgs(sout)
print sout
def progtest():
print(writetgs("PROG_DAC,1,1,65000\n") )
#print(writetgs("PROG_DAC,2,1,0\n") )
print(writetgs("PROG_DAC,2,1,32000\n") )
print(writetgs("PROG_TTL,1,1,1\n") )
print(writetgs("PROG_TTL,2,2,1\n") )
print(writetgs("ARM\n") )
for n in range (10):
print(tgS.readline())
time.sleep(0.5)
progtest()