tkinter - Tkinter 串行输入数据
问题描述
我创建了一个函数来检查串行端口上是否有任何活动,从 tkinter Gui 获取其串行数据,然后返回答案,但是我在初始化变量时遇到问题。
我尝试将其设置为 int,但我遇到了这个问题,如果没有,我会收到另一个错误,告诉我波特率无效。
#serial port checking function
def check_SERIAL(port_name='/dev/ttyUSB0',baud_rate=115200,serial_parity='serial.PARITY_NONE',stop_bits=8,byte_size=8,time_out=1): #pings serial interface, VAR: port name, baud rate, parity, stopB, byteS, Timeout
logger.debug('checking Serial Connection')
ser = serial.Serial(
port=port_name,
baudrate=baud_rate,
parity=serial_parity,
stopbits=stop_bits,
bytesize=byte_size,
timeout=time_out
)
time.sleep(1)
A=0
try:
ser.write("||;1>get logfile\r\n".encode())
for x in range(0,1000):
if ser.inWaiting() > 10:
A=1
finally:
ser.close()
if A==0:
raise device_crashed(" Device Crashed")
time.sleep(1)
#entries from the GUI
entry_PORT = Entry(second_frame, bg="white")
entry_PORT.grid(row=14,column=1,padx=0,pady=5)
entry_BAUD = Entry(second_frame, bg="white")
entry_BAUD.grid(row=16,column=1,padx=0,pady=5)
entry_PARITY = Entry(second_frame, bg="white")
entry_PARITY.grid(row=18,column=1,padx=0,pady=5)
entry_STOPB = Entry(second_frame, bg="white")
entry_STOPB.grid(row=20,column=1,padx=0,pady=5)
entry_BYTES = Entry(second_frame, bg="white")
entry_BYTES.grid(row=22,column=1,padx=0,pady=5)
#running code:
def start_testing():
try:
logger.debug('test has started ')
#checking device interfaces if are ok
check_SERIAL(port_name=str(entry_PORT),baud_rate=int(entry_BAUD),serial_parity=entry_PARITY,stop_bits=entry_STOPB,byte_size=entry_BYTES)
except Exception as e: #general exceptions
logger.error('Something went wrong: ' + str(e))
button=Button(second_frame, text='Start Test',borderwidth=10,command= start_testing)
button.place(relx=0.8,rely=0.4,relwidth=0.15,relheight=0.12)
我得到的错误:
int() argument must be as 'string, a bytes like object or a number, not 'Entry'
解决方案
推荐阅读
- node.js - Nodejs打字稿应用程序中的“预期变量声明”
- python - 如何从控制台打印/提取所有行和列?
- matlab - 如何在条形图上添加图例?
- azure - 如何递归比较 Azure 资源组?
- python - 将每个观察计数一行
- validation - 为什么我的 *ngIf 条件无法识别错误并在满足条件时显示消息?
- python - 为什么我收到 TypeError:字符串索引必须是整数?
- graph-theory - 他们的这种说法有什么矛盾的吗?
- google-apps-script - 请求电子表格范围值返回“您必须选择合并范围中的所有单元格...”
- python - 如何仅在我选择的文本上执行粗体/突出显示/更改字体之类的操作?