Skip to content

Commit

Permalink
includes fixes from downstairs
Browse files Browse the repository at this point in the history
  • Loading branch information
grg2rsr committed Jan 20, 2020
1 parent b953c50 commit e83fd10
Show file tree
Hide file tree
Showing 13 changed files with 717 additions and 688 deletions.
33 changes: 26 additions & 7 deletions ArduinoWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, parent):
# signals
self.Signals = Signals()

self.stopped = False
self.reprogram = False

self.initUI()

def initUI(self):
Expand All @@ -60,6 +63,12 @@ def initUI(self):
self.FormLayout.setVerticalSpacing(10)
self.FormLayout.setLabelAlignment(QtCore.Qt.AlignRight)

# reprogram
self.reprogramCheckBox = QtWidgets.QCheckBox("reupload sketch")
self.reprogramCheckBox.setChecked(False)
self.reprogramCheckBox.stateChanged.connect(self.reprogramCheckBox_changed)
self.FormLayout.addRow(self.reprogramCheckBox)

# get com ports and ini selector
# com_ports = self.get_com_ports()
# TODO is this UI element required? Yes if you want to run multiple box from one computer
Expand Down Expand Up @@ -137,9 +146,11 @@ def initUI(self):

# FUTURE TODO implement baud rate selector

# def reset_board(self):
# # TODO implement - necessary?
# pass
def reprogramCheckBox_changed(self):
if self.reprogramCheckBox.checkState() == 2:
self.reprogram = True
else:
self.reprogram = False

def send(self,command):
""" sends string command interface to arduino, interface compatible """
Expand Down Expand Up @@ -277,7 +288,10 @@ def Run(self,folder):
self.log_task(folder)

# upload
self.upload()
if self.reprogram:
self.upload()
else:
print(" --- resetting arduino only --- reusing previous sketch --- ")

# connect to serial port
self.connection = self.connect()
Expand All @@ -303,7 +317,7 @@ def Run(self,folder):
# everybody that needs to do sth when new data arrives listens to that signal

def read_from_port(ser):
while True:
while not self.stopped:
try:
line = ser.readline().decode('utf-8').strip()
if line is not '': # filtering out empty reads
Expand All @@ -317,10 +331,15 @@ def read_from_port(ser):
# FIXME CHECK if this will also fail on failed reads!
break

thread = threading.Thread(target=read_from_port, args=(self.connection, ))
thread.start() # apparently this line is not passed, thread hangs here? if yes,then why multithreading at all???
self.thread = threading.Thread(target=read_from_port, args=(self.connection, ))
self.thread.start() # apparently this line is not passed, thread hangs here? if yes,then why multithreading at all???

def closeEvent(self, event):

# take care of ending the threads
self.stopped = True
self.thread.join()

# overwrite logged arduino vars file
if self.parent().logging:
try:
Expand Down
27 changes: 16 additions & 11 deletions HardwareWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,18 @@ def Run(self,folder):
animal = self.parent().animal
task = self.parent().task
task_config = self.parent().task_config['Bonsai']
# task_folder = os.path.join(self.parent().profile['tasks_folder'], task)
task_folder = Path(self.parent().profile['tasks_folder']).joinpath(task)

# fname = animal+'.raw' # FIXME there is a thing with _ and 0 appended, check this

out_path = folder.joinpath('bonsai_') # this needs to be fixed in bonsai



# constructing the bonsai exe string
parameters = "-p:save_path=\""+str(out_path)+"\""

# TODO add bonsai com_port passing, check if multiple can be passed with colon separation
# parameters = "-p:save_path=\""+str(out_path)+"\""

bonsai_exe = Path(self.parent().profiles['General']['bonsai_cmd'])

# bonsai_workflow = os.path.join(task_folder,'Bonsai',task_config['workflow_fname'])
bonsai_workflow = task_folder.joinpath('Bonsai',task_config['workflow_fname'])
bonsai_workflow = "\""+bonsai_workflow+"\""


command = ' '.join([str(bonsai_exe),str(bonsai_workflow),"--start",parameters,"&"])

Expand All @@ -87,6 +80,10 @@ def Run(self,folder):

pass

def closeEvent(self, event):
# stub
self.close()

"""
__ ______ ___ _______ ______ _______ __ __
| | / __ \ / \ | \ / || ____|| | | |
Expand Down Expand Up @@ -118,6 +115,8 @@ def __init__(self, parent):

self.Buffer = sp.zeros((100,2))

self.stopped = False

self.LoadCellMonitor = LoadCellMonitor(self)
self.init_udp_server()
self.initUI()
Expand Down Expand Up @@ -198,7 +197,7 @@ def Run(self, folder):
# exception and then I let it pass w/o doing anything. Verify if necessary

def udp_reader():
while True:
while not self.stopped:
try:
# read data and publish it via a qt signal
# raw_read = sock.recv(12) # replace chunk size stuff with 1 int 2 floats or whatever you get from bonsai
Expand Down Expand Up @@ -279,7 +278,8 @@ def closeEvent(self, event):
# if serial connection is open, close it
if hasattr(self,'arduino_2nd_ser'):
self.arduino_2nd_ser.close()
self.LoadCellMonitor.close()

self.stopped = True
# self.th_read.join()
self.close()

Expand Down Expand Up @@ -368,6 +368,11 @@ def on_lc_data(self,x,y):
self.LineFB_pp.setData(y=self.lc_data[:,0])
self.LineLR_pp.setData(y=self.lc_data[:,1])


def closeEvent(self, event):
# stub
self.close()

""" copy paste working script from the computer downstairs """
# ###
# import sys, os
Expand Down
4 changes: 2 additions & 2 deletions TaskControl.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ def onLastClosed(self):

if __name__ == "__main__":
import argparse
# profiles_fpath = 'profiles_fphot.ini' # the fiber photometry computer downstairs in the viv
profiles_fpath = 'profiles_ccu.ini' # my ccu desktop in the open lab
profiles_fpath = 'profiles_fphot.ini' # the fiber photometry computer downstairs in the viv
# profiles_fpath = 'profiles_ccu.ini' # my ccu desktop in the open lab

# argparsing
parser = argparse.ArgumentParser(description=' xXx Unified TaskControl xXx ')
Expand Down
14 changes: 7 additions & 7 deletions Tasks/dummy_dev/Arduino/platformio.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
upload_port = /dev/ttyACM0
src_filter = +<main.cpp>

[env:megaatmega2560]
platform = atmelavr
board = megaatmega2560
framework = arduino
upload_port = COM8
src_filter = +<main.cpp>

Loading

0 comments on commit e83fd10

Please sign in to comment.