NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


from PySide2.QtCore import Signal, QObject
import serial, serial.tools.list_ports
from threading import Thread, Event

class Comunicacion(QObject):
datos_recibidos = Signal(str)

def __init__(self):
super().__init__()
self.arduino = serial.Serial()
self.arduino.timeout = 0.5

self.baudrates = ['4800', '9600']
self.puertos = []

self.hilo = None
self.alive = Event()

def puertos_disponibles(self):
self.puertos = [port.device for port in serial.tools.list_ports.comports()]

def conexion_serial(self):
try:
self.arduino.open()
except:
pass

if (self.arduino.is_open):
self.iniciar_hilo()

def desconectar(self):
self.stop_hilo()
self.arduino.close()

def leer_datos(self):
while(self.alive.isSet() and self.arduino.is_open):

data = self.arduino.readline().decode("utf-8").strip()
if data.startswith("Temperature is:"):

data=data.split(":")[1]

if(len(data)>1):
self.datos_recibidos.emit(data)

def iniciar_hilo(self):
self.hilo = Thread(target= self.leer_datos)
self.hilo.setDaemon(1)
self.alive.set()
self.hilo.start()

def stop_hilo(self):
if(self.hilo is not None):
self.alive.clear()
self.hilo.join()
self.hilo = None


-------------

----

import sys

from PyQt5.QtWidgets import QApplication
from progressBarCircular import *
from progressBarCircular2 import *
from comunicacion_serial import Comunicacion
from PySide2.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QMainWindow


class MiApp(QMainWindow):
def __init__(self,*args, **kwargs):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)

self.serial = Comunicacion()
self.puertos_disponible()
self.nivel = 0.0
self.serial.datos_recibidos.connect(self.datos_arduino)
# self.ui.velocidad.addItems(self.serial.baudrates)
# self.ui.velocidad.setCurrentText("9600")
self.mostrar_barra()
self.conectar()
# self.desconectar()
# self.ui.conectar.clicked.connect(self.conectar)
# self.ui.actualizar.clicked.connect(self.mostrar_barra)
# self.ui.desconectar.clicked.connect(self.desconectar)


def datos_arduino(self,data):
self.nivel = float(data)

def conectar(self):

port = 'COM3'
baud = '9600'

# port = self.ui.puertos.currentText()
# baud = self.ui.velocidad.currentText()
self.serial.arduino.port = port
self.serial.arduino.baudrate = baud
self.serial.conexion_serial()

# def desconectar(self):
# self.serial.desconectar()

def mostrar_barra(self):
self.progressbar()
QTimer.singleShot(20, self.mostrar_barra)

def puertos_disponible(self):
self.serial.puertos_disponibles()
# self.ui.puertos.clear()
# self.ui.puertos.addItems(self.serial.puertos)

def progressbar(self):
estilo = """ QFrame{
border-radius: 150px;
background-color: qconicalgradient(cx:0.5, cy:0.5, angle:90, stop: {stop1}
rgba(255, 0 , 55 , 255), stop: {stop2} rgba(255 , 0 , 0, 30));
} """

val = (self.nivel)/100

stop1 = str(abs(val - 0.001))
stop2 = str(val)

valor1 = int(float(stop1)*1000)
valor2 = int(float(stop2)*1000)

if (valor1>=0 and valor2<=1000) and (valor2>=0 and valor1<=1000):
nuevo_estilo = estilo.replace('{stop1}', stop1).replace('{stop2}', stop2)
self.ui.voltage.setText(str(self.nivel))
self.ui.progressbar.setStyleSheet(nuevo_estilo)

if __name__ == "__main__":
app = QApplication(sys.argv)
mi_app = MiApp()
mi_app.show()
sys.exit(app.exec_())






     
 
what is notes.io
 

Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 14 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.