-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrigger_box_demo.py
More file actions
68 lines (54 loc) · 1.86 KB
/
trigger_box_demo.py
File metadata and controls
68 lines (54 loc) · 1.86 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
from triggerbox import *
from psychopy import core
BAUDRATE_ANOTHER = 115200
# BAUDRATE = 1200
# connect to the trigger box via serial port
trigger = TriggerBox()
# send a 5V signal over analog channel 3 until it is switched off
goInfinite = trigger.make_analog_signal(channel = 3, voltage = 5, duration = 0)
trigger.ser.write(goInfinite)
# wait 5 seconds
core.wait(5)
# cancel the previously sent analog signal
cancel = trigger.make_cancel_signal(channel = 3) # does work now
trigger.ser.write(cancel)
# stop = trigger.make_analog_signal(3,0,0) # this works
# trigger.ser.write(stop)
# wait 5 seconds
core.wait(5)
# send a 5V signal over analog channel 3 for 100 ms
go = trigger.make_analog_signal(channel = 3, voltage = 5, duration = 100)
# send the signal
trigger.ser.write(go)
# wait 5 seconds
core.wait(5)
# send a message over the USB channel and read it back
label = trigger.make_digital_signal(channel = 1, message = 'T', duration = 0)
trigger.ser.write(label)
trigger.ser.readline().decode('utf-8')
# # send signal to winSC
# winSC_msg = trigger.make_winsc_signal()
# trigger.ser.write(winSC_msg)
# # wait 5 seconds
# core.wait(5)
# # set up another serial port to read the output from channel 2
# output = serial.Serial('COM10', BAUDRATE_ANOTHER, timeout = 0.5)
# # send message over channel 2 and then read it in output chaqnnel
# message = trigger.make_digital_signal(channel = 2, message = 'j', duration = 1000) # WORKS SOMETIMES ?!
# trigger.ser.write(message)
# x = 0
# while x < 5:
# print("COM9 says:",output.readline().decode('utf-8'))
# x+=1
# # output.readline().decode('utf-8') # DOESN'T WORK, GET NO SIGNAL OR 0 BYTE
###########################################
# CLEAN UP
try:
# close the serial connections
trigger.ser.close()
except:
print("Did not close trigger")
# try:
# output.close()
# except:
# print("Did not close DSUB")