trigger.py
2.24 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
#--------------------------------------------------------------------------
# Software: InVesalius - Software de Reconstrucao 3D de Imagens Medicas
# Copyright: (C) 2001 Centro de Pesquisas Renato Archer
# Homepage: http://www.softwarepublico.gov.br
# Contact: invesalius@cti.gov.br
# License: GNU - GPL 2 (LICENSE.txt/LICENCA.txt)
#--------------------------------------------------------------------------
# Este programa e software livre; voce pode redistribui-lo e/ou
# modifica-lo sob os termos da Licenca Publica Geral GNU, conforme
# publicada pela Free Software Foundation; de acordo com a versao 2
# da Licenca.
#
# Este programa eh distribuido na expectativa de ser util, mas SEM
# QUALQUER GARANTIA; sem mesmo a garantia implicita de
# COMERCIALIZACAO ou de ADEQUACAO A QUALQUER PROPOSITO EM
# PARTICULAR. Consulte a Licenca Publica Geral GNU para obter mais
# detalhes.
#--------------------------------------------------------------------------
import threading
from time import sleep
import wx
from wx.lib.pubsub import pub as Publisher
class Trigger(threading.Thread):
"""
Thread created to use external trigger to interact with software during neuronavigation
"""
def __init__(self, nav_id):
threading.Thread.__init__(self)
self.trigger_init = None
try:
import serial
self.trigger_init = serial.Serial('COM1', baudrate=9600, timeout=0)
self.nav_id = nav_id
self._pause_ = False
self.start()
except ImportError:
print 'PySerial library not installed. Please install to use Trigger option.'
except serial.serialutil.SerialException:
print 'Connection with port COM1 failed.'
def stop(self):
if self.trigger_init:
self.trigger_init.close()
self._pause_ = True
def run(self):
while self.nav_id:
lines = self.trigger_init.readlines()
# Following lines can simulate a trigger in 3 sec repetitions
# sleep(3)
# lines = True
if lines:
wx.CallAfter(Publisher.sendMessage, 'Create marker')
sleep(0.175)
if self._pause_:
return