Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"RX ring buffer full" error despite flushing buffers in PySerial #399

Open
Qlexio opened this issue Jan 27, 2025 · 0 comments
Open

"RX ring buffer full" error despite flushing buffers in PySerial #399

Qlexio opened this issue Jan 27, 2025 · 0 comments

Comments

@Qlexio
Copy link
Owner

Qlexio commented Jan 27, 2025

I'm working on a project where I use the PySerial module to communicate with a battery management system (BMS) through a serial port. I'm also using ThingsBoard and Streamlit in this project. However, I keep encountering the "RX ring buffer full" error, even though I am flushing the buffers each time. Additionally, the lines I read are different every time I run the code.

Code:
import serial
import csv
from time import sleep

responseArray = list()

def writeBatteryData(rest_client, batteryUsed):
"""Writes the battery attributes' values to the connected BMS

Args:
    batteryUsed (str): Battery used in the battery instance

Returns:
    None
"""
with open('deviceForms/batteryForm.csv', 'r') as csvfile:
    csvForm = csv.reader(csvfile)
    form = list(csvForm)
    numRows = len(form)

batteryForm = getDeviceAttributes(rest_client, batteryUsed, form, numRows)
start = 0
for start in range(numRows):
    if form[start][0] == 'Charge Overcurrent':
        break

with open('deviceForms/batteryThingSetCommands.csv', 'r') as csvfile:
    csvForm = csv.reader(csvfile)
    batteryCommandsForm = list(csvForm)

ser = serial.Serial(port='/dev/ttyACM1', baudrate=115200, timeout=5)
ser.reset_input_buffer()
ser.reset_output_buffer()
ser.write(b'select thingset\r\n')
response = ser.readline()

for i in range(start, numRows):
    ser.write((batteryCommandsForm[i-start][1] + str(batteryForm[i][1]) + '}\r\n').encode())
    sleep(0.1)
    response = ser.readline()
    responseArray.append(response)
    sleep(0.1)
    # Flushing buffer using read()
    if ser.in_waiting > 0:
        data = ser.read(ser.in_waiting)

ser.close()
print(responseArray)

writeBatteryData(rest_client, "NMCBattery")

Steps to Reproduce:

1.Run the provided code snippet.
2.Observe the "RX ring buffer full" error and the varying lines read each time.

Expected Behavior:
The buffers should be flushed correctly, and the RX ring buffer should not overflow. The lines read should be consistent.

Actual Behavior:
Encountering "RX ring buffer full" error and inconsistent lines being read.

Additional Information:

  1. ThingsBoard and Streamlit are being used in the project.
    2.I've tried flushing the buffers using ser.reset_input_buffer(), ser.reset_output_buffer(), and ser.read(ser.in_waiting) but the issue persists.

This issue has been cloned from: pyserial#766

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant