def auto_connect(self): port_list = ports.serial_ports() for port in port_list: if self.verbose: print('+ Trying port', port, end='') self.device = maestro.Device(con_port=False, ser_port=port) success = self.test_connection() if success: break if self.verbose: print('\t--> Rejected') if success and self.verbose: print('\t--> OK')
def select_port(): i = 1 print('Selecione uma porta para a comunicação') ports = serial_ports() for port in ports: print('{0} - {1}'.format(i, port)) i += 1 p = int(input('Selecione o número da porta que deseja usar: ')) return ports[p - 1]
def set_dtr(): global ser ser.close() PORT = ports.serial_ports() ser = serial.Serial(port=PORT, timeout = 1, baudrate = 9600) logging.info("Conexion Serial al PORT: %s", PORT) try: ser.setDTR(True) time.sleep(1) ser.setDTR(False) time.sleep(1) logging.info("======================================================Se ejecuto SET_DTR()======================================") except: logging.info("---------------------------------------------------- Fallo Ejecucion set_dtr() ---------------------------------")
def __init__(self, parent=None): super(MainGui2, self).__init__(parent) self.setupUi(self) # cargamos la ui #CONTROL VARIABLES self.patient = [] # almacena info del paciente # TODO: change by dict self.fname = '' # path del log self.f = '' self.Q = Queue() # para actualizar el monitor self.Q2 = Queue() # para actualizar la base de datos self.data_event = 0 #CONTROL EXPERIMENTO self.images = [] self.duration = 0 self.silence = 0 self.experiment_duration = 0 # BLE self.ble = serial.Serial() # declaro el puerto #MONITOR self.monitor = Monitor() #SCREEN self.screen = Screen() #DATABASE self.db = None self.cur = None ################################### # DOCK1 ################################### [self.port_combobox.addItem(i) for i in serial_ports()] ###################################### #MAINFRAME ####################################### #LEDS self.pc_led = QLed() self.pc_led.setOnColour(QLed.Green) self.pc_led.setOffColour(QLed.Red) self.experiment_led = QLed() self.experiment_led.setOffColour(QLed.Red) self.experiment_led.setOnColour(QLed.Green) self.patient_led = QLed() self.patient_led.setOffColour(QLed.Red) self.patient_led.setOnColour(QLed.Green) self.recording_led = QLed() self.recording_led.setOffColour(QLed.Red) self.recording_led.setOnColour(QLed.Blue) self.gridLayout_2.addWidget(self.pc_led, 0, 1, 1, 1) self.gridLayout_2.addWidget(self.experiment_led, 1, 1, 1, 1) self.gridLayout_2.addWidget(self.patient_led, 2, 1, 1, 1) self.gridLayout_2.addWidget(self.recording_led, 3, 1, 1, 1) #IMAGE #qpix = QtGui.QPixmap('flor.jpeg') #qpix = qpix.scaled(300, 300, QtCore.Qt.KeepAspectRatio) #self.central_image.setPixmap(qpix) #PROGRESS BAR #self.progressBar.setValue(0) self.setCentralWidget(self.monitor) ###################################### #TABLE PATIENT INFO ####################################### self.fillPatientTable() #SIGNALS self.connect(self.actionMonitor, QtCore.SIGNAL('triggered()'), self.monitor_view) self.connect(self.actionScreen, QtCore.SIGNAL('triggered()'), self.screen_view) self.connect(self.actionProcessing, QtCore.SIGNAL('triggered()'), self.viewler_view) self.connect_button.clicked.connect(self.pc_connect) self.scandevices_button.clicked.connect(self.scan_bluethoot_devices) self.pair_device_button.clicked.connect(self.pair_bluethoot_devices) self.run_button.clicked.connect(self.run_device) self.connect(self.actionNew_Patient, QtCore.SIGNAL('triggered()'), self.newDialog) self.connect(self.actionLoad_Patient, QtCore.SIGNAL('triggered()'), self.loadDialog) self.connect(self.actionNew_Experiment, QtCore.SIGNAL('triggered()'), self.newExperimentDialog) self.connect(self.actionLoad_experiment, QtCore.SIGNAL('triggered()'), self.loadExperimentDialog) self.connect(self.actionConnectDatabase, QtCore.SIGNAL('triggered()'), self.connectDatabase) self.connect(self.freq_comboBox, QtCore.SIGNAL("currentIndexChanged(const QString&)"), self.changeFrequency) #QTHREADS self.worker = worker() self.connect(self.worker, QtCore.SIGNAL("thread_readdata()"), self.read_data, QtCore.Qt.DirectConnection) self.worker2 = worker2() self.connect(self.worker2, QtCore.SIGNAL("thread_loopmonitor()"), self.monitor_loop, QtCore.Qt.DirectConnection) self.worker3 = worker3() self.connect(self.worker3, QtCore.SIGNAL("thread_writedatabase()"), self.newDataDB, QtCore.Qt.DirectConnection) #QTIMERS FOR RUNNING EXPERIMENT self.timer = QtCore.QTimer() self.connect(self.timer, QtCore.SIGNAL('timeout()'), self.run_experiment)
import ports import serial import time import sqlite3 as sqlite import re import requests import json """ This threading server was implemented based on: https://pymotw.com/2/BaseHTTPServer/index.html#module-BaseHTTPServer """ API_ENDPOINT = "http://13.59.155.171/drone/1" API_KEY = "cc4673bb6f9cd137f642d15ae87fb8f7" port_list = ports.serial_ports() print(port_list) fleet = Fleet(port_list) fleet_lock = threading.Lock() #app_dict entry format: {"instanceID" : [droneID, running_bool]} app_dict = {} dict_lock = threading.Lock() def connect_and_run(instanceID): """ Function to connect and run the drone. Sets the drone as running at the end. Created to be ran on a new thread so POST response isn't blocked. """
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) #set the main window self.resize(700, 400) self.setWindowTitle('MONITOR ARISTARKO') menubar = self.menuBar() self.statusBar() #CONTROL VARIABLES self.patient = {'name': '', 'surname': ''} self.fname = '' # path del log self.f = '' ###### SET FRAMES #set dock area as central widget self.area = DockArea() self.setCentralWidget( self.area) # inserto el pg como una widget central. #create docks and add them into dock area self.d1 = Dock("BLE CONNECTION", size=(100, 50), closable=True) self.d2 = Dock("CONTROLS", size=(200, 200)) self.d3 = Dock("PATIENT INFO", size=(400, 100), closable=True) self.d4 = Dock("MAIN", size=(400, 200), closable=True) self.d5 = Dock("STATUS", size=(400, 200), closable=True) self.area.addDock(self.d1, 'left') self.area.addDock(self.d2, 'bottom') self.area.addDock(self.d5, 'bottom') self.area.addDock(self.d3, 'bottom') self.area.addDock(self.d4, 'right') #BLUETHOOTH LE self.ble = '' #MONITOR self.monitor = Monitor() ######################################## #MENUS ####################################### fileMenu = menubar.addMenu('&File') newMenu = fileMenu.addAction('New Patient') loadMenu = fileMenu.addAction('Load Patient') ###################################### # create progress bar ###################################### self.pb = QtGui.QProgressBar(self.statusBar()) self.statusBar().addPermanentWidget(self.pb) self.statusBar().showMessage(self.tr("Parsing eventlog data...")) self.pb.setValue(50) ######################################## #DOCK 1 ####################################### #layout for dock1, BLE self.w1 = pg.LayoutWidget() # creo el layout self.d1.addWidget(self.w1) # lo add al dock1 #widgets labelPort = QtGui.QLabel('Port:') self.w1.addWidget(labelPort, row=0, col=0) comboBoxPort = QtGui.QComboBox(self) #comboBoxPort.setGeometry(QtCore.QRect(0, 0, 50, 24)) comboBoxPort.setEditable(False) self.w1.addWidget(comboBoxPort, row=1, col=0) [comboBoxPort.addItem(i) for i in serial_ports()] labelBaud = QtGui.QLabel('BaudRate:') self.w1.addWidget(labelBaud, row=0, col=1) comboBoxBaud = QtGui.QComboBox(self) #comboBoxBaud.setGeometry(QtCore.QRect(0, 0, 50, 24)) comboBoxBaud.setEditable(False) self.w1.addWidget(comboBoxBaud, row=1, col=1) baudlist = ['1200', '2400', '4800', '9600', '19200', '57600', '115200'] [comboBoxBaud.addItem(i) for i in baudlist] self.connectButton = QtGui.QPushButton('CONNECT') self.connectButton.setCheckable(True) scanButton = QtGui.QPushButton('SCAN PORTS') self.w1.addWidget(self.connectButton, row=2, col=1) self.w1.addWidget(scanButton, row=2, col=0) ################################################## ### DOCK2. BOTONES ################################################## self.w2 = pg.LayoutWidget() # creo el layout self.d2.addWidget(self.w2) # lo add al dock1 monitorButton = QtGui.QPushButton('MONITOR') self.w2.addWidget(monitorButton, row=0, col=0) historicButton = QtGui.QPushButton('VIEWLER') self.w2.addWidget(historicButton, row=0, col=1) Button3 = QtGui.QPushButton('TODO') self.w2.addWidget(Button3, row=1, col=0) Button4 = QtGui.QPushButton('TODO') self.w2.addWidget(Button4, row=1, col=1) Button5 = QtGui.QPushButton('RECORDING') self.w2.addWidget(Button5, row=2, col=0, colspan=2) #signals self.connectButton.clicked.connect(self.ble_connect) monitorButton.clicked.connect(self.monitor_view) self.connect(newMenu, QtCore.SIGNAL('triggered()'), self.newDialog) self.connect(loadMenu, QtCore.SIGNAL('triggered()'), self.loadDialog) ################################################# # DOCK3. PATIENT INFO ################################################# self.w3 = pg.LayoutWidget() # creo el layout self.d3.addWidget(self.w3) # lo add al dock1 name = QtGui.QLabel('Name:') self.name_label = QtGui.QLabel('') self.w3.addWidget(name, row=0, col=0) self.w3.addWidget(self.name_label, row=0, col=1) surname = QtGui.QLabel('Surname:') self.surname_label = QtGui.QLabel('') self.w3.addWidget(surname, row=0, col=2) self.w3.addWidget(self.surname_label, row=0, col=3) ################################################## # DOCK 5. STATUS LEDS ################################################## self.led1 = QLed(self, onColour=QLed.Green, shape=QLed.Circle) self.led2 = QLed(self, onColour=QLed.Green, shape=QLed.Circle) self.led3 = QLed(self, onColour=QLed.Red, shape=QLed.Round) self.led4 = QLed(self, onColour=QLed.Red, shape=QLed.Round) self.w4 = pg.LayoutWidget() # creo el layout self.d5.addWidget(self.w4) # lo add al dock1 self.w4.addWidget(QtGui.QLabel('WEARABLE: '), row=0, col=0) self.w4.addWidget(self.led1, row=0, col=1) self.w4.addWidget(QtGui.QLabel('DATABASE: '), row=0, col=2) self.w4.addWidget(self.led2, row=0, col=3) self.w4.addWidget(QtGui.QLabel('RECORDING FILE: '), row=1, col=0) self.w4.addWidget(self.led3, row=1, col=1) self.w4.addWidget(QtGui.QLabel('RECORDING DATABASE: '), row=1, col=2) self.w4.addWidget(self.led4, row=1, col=3) #QTHREADS self.worker = worker() self.connect(self.worker, QtCore.SIGNAL("thread_readdata()"), self.read_data, QtCore.Qt.DirectConnection)
import sqlite3 as sqlite import re import requests import json """ This threading server was implemented based on: https://pymotw.com/2/BaseHTTPServer/index.html#module-BaseHTTPServer """ API_ENDPOINT ="http://13.59.155.171/drone/1" API_KEY = "cc4673bb6f9cd137f642d15ae87fb8f7" port_list = ports.serial_ports() print (port_list) fleet = Fleet(port_list) fleet_lock = threading.Lock() #app_dict entry format: {"instanceID" : [droneID, running_bool]} app_dict = {} dict_lock = threading.Lock() def connect_and_run(instanceID): """ Function to connect and run the drone. Sets the drone as running at the end. Created to be ran on a new thread so POST response isn't blocked. """ droneid = app_dict[instanceID][0]
import zmq, time, datetime, serial, sys, logging, ports logging.basicConfig(filename='/home/pi/vprocess6/log/myserial.log', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s') DIR="/home/pi/vprocess6/" #5556: for listen data #5557: for publisher data tau_serial = 0.35 #[ms] save_setpoint = "wph11.1f111u111m1111t111r111111d111" PORT = ports.serial_ports() ser = serial.Serial(port=PORT, timeout = 1, baudrate = 9600) logging.info("Conexion Serial al PORT: %s", PORT) def set_dtr(): global ser ser.close() PORT = ports.serial_ports() ser = serial.Serial(port=PORT, timeout = 1, baudrate = 9600) logging.info("Conexion Serial al PORT: %s", PORT) try: ser.setDTR(True) time.sleep(1) ser.setDTR(False) time.sleep(1) logging.info("======================================================Se ejecuto SET_DTR()======================================") except:
#!/usr/bin/env python3 import serial import ports serial_ports = ports.serial_ports() serial_port = serial.Serial(serial_ports[0],9600) serial_port.write(str("{['G:SYS:NAME']}\n\r"))
import serial from ports import serial_ports def main(port): if not port: port = "/dev/ttyAMA0" ser = serial.Serial(port, 9600, timeout=None) buf = bytearray() while True: index = max(1, min(2048, ser.in_waiting)) data = ser.read(index) index = data.find(b"\n") if index >= 0: r = buf + data[:index + 1] buf[0:] = data[index + 1:] try: print(r.decode().strip().split(':')) except: pass else: buf.extend(data) if __name__ == "__main__": ports = serial_ports() print("Reading from port %s" % ports[0]) main(ports[0])