Ejemplo n.º 1
0
class OpenBCIThread(QtCore.QThread):
  newPacket = QtCore.Signal(object)
  
  def __init__(self, ttyPath = '/dev/ttyUSB0'):
    super(OpenBCIThread, self).__init__()
    
    self.board = OpenBCIBoard(ttyPath, scaled_output=False)

  def handlePacket(self, sample):
    self.newPacket.emit(sample.channel_data)
    QtGui.QApplication.instance().processEvents()
    
  def run(self):
    try:
      self.board.print_register_settings()
      self.board.start_streaming(self.handlePacket)

    # Important workaround for OSX: If the input is not kept on being read, the whole (input sub-)system freezes
    except Exception as e:
      print ("Exception", e)
      while True:
        self.board.ser.read()
					for i in xrange(8):
						result = classify_waveform(self.samples[i])
						# write this over serial
					for changather in self.samples:
						del changather[:]
					self.sample_counter = 0

aparser = ArgumentParser()
aparser.add_argument('dongle_device')
aparser.add_argument('underlying_arduino')
args = aparser.parse_args()

load_waveform_samples()
# make flexible

board = OpenBCIBoard(port=args.dongle_device)
arduino_slave = serial.Serial(args.underlying_arduino, 9600) #replace with serial rate for underlying arduino program
#board.print_register_settings()

for c in 'svcd':
	board.ser.write(c)
	time.sleep(0.100)
time.sleep(0.100)

atexit.register(board.disconnect)

# collect the data in a separate thread
# to prevent blocking
classifying_thread = FFTBCIThread()
classifying_thread.daemon = True
classifying_thread.start()
Ejemplo n.º 3
0
#signal.signal(signal.SIGINT, signal.SIG_DFL)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

ttyPath = '/dev/ttyUSB0'
if len(sys.argv) > 1:
  ttyPath = sys.argv[1]

last_packet = 0


def send_packet(packet):
  global last_packet

  expected = (last_packet + 1) % 256

  if packet.id != expected:
  	print 'lost packet', expected

  last_packet = packet.id


  data = json.dumps(packet.channel_data)
  sock.sendto(data.encode('utf-8'), ('localhost', 8888))
  data = struct.pack('=f', packet.channel_data[0] * 0.022351744455307063)
  sock.sendto(data, ('localhost', 9999))

board = OpenBCIBoard(ttyPath, scaled_output=False)
board.print_register_settings()
board.start_streaming(send_packet)
Ejemplo n.º 4
0
from open_bci_v3 import OpenBCIBoard
import sys, signal
import socket
import json
import struct

#app = QCoreApplication(sys.argv)
#signal.signal(signal.SIGINT, signal.SIG_DFL)

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

ttyPath = '/dev/ttyUSB0'
if len(sys.argv) > 1:
    ttyPath = sys.argv[1]


def send_packet(packet):
    data = json.dumps(packet.channel_data)
    sock.sendto(data.encode('utf-8'), ('localhost', 8888))
    data = struct.pack('=f', packet.channel_data[0] * 0.022351744455307063)
    sock.sendto(data, ('localhost', 9999))


board = OpenBCIBoard(ttyPath, scaled_output=False)
board.print_register_settings()
board.start_streaming(send_packet)
Ejemplo n.º 5
0
from BDFWriter import BDFWriter
from open_bci_v3 import OpenBCIBoard
import thread

NUM_CHANNELS = 8

bdf = BDF(NUM_CHANNELS)

board = OpenBCIBoard(port='/dev/ttyUSB0', baud=115200, scaled_output=False)
board.print_register_settings()
#board.test_signal(2)
board.print_register_settings()


def handle_sample(sample):
    bdf.append_sample(sample.channel_data)

    if sample.id == 0:
        bdf.write_file(file('record.bdf', 'wb'))

#thread.start_new_thread(board.start_streaming, (handle_sample,))

board.start_streaming(handle_sample)
Ejemplo n.º 6
0
	curses.echo()
	curses.endwin()

aparser = ArgumentParser()
aparser.add_argument('dongle_device')
aparser.add_argument('-c0', type=str, default="Channel 0")
aparser.add_argument('-c1', type=str, default="Channel 1")
aparser.add_argument('-c2', type=str, default="Channel 2")
aparser.add_argument('-c3', type=str, default="Channel 3")
aparser.add_argument('-c4', type=str, default="Channel 4")
aparser.add_argument('-c5', type=str, default="Channel 5")
aparser.add_argument('-c6', type=str, default="Channel 6")
aparser.add_argument('-c7', type=str, default="Channel 7")
args = aparser.parse_args()

board = OpenBCIBoard(port=args.dongle_device)
for c in 'svcd':
	board.ser.write(c)
	time.sleep(0.100)
time.sleep(0.100)

sampletime = 1.0/board.getSampleRate()
dirpath = os.path.dirname(os.path.realpath(__file__))

atexit.register(write_packets)
atexit.register(board.disconnect)
boardthread = threading.Thread(target=board.start_streaming, args=(label_packet, -1))
#board.start_streaming([label_packet], -1)
boardthread.daemon = True
boardthread.start()
Ejemplo n.º 7
0
 def __init__(self, ttyPath = '/dev/ttyUSB0'):
   super(OpenBCIThread, self).__init__()
   
   self.board = OpenBCIBoard(ttyPath, scaled_output=False)
        [curve[i].setData(a[8], a[i])
         for i in range(numberofchannels)]  # set the curve with this data
        pg.QtGui.QApplication.processEvents()  # you MUST process the plot now

    ### MAIN PROGRAM #####
    # this is a brutal infinite loop calling your realtime data plot
    while True:
        update()

    ### END QtApp ####
    pg.QtGui.QApplication.exec_()  # you MUST put this at the end
    ##################


# Read serial information related to the electrodes
board = OpenBCIBoard()
board.print_register_settings()

numberofchannels = 8

# Montreal task
levelqueue = Queue()
question = Question(level=1, timer=20, levelqueue=levelqueue)

# Filtering setup
w = sg.firwin(256, [5, 50], pass_zero=False, fs=250, window="hann")
w = np.flip(
    w
)  # Change w0 to last position in order to multiply that last sample that came from queue

# File to save recordings in time domain