I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening?
Now, to debug the above issue, I added a print statement just before my read() function. So it looks like:
self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received
In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time).
Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output).
in_waiting = 3896
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea
in_waiting = 3820
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea
in_waiting = 3744
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e
So my questions are…
What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)?
submitted by /u/supersonic_528
[link] [comments]
r/learnpython I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening? Now, to debug the above issue, I added a print statement just before my read() function. So it looks like: self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time). Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output). in_waiting = 3896 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3820 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3744 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e So my questions are… What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)? submitted by /u/supersonic_528 [link] [comments]
I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening?
Now, to debug the above issue, I added a print statement just before my read() function. So it looks like:
self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received
In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time).
Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output).
in_waiting = 3896
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea
in_waiting = 3820
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea
in_waiting = 3744
12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e
So my questions are…
What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)?
submitted by /u/supersonic_528
[link] [comments]