I am trying to control the flow of received data from a serial db9 RS232 and I am using the Pyserial. Normally I should receive 13 bytes data, but I want to be able to control my flow when the transmitter is sending more than 13 bytes. For this I wonder using the flow control options but I am not familiar with that. So can anyone please give me examples about using the XonXoff, rtscts and dsrdtr? Thanks for your help!
1 Answers
Serialport flow control controls the buffer size and the amount of data buffered in it to prevent buffer overruns, that is not what you want.
It also does not guarantee exact size or timing.
Your options are to either accept the all data you receive, analyze its contents and cut out the data blocks, or to establish your own protocol with the other device in command/response or ENQ/ACK/NAK format to send only one data block at a time.
In Addition:
Once the weight value is fixed, you can just check if the data is valid until some event occurs, and then discard the data itself. Just because you receive the data does not mean that it must be used by the main application (POS?).
Is the system crash actually happening?
Isn't it the Fear, Uncertainty, or Doubt you have because you don't fully understand the situation?
The system will not crash just by receiving a large amount of unused data.
You just need enough buffers to check the format.
Also, is it really a lot of data? For example, if you receive 13 bytes of data every 50 to 100 ms, it is not a large amount at all.
It's much more likely that there is a bug in the processing of the application that handles it.
That said, if you want to do something, read the weigh scale specifications carefully.
Alternatively, add a description to the question or provide a link to the specification documentation.
If your weigh scale doesn't have the ability to stop sending data with flow control, you're just wasting your time and effort increasing the likelihood of bugs.
If you receive it thousands to millions of times, even if it's all in a different area, it's probably few tens of megabytes at most.
It takes about 1 minute to send and receive video data.
Normally, the same area is reused, so it is impossible to have such a size.
Software/system bugs are ubiquitous, so it's possible that they will crash for some reason, but the weigh scale you're trying to use will probably have a large number of users running.
If the weigh scale works with the current specifications and there are no problems in the store, it means that you don't have to do anything weird and anxious.
If you still want to try it, you can use:
If you want to let the PySerial module or system take control, you can set one of the following to true.
However, the size of the buffer is fixed, and the size and timing for the occurrence of control events cannot be set.
If you want to control it yourself, you can set all the above specifications to False and do the following yourself.
software flow control:
Write XON = 0x11, XOFF = 0x13.
Software flow control

- 4,060
- 2
- 10
- 30
-
I have modified my question, so you can see the output of my code, and the difference that i got. When I make a selection on my cmd, my code is stuck, but my device is still sending data over the RS232, so this is my problem. I want to tell the device to stop sending data. And i don't want to close et reopen the serial... – take_it_easy_159 Oct 30 '20 at 13:34
-
plus i can't modify the settings of my device – take_it_easy_159 Oct 30 '20 at 13:46
-
I see your idea, but it's just a simple detail. My initial problem is that i will be running my code for a long duration, it means that I may receive large amount of **unusable data**, so it may cause my system to crash at anytime... – take_it_easy_159 Oct 30 '20 at 16:42
-
Till now it doesn't crash because i tested this bug just for few seconds. Now for not more than 5 seconds of testing this bug the number of bytes received has increased by 100. Imagine running the application for few days and this bug occurs from nowhere... For this reason I think my system will crash somewhere. By the way I use the ser.readline(). And yes, i think you are right, it's likely i am wasting my time, because in the documentation it's not mentioned that the flow control can be controlled. So for that i was asking for some examples about XONXOFF, to do my tests on the unclear point – take_it_easy_159 Oct 31 '20 at 12:25
-
Okay Thank you a lot for your advice! I will try to control the flow by myself and update my question for any news – take_it_easy_159 Oct 31 '20 at 14:26