Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
sdt.tutorial | 05f5df5d9b | |
sdt.tutorial | 197c019adc | |
sdt.tutorial | 3d70524150 |
|
@ -8,5 +8,5 @@ spec:
|
||||||
runtime: python3.9
|
runtime: python3.9
|
||||||
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
package: requirements.txt # 설치할 Python 패키지 정보 파일입니다.(기본 값은 requirement.txt 입니다.)
|
||||||
stackbase:
|
stackbase:
|
||||||
tagName: v1.0.0 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
tagName: v1.0.2 # Stackbase(gitea)에 릴리즈 태그명 입니다.
|
||||||
repoName: dts-py-app # Stackbase(gitea)에 저장될 저장소 이릅니다.
|
repoName: dts-py-app # Stackbase(gitea)에 저장될 저장소 이릅니다.
|
||||||
|
|
180
main.py
180
main.py
|
@ -1,124 +1,56 @@
|
||||||
from SDT_Device.DTS import DTS
|
from SDT_Device.DTS import DTS
|
||||||
import sys
|
|
||||||
|
import time
|
||||||
from PyQt6 import QtCore
|
import sys
|
||||||
from PyQt6.QtCore import Qt
|
import json
|
||||||
from PyQt6.QtWidgets import QApplication, QMainWindow
|
import uuid
|
||||||
from MainWindow import Ui_MainWindow
|
import sdtcloudpubsub
|
||||||
from pyqtgraph import PlotWidget, plot
|
|
||||||
import pyqtgraph as pg
|
|
||||||
from random import randint
|
# with open("./info.json","r") as f:
|
||||||
import threading
|
# info = f.read()
|
||||||
import time
|
|
||||||
import struct
|
# ch = info['ch']
|
||||||
|
# ch = 0
|
||||||
|
# ip = info['ip']
|
||||||
class MainWindow(QMainWindow, Ui_MainWindow):
|
# port = info['port']
|
||||||
def __init__(self):
|
# enableDelayVal = info['enableDelayVal']
|
||||||
super().__init__()
|
# sampleRangeVal = info['sampleRangeVal']
|
||||||
self.setupUi(self)
|
# avgStepVal = info['avgStepVal']
|
||||||
self.show()
|
|
||||||
|
# Default Setup for Test
|
||||||
self.pb_Start1.clicked.connect(self.SendStartPacket1)
|
ch = 0
|
||||||
self.pb_Stop1.clicked.connect(self.SendStopPacket1)
|
ip= "192.168.0.20"
|
||||||
|
port = 5001
|
||||||
self.pushButton_EnableDelaySet.clicked.connect(self.SetEnableDelay)
|
enableDelayVal = 10
|
||||||
self.pushButton_AverageStepSet.clicked.connect(self.SetAverage)
|
sampleRangeVal = 100
|
||||||
self.pushButton_SampleRangeSet.clicked.connect(self.SetSampleRange)
|
avgStepVal = 10
|
||||||
|
|
||||||
self.comboboxMinVal = 8
|
sdtcloud = sdtcloudpubsub.sdtcloudpubsub()
|
||||||
for i in range(self.comboboxMinVal, 12):
|
mqttClient = sdtcloud.setClient(f"device-app-{uuid.uuid1()}") # parameter is client ID(string)
|
||||||
self.comboBox_AverageStepVal.addItem(str(2**i))
|
|
||||||
|
# Run Start
|
||||||
ip = "192.168.0.20"
|
dts = DTS(ip,port)
|
||||||
port = 5001
|
dts.setSystemReset()
|
||||||
self.dts = DTS(ip, port)
|
dts.setAvgStart(ch, 0)
|
||||||
self.dtsInit()
|
|
||||||
|
dts.setAvgEnableDelay(ch, 10 + enableDelayVal)
|
||||||
self.x1 = []
|
dts.setAvgSampleRange(ch, sampleRangeVal)
|
||||||
self.y1 = []
|
dts.setAvgStep(ch, avgStepVal)
|
||||||
self.data_line1 = self.graphWidget1.plot(self.x1, self.y1)
|
|
||||||
|
# Get Data Start
|
||||||
self.timer = QtCore.QTimer()
|
dts. setAvgStart(ch, 1)
|
||||||
self.timer.setInterval(250)
|
|
||||||
self.timer.timeout.connect(self.update_plot_data)
|
dts.setTimerTick(ch, 100_000_000)
|
||||||
self.timer.start()
|
|
||||||
|
|
||||||
self.tick = 0
|
while(1):
|
||||||
|
print("Run")
|
||||||
self.prevDataCount = 0
|
y1 = dts.ReadAdcData(0)
|
||||||
|
|
||||||
def SetEnableDelay(self):
|
print(y1)
|
||||||
val = int(self.lineEdit_EnableDelayValue.text())
|
msg = {
|
||||||
self.dts.setAvgEnableDelay(0, 10 + val)
|
"sensor_data": y1
|
||||||
self.dts.setAvgStart(0, 0)
|
}
|
||||||
self.dts.setAvgStart(0, 1)
|
sdtcloud.pubMessage(mqttClient, msg)
|
||||||
|
time.sleep(1)
|
||||||
def SetAverage(self):
|
|
||||||
val = self.comboBox_AverageStepVal.currentIndex() + self.comboboxMinVal
|
|
||||||
self.dts.setAvgStep(0, val)
|
|
||||||
self.dts.setAvgStart(0, 0)
|
|
||||||
self.dts.setAvgStart(0, 1)
|
|
||||||
|
|
||||||
def SetSampleRange(self):
|
|
||||||
val = int(self.lineEdit_SampleRangeValue.text())
|
|
||||||
self.dts.setAvgSampleRange(0, val)
|
|
||||||
self.dts.setAvgStart(0, 0)
|
|
||||||
self.dts.setAvgStart(0, 1)
|
|
||||||
|
|
||||||
def SendStartPacket1(self):
|
|
||||||
print("Send Start1")
|
|
||||||
self.dts.setAvgStart(0, 1)
|
|
||||||
|
|
||||||
def SendStopPacket1(self):
|
|
||||||
print("Send Stop1")
|
|
||||||
self.dts.setAvgStart(0, 0)
|
|
||||||
|
|
||||||
def update_plot_data(self):
|
|
||||||
self.y1 = self.dts.ReadAdcData(0)
|
|
||||||
size = len(self.y1)
|
|
||||||
self.x1 = list(range(size))
|
|
||||||
self.data_line1.setData(self.x1, self.y1)
|
|
||||||
|
|
||||||
print(self.dts.dataCount)
|
|
||||||
if self.prevDataCount != self.dts.dataCount[0]:
|
|
||||||
self.prevDataCount = self.dts.dataCount[0]
|
|
||||||
current_time = time.time()
|
|
||||||
formatted_time = time.strftime("%H:%M:%S", time.localtime(current_time))
|
|
||||||
print(f"[{formatted_time}] dataCount={self.dts.dataCount[0]}")
|
|
||||||
|
|
||||||
debugData = self.dts.getDebugData()
|
|
||||||
self.lineEdit_TriggerCount.setText(str(debugData[4]))
|
|
||||||
|
|
||||||
def dtsInit(self):
|
|
||||||
self.dts.setSystemReset()
|
|
||||||
|
|
||||||
self.comboBox_AverageStepVal.setCurrentText(f"{self.comboboxMinVal}")
|
|
||||||
avgStepVal = self.comboBox_AverageStepVal.currentIndex() + self.comboboxMinVal
|
|
||||||
|
|
||||||
self.lineEdit_SampleRangeValue.setText("50000")
|
|
||||||
sampleRangeVal = int(self.lineEdit_SampleRangeValue.text())
|
|
||||||
|
|
||||||
self.lineEdit_EnableDelayValue.setText("0")
|
|
||||||
enableDelayVal = int(self.lineEdit_EnableDelayValue.text())
|
|
||||||
|
|
||||||
ch = 0
|
|
||||||
self.dts.setAvgEnableDelay(ch, 10 + enableDelayVal)
|
|
||||||
self.dts.setAvgSampleRange(ch, sampleRangeVal)
|
|
||||||
self.dts.setAvgStep(ch, avgStepVal)
|
|
||||||
self.dts.setAvgStart(ch, 0)
|
|
||||||
|
|
||||||
self.dts.setTimerTick(ch, 100_000_000)
|
|
||||||
|
|
||||||
|
|
||||||
def mainInit():
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
w = MainWindow()
|
|
||||||
app.exec()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
mainInit()
|
|
||||||
|
|
||||||
|
|
||||||
# pyuic6 .\MainWindow.ui -o MainWindow.py
|
|
||||||
|
|
Loading…
Reference in New Issue