-
Notifications
You must be signed in to change notification settings - Fork 4
/
writeWindow.py
233 lines (190 loc) · 9.06 KB
/
writeWindow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
from PyQt6 import QtGui
import sys
from sys import platform
import serial
from serial.tools.list_ports import comports
import time
from tools import *
from reader import *
class CustomComboBox(QComboBox):
# Define a custom signal
clicked = pyqtSignal()
def showPopup(self):
# Emit the custom signal before showing the dropdown
self.clicked.emit()
super().showPopup()
class writeWindow(QWidget):
def __init__(self):
super().__init__()
self.debug = True
self.setWindowTitle('RFID Tag Writer')
self.setGeometry(100, 100, 300, 500)
# create grid layout
self.layout = QGridLayout()
# set layout on window
self.setLayout(self.layout)
# Transmit power level stuff
self.available_power_levels = []
for i in range(0, 0x1C):
self.available_power_levels.append("{}dB".format(i-2))
self.selected_tx_power_level = -2
self.pwr_lvl_change = True
# possible types are "B" for binary, "I" for int, and "D" for decoded
self.table_display_type = "D"
self.display_XTID_details = True
# serial stuff
# get list of devices (works for all platforms)
self.available_serial_devices = list(map(lambda com_device: com_device.name, comports()))
self.selected_device = None
self.baudrate = 38400
self.ser = None
# init UI
self.initUI()
def initUI(self):
######################################### First Row ############################
# grid width
width = 1
# adjust first row offset to account for menu bar (different for different OS)
if platform == "win32":
# windows
row = 1
elif platform == "darwin":
# osx
row = 0
elif platform == "linux":
row = 1
# ############## label for select serial device ##############
label = QLabel(self)
label.setFont(QtGui.QFont('Arial', 15))
label.setText("Select Serial Device:")
label.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
label.setMinimumWidth(150)
self.layout.addWidget(label, row,0)
# ############## select device dropdown ##############
self.device_select_box = CustomComboBox()
self.device_select_box.addItems(self.available_serial_devices)
self.device_select_box.activated.connect(self.update_selected_serial_device)
self.device_select_box.clicked.connect(self.refresh_serial_devices)
self.device_select_box.setMinimumWidth(220)
self.layout.addWidget(self.device_select_box, row, 1)
######################################### Second Row ############################
row += 1
# ####### Label for transmit power #########
label = QLabel(self)
label.setFont(QtGui.QFont('Arial', 15))
label.setText("Select Source:")
label.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
label.setMinimumWidth(150)
self.layout.addWidget(label, row,0)
# ############## label for output power select ##############
label = QLabel(self)
label.setFont(QtGui.QFont('Arial', 15))
label.setText("TX Power:")
label.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
label.setMinimumWidth(150)
self.layout.addWidget(label, row,1)
# # mode select between TID, EPC single, EPC multi, and multi segment
# # ############## Mode Selection ##############
# self.tx_power_box = CustomComboBox()
# self.tx_power_box.addItems(self.available_power_levels)
# self.tx_power_box.activated.connect(self.update_tx_power_level)
# self.tx_power_box.setMinimumWidth(220)
# self.layout.addWidget(self.tx_power_box, row, 1)
# # ############## label for mode select ##############
# label = QLabel(self)
# label.setFont(QtGui.QFont('Arial', 15))
# label.setText("Read Rate (ms):")
# label.setAlignment(Qt.AlignmentFlag.AlignRight | Qt.AlignmentFlag.AlignVCenter)
# label.setMinimumWidth(150)
# self.layout.addWidget(label, row,2)
# # mode select between TID, EPC single, EPC multi, and multi segment
# # ############## Mode Selection ##############
# self.update_rate_box = CustomComboBox()
# self.update_rate_box.addItems(self.available_update_rates)
# self.update_rate_box.activated.connect(self.update_read_rate)
# self.update_rate_box.setMinimumWidth(150)
# self.layout.addWidget(self.update_rate_box, row, 3)
# ######################################### Third Row ############################
# # ############## section label ##############
# row += 1
# section_one_label = QLabel(self)
# section_one_label.setMaximumHeight(30)
# section_one_label.setText("Unique Tags")
# section_one_label.setFont(QtGui.QFont('Arial', 20))
# self.layout.addWidget(section_one_label, row,0)
# # ############## export log button ##############
# self.export_log_button = QPushButton(self, text='Export Log')
# self.export_log_button.setStyleSheet(blue_button_style_shet)
# self.export_log_button.clicked.connect(self.export_log)
# self.layout.addWidget(self.export_log_button,row,1)
# # ############## reset log button ##############
# self.reset_log_button = QPushButton(self, text='Clear Log')
# self.reset_log_button.setStyleSheet(red_button_style_shet)
# self.reset_log_button.clicked.connect(self.clear_log)
# self.layout.addWidget(self.reset_log_button,row,2)
# # ############## button to start logging ##############
# self.start_logging_button = QPushButton(self, text='Start Logging')
# self.start_logging_button.setStyleSheet(green_button_style_shet)
# self.start_logging_button.clicked.connect(self.start_log)
# self.layout.addWidget(self.start_logging_button,row,3)
# # ############## data table ##############
# row += 1
# self.data_table = QTableWidget()
# self.layout.addWidget(self.data_table, row, 0, 1, width)
# ######################################### END block ############################
# # Add vertical spacer at the end
# # row += 1
# # spacer = QSpacerItem(20, 40, QSizePolicy.Policy.Minimum, QSizePolicy.Policy.Expanding)
# # self.layout.addItem(spacer, row, 0, 1, width)
# # # Set row stretch for the last row
# # self.layout.setRowStretch(1, 1)
def write_data(self):
print("logging started")
# start logging
try:
if platform == "darwin":
self.ser = serial.Serial("/dev/"+self.selected_device, self.baudrate, timeout=1)
elif platform == "linux":
self.ser = serial.Serial("/dev/"+self.selected_device, self.baudrate, timeout=1)
else:
self.ser = serial.Serial(self.selected_device, self.baudrate, timeout=1)
print("Serial interface opened")
print("device: {}".format(self.selected_device))
print("clearing input buffer")
self.ser.reset_input_buffer()
print("clearing output buffer")
self.ser.reset_output_buffer()
except Exception as error:
print("Failed to open {}".format(self.selected_device))
print("error message: {}".format(error))
return False
# change button to stop configuration
self.start_logging_button.setText('Stop Logging')
self.start_logging_button.setStyleSheet(red_button_style_shet)
# disconnect old connections
self.start_logging_button.clicked.disconnect()
self.start_logging_button.clicked.connect(self.stop_log)
self.start_logging_button.update()
# instantiate reader object
self.reader = Reader(self.ser)
# start data collection
# Start timer to call update_label every Nms
self.timer.start(self.update_rate)
def refresh_serial_devices(self):
# refresh the available serial devices
self.available_serial_devices = list(map(lambda com_device: com_device.name, comports()))
# update dropdown options
self.device_select_box.clear()
self.device_select_box.addItems(self.available_serial_devices)
print("updated device list")
def update_selected_serial_device(self):
# log selected device
self.selected_device = self.device_select_box.currentText()
print("selected device: {}".format(self.selected_device))
def update_tx_power_level(self):
# update transmit power levels
self.selected_tx_power_level = int(self.tx_power_box.currentText().replace("dB", ""))
print("Changing TX power level to {}dB".format(self.selected_tx_power_level))
self.pwr_lvl_change = True