wxPython:从RS232接口循环更新wx.ListCtrl数据表崩溃求助
RS232数据更新导致wx.ListCtrl崩溃,求表格可视化替代方案
我正在开发一个从RS232接口循环读取数据并显示在wx.ListCtrl中的程序。目前数据每秒更新一次,但更新wx.ListCtrl时程序崩溃,崩溃信息如下。我怀疑当前GUI控件不适合该场景,希望获得RS232流文本表格的可视化替代方案。
此前用控制台输出数据更新无问题。
代码片段
def OnConn(self, event): """Say hello to the user.""" # configure the serial connections (the parameters differs on the device you are connecting to) ser = serial.Serial( port='COM11', baudrate=115200, timeout=1, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS ) retConn = ser.isOpen() wx.MessageBox(f'Connection Open = {retConn}') while 1: bytesToRead = ser.inWaiting() data = ser.read(bytesToRead) time.sleep(0.5) dataRS232 = data.decode("utf-8") # Add the rows for item in dataRS232: index = self.list.InsertItem(self.list.GetItemCount(), item[0]) for col, text in enumerate(item[1:]): print(f'index = {index} column = {col} text = {text}') self.list.SetItem(index, col+1, text) ser.close()
崩溃信息
Windows fatal exception: access violation Main thread: Current thread 0x00002e44 (most recent call first): File "C:\Users\tratkanov\AppData\Local\anaconda3\Lib\site-packages\wx\core.py", line 2262 in MainLoop File "c:\users\tratkanov\projectfolder\pythonprojects\rs232_gui.py", line 169 in main File "c:\users\tratkanov\projectfolder\pythonprojects\rs232_gui.py", line 185 in <module> File "C:\Users\tratkanov\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py", line 356 in compat_exec File "C:\Users\tratkanov\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 473 in exec_code File "C:\Users\tratkanov\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 615 in _exec_file File "C:\Users\tratkanov\AppData\Local\anaconda3\Lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 528 in runfile File "C:\Users\tratkanov\AppData\Local\Temp\ipykernel_16964\1439496246.py", line 1 in <module> Restarting kernel...
内容的提问来源于stack exchange,提问作者dim_dim
相关产品推荐
相关产品推荐

