Rabu, 03 Januari 2018

Aplikasi Counter Bank GUI

Teman-teman sy ingin berbagi tentang penerapan raspberry untuk aplikasi counter di RS, Bank dll
cara kerjanya adalah: sistem raspberry menerima data serial dari PC operator
msial operator2 mengirimkand data antrian U77

maka secara background : PC tsb akan mengirimkan data serialnya ke raspberry
dan raspberry akan meresponnya dengan menampilkannya secara Realtime ke display moitornya
Sederhana namun bobot dari koding ini adalah sbb:
+Realtime GUI
+Realtime Serial Event
+Python Berbasis GUI

Harapannya semoga aplikasi ini bisa menambah kecintaan kita pada raspberry PI....CMIIw :-)


from PyQt5 import QtCore, QtGui, QtWidgets
import serial
import time, threading
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import QtWidgets
global ser
ser = serial.Serial('/dev/ttyUSB0', baudrate=1200, timeout=10,
                    parity=serial.PARITY_NONE,
                    stopbits=serial.STOPBITS_ONE,
                    bytesize=serial.EIGHTBITS
                    )



class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        desktop = QDesktopWidget()
     
        screenwidth = desktop.screen().width()+100
        screenheight = desktop.screen().height()+100
        top=screenheight/7
        bottom=screenheight-top-top-100
   
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(screenwidth, screenheight)
        MainWindow.setStyleSheet("background-color: #003366;")
     
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.lbl = QtWidgets.QLabel(self.centralwidget)
        self.lbl.setGeometry(QtCore.QRect(-5, top-100, screenwidth, 80))
        self.lbl.setStyleSheet("color: #FFFFFF;font:Bold")
        self.lbl.setFont(QFont('Xtreme Chrome',60))
        self.lbl.setAlignment(QtCore.Qt.AlignCenter)
        self.lbl.setObjectName("lbl")
     
        self.lblCounter = QtWidgets.QLabel(self.centralwidget)
        self.lblCounter.setGeometry(QtCore.QRect(-5, top+30, screenwidth, 300))
        self.lblCounter.setStyleSheet("background-color: #000000; color: #FFFF00;font:Bold")
        self.lblCounter.setFixedHeight(300)
        self.lblCounter.setAlignment(QtCore.Qt.AlignCenter)
        self.lblCounter.setFont(QFont('Xtreme Chrome',250))
        self.lblCounter.setObjectName("lblCounter")

        self.lblLoket = QtWidgets.QLabel(self.centralwidget)
        self.lblLoket.setGeometry(QtCore.QRect(-5, bottom, screenwidth, 130))
        self.lblLoket.setStyleSheet("background-color: #cccccc; color: #ff0000;font:Bold")
        self.lblLoket.setFixedHeight(150)
        self.lblLoket.setAlignment(QtCore.Qt.AlignCenter)
        self.lblLoket.setFont(QFont('Xtreme Chrome',130))
        self.lblLoket.setObjectName("lblLoket")
     
    ##################
     
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 259, 21))
        self.menubar.setObjectName("menubar")
     
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "   "))
        self.lblCounter.setText(_translate("MainWindow", "A000"))
        self.lblLoket.setText(_translate("MainWindow", "Loket X"))
        self.lbl.setText(_translate("MainWindow", "NOMOR ANTRIAN"))
     
        # User Code
        self.timeout = 0
        self.check_serial_event()

    def check_serial_event(self):
        serial_thread = threading.Timer(1, self.check_serial_event)
        if ser.is_open == True:
            serial_thread.start()
            distance=""
            char1='T' #Loket 1
            char2='B'
     
            if ser.in_waiting:
                while True:
                    try:
                        msg = ser.readline().decode('ascii')
                        distance=distance+msg  
                        if distance.index(char2):
                            break
                     
                    except:
                        pass
                 
                print (distance)  
                ser.flush()
                #ser.close()
                l1=distance.index(char1)
                #l2=distance.index(char2)
                l2=distance.find(char2, l1+5)

                H1=distance[l1:l2-2] #l1+7
                H2=distance[l2:l2+4]

                print ('H1='+H1)
                print ('H2='+H2)
             
                self.lblLoket.setText(H1)
                self.lblCounter.setText(H2)
                distance=""
             
         
        #ser.close()
if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())



Implementasinya:
OK ...In Sya Allah Mudah....