如何诊断Lakeshore 336温控器偶发随机串口通信崩溃问题
Lakeshore 336温控器 pyserial 突发无响应故障排查求助
我通过pyserial在Linux Mint系统上连接Lakeshore 336温控器,应用程序曾连续数月稳定运行无故障,但偶尔会突然停止响应,抛出如下错误:
device reports readiness to read but returned no data (device disconnected or multiple access on port?)
在Raspberry Pi 4上运行旧版GUI时也出现过该错误,因此可以确定问题与运行环境无关。
该设备的API继承自自定义父类,其read函数实现如下。我已尝试用信号量规避多访问问题,但故障仍会发生,恳请帮忙提供诊断(复现)及解决方法:
def read(self, command): response = '' if self.mutex.tryLock(self.waitLock): try: if self.ser is not None: if self.serialDevice: self.ser.write(bytes(command + self.settings['ending'],'utf-8')) response = self.ser.readline().decode('utf-8').strip() else: self.openSocket() self.ser.sendall((command+self.settings['ending']).encode()) response, listening = '', True while listening: response += self.ser.recv(128).decode() if self.settings['ending'] in response: response = response.strip() listening = False self.closeSocket() except Exception as e: print('While reading {} from {}, SerialDevice:read raised:'.format(command, self.settings['name']), e) response = '' finally: self.mutex.unlock() #pass else: print('{} not locking while attempting {}'.format(self.settings['name'], command)) return response
内容的提问来源于stack exchange,提问作者Alexis R Devitre
相关产品推荐
相关产品推荐

