St.fragment thread safe problem

I am testing out the fragment feature in a local app that communicates with a serial RS232 device. The thing is that commands and queries need to happen in a well defined sequence. The st.fragment function queries the device for status variables by first sending a command to the serial port and then reading the result. This part alone works well. A problem may arise when I start changing parameters from my apps UI in addition. Either it works or I get an error indicating multiple port access:

Serial.serialutil.SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)

I tried to add a simple ‘lock’ state variable to sessionstate to prevent the access of the fragment function while I change parameters, but it didnt work.
Is there an easy fix for that like some asyncio thread lock function to prevent concurrent access to the serial port?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.